How to configure different retrievals with RunnableWithMessageHistory in a RAG pipeline #17512
Replies: 1 comment 2 replies
-
🤖 Hey @strivereep! Great to see you diving into more adventures with LangChain. How's the coding journey going? Based on your code and requirements, it seems like you want to switch between different retrievers based on an 'option' parameter. This is indeed possible in LangChain. You can modify your def get_retriever(input_dict: dict):
option = input_dict.get('option', 'default_option')
if option == 'index1':
return vectorstore1.as_retriever()
else:
return vectorstore2.as_retriever() In this modified function, Then, you can modify your context = itemgetter("human_input") | (lambda x: {"human_input": x, "option": option}) | get_retriever | format_docs In this modified Please note that this solution assumes that the 'option' parameter is always provided in the input dictionary when invoking I hope this helps! If you have any further questions, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I have created chain with history with redis as primary source of memory for storing the chat histories. Everythin is working fine but now I need to pass extra params other than human_input, i.e. say option. And based upon the option params, I want to switch the retriever i.e. if user passes index1, then use vectorstore1 else vectorstore2.
Not sure if this is better way to do that, any other approaches will be fine.
System Info
langchain===0.1.5
langchain-community===0.0.17
langchain_openai===0.0.5
langchain_core=== 0.1.18
langserve===0.0.41
Beta Was this translation helpful? Give feedback.
All reactions