multiple inputs in Query Pipeline (advanced text2sql with run,multi) #14224
Replies: 3 comments 8 replies
-
Hey @sumitbindra! I'm here to help you with any questions or issues you have. Let's work together to solve this problem. To set up
Here is a practical example: from llama_index.core.query_pipeline.query import QueryPipeline
from llama_index.core.query_pipeline.components import QueryComponent
# Define your custom components
class QueryComponent1(QueryComponent):
def run_component(self, query_str, tablename):
# Process the query_str and tablename
return {"processed_query": f"Processed {query_str} for {tablename}"}
class QueryComponent2(QueryComponent):
def run_component(self, processed_query):
# Further process the query
return {"final_output": f"Final output: {processed_query}"}
# Initialize the components
qc1 = QueryComponent1()
qc2 = QueryComponent2()
# Define the query pipeline
pipeline = QueryPipeline()
pipeline.add_modules({"qc1": qc1, "qc2": qc2})
pipeline.add_link("qc1", "qc2", dest_key="processed_query")
# Run the pipeline with multiple inputs
inputs = {
"qc1": {"query_str": "SELECT * FROM users", "tablename": "users"}
}
output = pipeline.run_multi(inputs)
print(output) In this example:
This setup ensures that the inputs are correctly distributed to the respective modules and processed accordingly. You can customize the components and their processing logic as needed for your specific use case. For more detailed information and examples, you can refer to the LlamaIndex documentation on multi-input/multi-output pipelines [1][2][3]. |
Beta Was this translation helpful? Give feedback.
-
when i run this code:
I get the following error: Traceback (most recent call last): How do I fix it? |
Beta Was this translation helpful? Give feedback.
-
do I have to add "tablename" to output keys of Querycomponent1? |
Beta Was this translation helpful? Give feedback.
-
Hello All,
I am trying to figure out how to use multiple inputs in advanced text2sql with a query pipeline. I think using run.multi here is the answer but not sure how it will be implemented if the inputs are used in several modules in query pipeline.
https://docs.llamaindex.ai/en/stable/examples/pipeline/query_pipeline_sql/?h=sql#2-advanced-capability-2-text-to-sql-with-query-time-row-retrieval-along-with-table-retrieval
Run.multi example: https://docs.llamaindex.ai/en/stable/module_guides/querying/pipeline/usage_pattern/#multi-inputmulti-output
The eg above is what I want to implement for multiple inputs in the advanced text to sql query pipeline:
My functions takes in two variables : query_str (string) and tablename (string). The example has only one input component. I tried using run.multi with a dictionary but am confused on how it will be setup if the multiple inputs go in a few different modules.
Would appreciate any help on this.
Beta Was this translation helpful? Give feedback.
All reactions