-
When I am running NLSQLRetriever.retrieve the result is returned in below format. Is there a way to just get the Metadata?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yes, there is a way to get just the metadata when running Here is an example of how to initialize from llama_index.core.retrievers import NLSQLRetriever
from llama_index.core import SQLDatabase
# Assuming you have an instance of SQLDatabase
sql_database = SQLDatabase(...)
# Initialize NLSQLRetriever with return_raw set to True
nl_sql_retriever = NLSQLRetriever(
sql_database=sql_database,
tables=["city_stats"],
return_raw=True
)
# Now you can use nl_sql_retriever to retrieve just the metadata
results = nl_sql_retriever.retrieve(
"Return the top 5 cities (along with their populations) with the highest population."
)
# NOTE: all the content is in the metadata
for n in results:
display_source_node(n, show_source_metadata=True) In this setup, the metadata will contain the information you are interested in [1]. |
Beta Was this translation helpful? Give feedback.
To retrieve just the metadata and store it in a variable when using
NLSQLRetriever.retrieve
, you can use theretrieve_with_metadata
method. Here is an example of how you can do this:The
retrieve_with_metadata
method returns a tuple where the second element is the metadata. You can store this metadata in a variable as shown above. The metadata will include details such as the SQL query used and oth…