Find answers from the community

Updated 3 months ago

what is this error? -------------------------------------------------------------------

what is this error? -


---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_20692\960662579.py in <module>
----> 1 from llama_index.retrievers import NLSQLRetriever
2
3 # default retrieval (return_raw=True)
4 nl_sql_retriever = NLSQLRetriever(
5 sql_database, tables=["city_stats"], return_raw=True

ImportError: cannot import name 'NLSQLRetriever' from 'llama_index.retrievers' (C:\Users\alens\AppData\Roaming\Python\Python39\site-packages\llama_index\retrievers__init__.py)
k
P
5 comments
Please stand by @PREDATOR as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
The error message you're seeing is an ImportError, which means that Python is unable to import the specified module or function. In this case, it's trying to import NLSQLRetriever from llama_index.retrievers, but it can't find it.

Based on the information provided in the extracts, it seems that NLSQLRetriever is not a valid class or function in the llama_index.retrievers module. Instead, you might want to use SQLTableRetrieverQueryEngine from llama_index.indices.struct_store as shown in the documentation () or SQLJoinQueryEngine from llama_index.query_engine as shown in the github notebook ().

Here's an example of how you might use SQLTableRetrieverQueryEngine:

Plain Text
from llama_index.indices.struct_store import SQLTableRetrieverQueryEngine

query_engine = SQLTableRetrieverQueryEngine(
    sql_database, obj_index.as_retriever(similarity_top_k=1)
)
response = query_engine.query("Which city has the highest population?")
print(response)


Please replace sql_database and obj_index with your actual SQL database and object index. If you're still having trouble, I recommend checking the LlamaIndex documentation or the source code to ensure you're using the correct classes and functions.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@kapa.ai what is the import settings for NLSQLRetriever?
Let me check the knowledge base for you. One moment! :books:
----------------------
I'm sorry, but based on the information provided in the extracts, there is no class or function named NLSQLRetriever available in the LlamaIndex library. It's possible that there might be a misunderstanding or typo in the class name.

If you're trying to work with SQL databases in LlamaIndex, you might want to use NLSQLTableQueryEngine from llama_index.indices.struct_store.sql_query or SQLJoinQueryEngine from llama_index.query_engine. Here's an example of how you might import and use NLSQLTableQueryEngine:

Plain Text
from llama_index.indices.struct_store.sql_query import NLSQLTableQueryEngine

sql_query_engine = NLSQLTableQueryEngine(
    sql_database=sql_database,
    tables=["city_stats"],
)


Please replace sql_database with your actual SQL database. If you're still having trouble, I recommend checking the LlamaIndex documentation or the source code to ensure you're using the correct classes and functions.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord