Find answers from the community

Updated 3 months ago

Hey guys, I am extremely a beginner so

Hey guys, I am extremely a beginner so forgive me for my naive questions. Also, if this is not the right place to ask, please correct me.

I am trying to develop a Text-to-SQL RAG for my database. I have pretty much followed the example on the LlamaIndex Documentation page here: https://docs.llamaindex.ai/en/stable/examples/pipeline/query_pipeline_sql/

As seen in the example, there are a bunch of modules, including a sql_retriever module and a response_synthesis_prompt module, which has a string defined as the following:

"Given an input question, synthesize a response from the query results.\n"
"Query: {query_str}\n"
"SQL: {sql_query}\n"
"SQL Response: {context_str}\n"
"Response: "

In this case, {context_str} is fed by the sql_retriever module. However, this context string is always in the format of one node object.

So let's say my prompt is "How many entries are in the table?". It goes through the whole query pipeline. But then the {context_str} generated by the sql_retriever module ends up being of a node object defined as something like:
['Node ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx\nText: [(3000,)]\nScore: None\n']

And then so the response synthesis module interprets that as only one entry, instead of 3,000 (as you can see in the node object).

My code is basically exactly what it looks like on the documentation. I feel like there is an obvious solution to this but Idk what it is since I am a pure beginner. Can anyone help? thanks.
a
G
34 comments
thats incorrect buddy context_str isnt gonna be a node , its gonna be the sql query results
its different that those other documents retrievers
if you wanna make text2sql i recommend using a pipeline, llm makes a sql query from the input and the retrieved relevant tables then query the table then synthesize a response
i believe theres an example of it if you look up a text 2 sql
why u say buddy tho
Yea I followed the text 2 sql thing word for word
Wait ill show u
@amamr look, here is the output from the example on the docs itself:

contextstr: [NodeWithScore(node=TextNode(id='23214862-784c-4f2b-b489-39d61ea96580', embedding=None, metadata={}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, hash='c336a1cbf9...

So even they have it as a node object
are you using the first one ?
No I implement the last example which has both table and row retrieval
Plain Text
qp.add_chain(["input", "table_retriever", "table_output_parser"])
qp.add_link("input", "text2sql_prompt", dest_key="query_str")
qp.add_link("table_output_parser", "text2sql_prompt", dest_key="schema")
qp.add_chain(
    ["text2sql_prompt", "text2sql_llm", "sql_output_parser", "sql_retriever"]
)
qp.add_link(
    "sql_output_parser", "response_synthesis_prompt", dest_key="sql_query"
)
qp.add_link(
    "sql_retriever", "response_synthesis_prompt", dest_key="context_str"
)
qp.add_link("input", "response_synthesis_prompt", dest_key="query_str")
qp.add_link("response_synthesis_prompt", "response_synthesis_llm")
Yea I did that
and youre printing the what variable exactly ?
context_str ?
and it gave you this ?
Well i am not printing but i am using pheonix to see the whole pipeline inputs and putputs line by line which prints out in the terminal
yes it gave me that
Wait hold up i think I 'fixed' it

Instead of defining the reponse_synthesis_prompt as:

"Given an input question, synthesize a response from the query results.\n"
"Query: {query_str}\n"
"SQL: {sql_query}\n"
"SQL Response: {context_str}\n"
"Response: "
i just chnaged it to: "SQL Response (in the text field of the following node object: {context_str}"
and its fine now
Lmao sorry to waste your time but thank you appreciate it
you had a typos ? XSD
anws good luck
Not really typo
For some reason my response synthesizer cannot interpret the context str even though i implemented it the same way as the example literally copy and paste hah
Add a reply
Sign up and join the conversation on Discord