Find answers from the community

Updated 9 months ago

Hi, I am not able to understand how does

Hi, I am not able to understand how does the Query Pipeline work w.r.t the DAG use case here: https://docs.llamaindex.ai/en/stable/examples/pipeline/query_pipeline_sql/
Once we add the chains and links for the DAG, how is the decision made to traverse a particular path. The following is the QP created:

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")

Now when we run the query:

response = qp.run(
query="What was the year that The Notorious B.I.G was signed to Bad Boy?"
)
print(str(response))

How does the code know which path to take?
L
t
3 comments
There is only one input and one output in a DAG here. Any subpaths all converge.

if you trace all the paths (or call the command to draw it out), you'd see what I mean
Sorry I still don't understand, I did draw it out. However, how does it know that from "input" it has to go to "table_retriever" or "text2sql_prompt" or "response_synthesis_prompt"?
qp.add_chain(["input", "table_retriever", "table_output_parser"])

This links input to table retriever, and table retriever to table output parser

qp.add_link("input", "text2sql_prompt", dest_key="query_str")

This connects input to the query_str input of the text2sql_prompt

qp.add_link("table_output_parser", "text2sql_prompt", dest_key="schema")

This connects the table output parser to the schema input of the text2sql_prompt

Plain Text
qp.add_chain(
    ["text2sql_prompt", "text2sql_llm", "sql_output_parser", "sql_retriever"]
)


This chains together the text2sql prompt, to the llm, to the output parser, to the retriever

Plain Text
qp.add_link(
    "sql_output_parser", "response_synthesis_prompt", dest_key="sql_query"
)


This connects to the sql output parser to the sql query of the response synthesis prompt

Plain Text
qp.add_link(
    "sql_retriever", "response_synthesis_prompt", dest_key="context_str"
)


This connects the sql retriever to the context_str of the response synthsis prompt

qp.add_link("input", "response_synthesis_prompt", dest_key="query_str")

This connects the input as the query_str to the response syntehsis prompt

Plain Text
qp.add_link("response_synthesis_prompt", "response_synthesis_llm")


And lastly, we feed that prompt to an LLM, and thats our output
Add a reply
Sign up and join the conversation on Discord