Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKQA over structured dataSQLRetrieval-augmented generation (RAG)RAG over codeUsing a RetrieverRemembering chat historyAnalyze a single long documentAgent with retrieval toolText splitting by headerRAG over in-memory documentsRAG using local modelsDynamically select from multiple retrieversRetrieving from multiple sourcesCiting retrieval sourcesRetrieve from vector stores directlyInteracting with APIsChatbotsExtractionSummarizationTaggingWeb scrapingSynthetic data generationGraph queryingRetrieval-augmented generation (RAG)Dynamically select from multiple retrieversDynamically select from multiple retrieversThis notebook demonstrates how to use the RouterChain paradigm to create a chain that dynamically selects which Retrieval system to use. Specifically we show how to use the MultiRetrievalQAChain to create a question-answering chain that selects the retrieval QA chain which is most relevant for a given question, and then answers the question using it.from langchain.chains.router import MultiRetrievalQAChainfrom langchain.llms import OpenAIfrom langchain.embeddings import OpenAIEmbeddingsfrom langchain.document_loaders import TextLoaderfrom langchain.vectorstores import FAISSsou_docs = TextLoader('../../state_of_the_union.txt').load_and_split()sou_retriever = FAISS.from_documents(sou_docs, OpenAIEmbeddings()).as_retriever()pg_docs = TextLoader('../../paul_graham_essay.txt').load_and_split()pg_retriever = FAISS.from_documents(pg_docs, OpenAIEmbeddings()).as_retriever()personal_texts = [    "I love apple pie",    "My favorite color is fuchsia",    "My dream is to become a professional dancer",    "I broke my arm when I was 12",    "My parents are from Peru",]personal_retriever = FAISS.from_texts(personal_texts, OpenAIEmbeddings()).as_retriever()retriever_infos = [    {        "name": "state of the union",        "description": "Good for answering
This notebook demonstrates how to use the RouterChain paradigm to create a chain that dynamically selects which Retrieval system to use. Specifically we show how to use the MultiRetrievalQAChain to create a question-answering chain that selects the retrieval QA chain which is most relevant for a given question, and then answers the question using it.
This notebook demonstrates how to use the RouterChain paradigm to create a chain that dynamically selects which Retrieval system to use. Specifically we show how to use the MultiRetrievalQAChain to create a question-answering chain that selects the retrieval QA chain which is most relevant for a given question, and then answers the question using it. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKQA over structured dataSQLRetrieval-augmented generation (RAG)RAG over codeUsing a RetrieverRemembering chat historyAnalyze a single long documentAgent with retrieval toolText splitting by headerRAG over in-memory documentsRAG using local modelsDynamically select from multiple retrieversRetrieving from multiple sourcesCiting retrieval sourcesRetrieve from vector stores directlyInteracting with APIsChatbotsExtractionSummarizationTaggingWeb scrapingSynthetic data generationGraph queryingRetrieval-augmented generation (RAG)Dynamically select from multiple retrieversDynamically select from multiple retrieversThis notebook demonstrates how to use the RouterChain paradigm to create a chain that dynamically selects which Retrieval system to use. Specifically we show how to use the MultiRetrievalQAChain to create a question-answering chain that selects the retrieval QA chain which is most relevant for a given question, and then answers the question using it.from langchain.chains.router import MultiRetrievalQAChainfrom langchain.llms import OpenAIfrom langchain.embeddings import OpenAIEmbeddingsfrom langchain.document_loaders import TextLoaderfrom langchain.vectorstores import FAISSsou_docs = TextLoader('../../state_of_the_union.txt').load_and_split()sou_retriever = FAISS.from_documents(sou_docs, OpenAIEmbeddings()).as_retriever()pg_docs = TextLoader('../../paul_graham_essay.txt').load_and_split()pg_retriever = FAISS.from_documents(pg_docs, OpenAIEmbeddings()).as_retriever()personal_texts = [    "I love apple pie",    "My favorite color is fuchsia",    "My dream is to become a professional dancer",    "I broke my arm when I was 12",    "My parents are from Peru",]personal_retriever = FAISS.from_texts(personal_texts, OpenAIEmbeddings()).as_retriever()retriever_infos = [    {        "name": "state of the union",        "description": "Good for answering