LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • MCP Adapters
    • Overview
    • Agents
    • Callbacks
    • Chains
    • Chat models
    • Embeddings
    • Evaluation
    • Globals
    • Hub
    • Memory
    • Output parsers
    • Retrievers
    • Runnables
    • LangSmith
    • Storage
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    MCP Adapters
    OverviewAgentsCallbacksChainsChat modelsEmbeddingsEvaluationGlobalsHubMemoryOutput parsersRetrieversRunnablesLangSmithStorage
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-classicchainsretrievalcreate_retrieval_chain
    Function●Since v1.0

    create_retrieval_chain

    Create retrieval chain that retrieves documents and then passes them on.

    Copy
    create_retrieval_chain(
      retriever: BaseRetriever | Runnable[dict, RetrieverOutput],
      combine_docs_chain: Runnable[dict[str, Any], str]
    ) -> Runnable

    Example:

    # pip install -U langchain langchain-openai
    
    from langchain_openai import ChatOpenAI
    from langchain_classic.chains.combine_documents import (
        create_stuff_documents_chain,
    )
    from langchain_classic.chains import create_retrieval_chain
    from langchain_classic import hub
    
    retrieval_qa_chat_prompt = hub.pull("langchain-ai/retrieval-qa-chat")
    model = ChatOpenAI()
    retriever = ...
    combine_docs_chain = create_stuff_documents_chain(
        model, retrieval_qa_chat_prompt
    )
    retrieval_chain = create_retrieval_chain(retriever, combine_docs_chain)
    
    retrieval_chain.invoke({"input": "..."})

    Used in Docs

    • Alibaba cloud mysql integration
    • ApertureDB integration
    • Docling integration
    • Image captions integration
    • Jina reranker integration

    Parameters

    NameTypeDescription
    retriever*BaseRetriever | Runnable[dict, RetrieverOutput]

    Retriever-like object that returns list of documents. Should either be a subclass of BaseRetriever or a Runnable that returns a list of documents. If a subclass of BaseRetriever, then it is expected that an input key be passed in - this is what is will be used to pass into the retriever. If this is NOT a subclass of BaseRetriever, then all the inputs will be passed into this runnable, meaning that runnable should take a dictionary as input.

    combine_docs_chain*Runnable[dict[str, Any], str]

    Runnable that takes inputs and produces a string output. The inputs to this will be any original inputs to this chain, a new context key with the retrieved documents, and chat_history (if not present in the inputs) with a value of [] (to easily enable conversational retrieval.

    View source on GitHub