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

    Type Parameters

    • RunOutput

    Parameters

    Returns Promise<RunnableInterface<{
        input: string;
        chat_history?: BaseMessage[] | string;
    } & {
        [key: string]: unknown;
    }, {
        answer: RunOutput;
        context: string;
    } & {
        [key: string]: unknown;
    }>>

    An LCEL Runnable which returns a an object containing at least context and answer keys.

    Example

    // yarn add langchain @langchain/openai

    import { ChatOpenAI } from "@langchain/openai";
    import { pull } from "langchain/hub";
    import { createRetrievalChain } from "langchain/chains/retrieval";
    import { createStuffDocumentsChain } from "langchain/chains/combine_documents";

    const retrievalQAChatPrompt = await pull("langchain-ai/retrieval-qa-chat");
    const llm = new ChatOpenAI({});
    const retriever = ...
    const combineDocsChain = await createStuffDocumentsChain(...);
    const retrievalChain = await createRetrievalChain({
    retriever,
    combineDocsChain,
    });
    const response = await chain.invoke({ input: "..." });

Generated using TypeDoc