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)Retrieving from multiple sourcesOn this pageRetrieving from multiple sourcesOften times you may want to do retrieval over multiple sources. These can be different vectorstores (where one contains information about topic X and the other contains info about topic Y). They could also be completely different databases altogether!A key part is is doing as much of the retrieval in parallel as possible. This will keep the latency as low as possible. Luckily, LangChain Expression Language supports parallelism out of the box.Let's take a look where we do retrieval over a SQL database and a vectorstore.from langchain.chat_models import ChatOpenAISet up SQL query‚Äãfrom langchain.utilities import SQLDatabasefrom langchain.chains import create_sql_query_chaindb = SQLDatabase.from_uri("sqlite:///../../../../../notebooks/Chinook.db")query_chain = create_sql_query_chain(ChatOpenAI(temperature=0), db)Set up vectorstore‚Äãfrom langchain.indexes import VectorstoreIndexCreatorfrom langchain.schema.document import Documentindex_creator = VectorstoreIndexCreator()index = index_creator.from_documents([Document(page_content="Foo")])retriever = index.vectorstore.as_retriever()Combine‚Äãfrom langchain.prompts import ChatPromptTemplatesystem_message = """Use the information from the below two sources to answer any questions.Source 1: a SQL database about
Often times you may want to do retrieval over multiple sources. These can be different vectorstores (where one contains information about topic X and the other contains info about topic Y). They could also be completely different databases altogether!
Often times you may want to do retrieval over multiple sources. These can be different vectorstores (where one contains information about topic X and the other contains info about topic Y). They could also be completely different databases altogether! ->: 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)Retrieving from multiple sourcesOn this pageRetrieving from multiple sourcesOften times you may want to do retrieval over multiple sources. These can be different vectorstores (where one contains information about topic X and the other contains info about topic Y). They could also be completely different databases altogether!A key part is is doing as much of the retrieval in parallel as possible. This will keep the latency as low as possible. Luckily, LangChain Expression Language supports parallelism out of the box.Let's take a look where we do retrieval over a SQL database and a vectorstore.from langchain.chat_models import ChatOpenAISet up SQL query‚Äãfrom langchain.utilities import SQLDatabasefrom langchain.chains import create_sql_query_chaindb = SQLDatabase.from_uri("sqlite:///../../../../../notebooks/Chinook.db")query_chain = create_sql_query_chain(ChatOpenAI(temperature=0), db)Set up vectorstore‚Äãfrom langchain.indexes import VectorstoreIndexCreatorfrom langchain.schema.document import Documentindex_creator = VectorstoreIndexCreator()index = index_creator.from_documents([Document(page_content="Foo")])retriever = index.vectorstore.as_retriever()Combine‚Äãfrom langchain.prompts import ChatPromptTemplatesystem_message = """Use the information from the below two sources to answer any questions.Source 1: a SQL database about