query pipelines with router #15852
-
I am trying to extend the Query Pipeline for Advanced Text-to-SQL guide here (https://docs.llamaindex.ai/en/stable/examples/pipeline/query_pipeline_sql/). ValueError Traceback (most recent call last) File /opt/conda/lib/python3.10/site-packages/llama_index/core/query_pipeline/components/router.py:111, in RouterComponent.init(self, selector, choices, components, verbose) ValueError: Expected one required input key |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
Hey there, @debarun-ghosh17! I'm here to help you with any bugs, questions, or contributions you have in mind. Let's tackle this issue together! I found a similar unsolved discussion that might be relevant: Router with a Query Pipeline [1]. To combine a text-to-SQL query pipeline and a RAG-based pipeline using a
Here is an example code snippet to illustrate this: from llama_index.legacy.core.query_pipeline.components.router import RouterComponent
from llama_index.legacy.core.base_selector import BaseSelector
from llama_index.legacy.core.query_pipeline.query_component import QueryComponent, InputKeys, OutputKeys
# Define your selector (assuming you have a custom selector implementation)
class MySelector(BaseSelector):
def select(self, choices, query):
# Custom logic to select the appropriate component
pass
# Define your text-to-SQL query component
class TextToSQLComponent(QueryComponent):
@property
def input_keys(self):
return InputKeys.from_keys({"query"})
@property
def output_keys(self):
return OutputKeys.from_keys({"output"})
def _run_component(self, **kwargs):
# Implementation of the text-to-SQL logic
pass
# Define your RAG-based query component
class RAGComponent(QueryComponent):
@property
def input_keys(self):
return InputKeys.from_keys({"query"})
@property
def output_keys(self):
return OutputKeys.from_keys({"output"})
def _run_component(self, **kwargs):
# Implementation of the RAG-based logic
pass
# Initialize the components
text_to_sql_component = TextToSQLComponent()
rag_component = RAGComponent()
# Initialize the selector
selector = MySelector()
# Initialize the RouterComponent
router_component = RouterComponent(
selector=selector,
choices=["text_to_sql", "rag"],
components=[text_to_sql_component, rag_component],
verbose=True
)
# Now you can use the router_component to route queries
result = router_component.run_component(query="Your query here") In this example:
This setup ensures that the |
Beta Was this translation helpful? Give feedback.
To resolve the error and set the input keys correctly, you should use the
InputKeys
class to define the required and optional keys for each component. Here’s how you can do it:Define the Input and Output Keys for Each Pipeline: Use the
InputKeys
class to specify the required and optional keys.Wrap Each Pipeline in a Component: Create a wrapper component for each pipeline that conforms to the single input key requirement.
Initialize the RouterComponent: Pass the wrapped components to the
RouterComponent
.Here’s an example: