Replies: 3 comments 2 replies
-
The query pipeline couldn't retrieve the correct node even though the exact text exists in the index because the table parser component was not designed to return relevant rows per table schema. It only returned the table schemas without considering the contextually relevant rows that might contain the exact text. To address this, the table parser component needs to be expanded to include relevant rows per table schema. This can be done by using vector retrieval of relevant rows based on the original query string. Here is the expanded table parser component: from llama_index.core.retrievers import SQLRetriever
from typing import List
from llama_index.core.query_pipeline import FnComponent
sql_retriever = SQLRetriever(sql_database)
def get_table_context_and_rows_str(
query_str: str, table_schema_objs: List[SQLTableSchema]
):
"""Get table context string."""
context_strs = []
for table_schema_obj in table_schema_objs:
# first append table info + additional context
table_info = sql_database.get_single_table_info(
table_schema_obj.table_name
)
if table_schema_obj.context_str:
table_opt_context = " The table description is: "
table_opt_context += table_schema_obj.context_str
table_info += table_opt_context
# also lookup vector index to return relevant table rows
vector_retriever = vector_index_dict[
table_schema_obj.table_name
].as_retriever(similarity_top_k=2)
relevant_nodes = vector_retriever.retrieve(query_str)
if len(relevant_nodes) > 0:
table_row_context = "\nHere are some relevant example rows (values in the same order as columns above)\n"
for node in relevant_nodes:
table_row_context += str(node.get_content()) + "\n"
table_info += table_row_context
context_strs.append(table_info)
return "\n\n".join(context_strs)
table_parser_component = FnComponent(fn=get_table_context_and_rows_str) This modification ensures that the query pipeline retrieves not only the table schemas but also the relevant rows that might contain the exact text, thereby improving the accuracy of the node retrieval [1]. |
Beta Was this translation helpful? Give feedback.
-
querypipeline couldn't retrieve correct node via retriever even exact text exists in the redis index, how to debug? @dosu |
Beta Was this translation helpful? Give feedback.
-
how to retrieve exact text exists in the redis index, how to debug? @dosu |
Beta Was this translation helpful? Give feedback.
-
query pipeline couldn't retrieve correct node even exact text exists in the index
Beta Was this translation helpful? Give feedback.
All reactions