Find answers from the community

G
GT
Offline, last seen 3 months ago
Joined September 25, 2024
Is there any I can wrap any of the following into a tool?:

my text-to-sql query pipeline is defined as the following:
Plain Text
qp = QueryPipeline(
    modules={..., ..., ...},
    verbose=True
)

I also have an agent wrapped around this pipeline (for retry logic):
Plain Text
agent_worker = QueryPipelineAgentWorker(qp, callback_manager)
agent = agent_worker.as_agent(verbose=True)

I am extremely confused as to how I can have my ReAct chat use the pipeline (or the agent, it doesnt matter which to me) as a "tool". It seems it only "query engines" or functions can be tools. Please any guidance is appreciated
7 comments
k
L
G
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.
34 comments
G
a
I will try that, thank you

But theres also the issue that the ReAct agent picks the tool at all. If i say something like Hi, it shouldnt pick a tool to respond, right?
Is that also just related to the llm not being smart?
3 comments
G
L
Is there any way I can add retry logic to an advanced text-to-sql pipeline? My pipeline is defined below,which is straight from llamaindex docs:

https://docs.llamaindex.ai/en/stable/examples/pipeline/query_pipeline_sql/?h=table+parser#define-expanded-query-pipeline
Plain Text
from llama_index.core.query_pipeline import (
    QueryPipeline as QP,
    Link,
    InputComponent,
    CustomQueryComponent,
)

qp = QP(
    modules={
        "input": InputComponent(),
        "table_retriever": obj_retriever,
        "table_output_parser": table_parser_component,
        "text2sql_prompt": text2sql_prompt,
        "text2sql_llm": llm,
        "sql_output_parser": sql_parser_component,
        "sql_retriever": sql_retriever,
        "response_synthesis_prompt": response_synthesis_prompt,
        "response_synthesis_llm": llm,
    },
    verbose=True,
)

The links and chains are also taken straight from the docs.

I want to implement retry logic such that if the SQL statement and its result is incorrect (incorrect syntax or doesn't address the prompt, for example), it should like "fix" the SQL statement and check it & the results again, and keep doing it until it is correct. (maybe max 3 tries). The problem is I am trying to follow the documentation here: https://docs.llamaindex.ai/en/stable/examples/agent/agent_runner/query_pipeline_agent/#setup-simple-retry-agent-pipeline-for-text-to-sql

But I am unclear as to how exactly I can add this to my already defined pipeline (above). Any help is appreciated, thanks
8 comments
G
L
any help is appreciated. I looked all through the docs and couldn't find anything
4 comments
G
L