I’m working on a system where users pick a service type and ask questions. Based on their choice, I need to query different Elasticsearch databases and generate answers.
I have three services, each with its own search index. My current approach creates separate chains:
service_x_chain = search_x | template | model
service_y_chain = search_y | template | model
service_z_chain = search_z | template | model
This works but I want to build one unified chain that picks the right searcher automatically:
searchers = {
"service_x": search_x,
"service_y": search_y,
"service_z": search_z
}
def pick_searcher(data):
return searchers[data['service_type']]
unified_chain = RunnableLambda(pick_searcher) | template | model
result = unified_chain.invoke({
"user_query": "What causes ocean waves",
"service_type": "service_y"
})
The issue is that my router function correctly identifies which searcher to use, but then it tries to run that searcher with the full dictionary input. LangChain retrievers only accept plain strings as queries, not dictionaries with multiple keys.
I need to route to the correct retriever while also extracting just the query string for the searcher. Any suggestions on how to handle this parameter passing issue?