Create retrieval chain that retrieves documents and then passes them on.
create_retrieval_chain(
retriever: BaseRetriever | Runnable[dict, RetrieverOutput],
combine_docs_chain: Runnable[dict[str, Any], str]
) -> RunnableExample:
# 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": "..."})| Name | Type | Description |
|---|---|---|
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 |
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 |