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

    Type Parameters

    • RunOutput

    Parameters

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

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

    // 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: "..." });