A class that represents a multi-retrieval question answering chain in the LangChain framework. It extends the MultiRouteChain class and provides additional functionality specific to multi-retrieval QA chains.

const multiRetrievalQAChain = MultiRetrievalQAChain.fromLLMAndRetrievers(
new ChatOpenAI(),
{
retrieverNames: ["aqua teen", "mst3k", "animaniacs"],
retrieverDescriptions: [
"Good for answering questions about Aqua Teen Hunger Force theme song",
"Good for answering questions about Mystery Science Theater 3000 theme song",
"Good for answering questions about Animaniacs theme song",
],
retrievers: [
new MemoryVectorStore().asRetriever(3),
new MemoryVectorStore().asRetriever(3),
new MemoryVectorStore().asRetriever(3),
],
retrievalQAChainOpts: {
returnSourceDocuments: true,
},
},
);

const result = await multiRetrievalQAChain.call({
input:
"In the Aqua Teen Hunger Force theme song, who calls himself the mike rula?",
});

console.log(result.sourceDocuments, result.text);

Hierarchy (view full)

Constructors

Properties

defaultChain: BaseChain<ChainValues, ChainValues>
destinationChains: {
    [name: string]: BaseChain;
}
routerChain: RouterChain
silentErrors: boolean = false
memory?: any

Accessors

Methods

  • Parameters

    • inputs: ChainValues[]
    • Optionalconfig: any[]

    Returns Promise<ChainValues[]>

    Use .batch() instead. Will be removed in 0.2.0.

    Call the chain on all inputs in the list

  • Parameters

    • values: any
    • Optionalconfig: any
    • Optionaltags: string[]

    Returns Promise<ChainValues>

    Use .invoke() instead. Will be removed in 0.2.0.

    Run the core logic of this chain and add to output if desired.

    Wraps _call and handles memory.

  • Invoke the chain with the provided input and returns the output.

    Parameters

    • input: ChainValues

      Input values for the chain run.

    • Optionaloptions: any

    Returns Promise<ChainValues>

    Promise that resolves with the output of the chain run.

  • Parameters

    • inputs: Record<string, unknown>
    • outputs: Record<string, unknown>
    • returnOnlyOutputs: boolean = false

    Returns Promise<Record<string, unknown>>

  • A static method that creates an instance of MultiRetrievalQAChain from a BaseLanguageModel and a set of retrievers. It takes in optional parameters for the retriever names, descriptions, prompts, defaults, and additional options. It is an alternative method to fromRetrievers and provides more flexibility in configuring the underlying chains.

    Parameters

    • llm: BaseLanguageModelInterface

      A BaseLanguageModel instance.

    • __namedParameters: {
          retrieverDescriptions: string[];
          retrieverNames: string[];
          retrievers: BaseRetrieverInterface[];
          defaults?: MultiRetrievalDefaults;
          multiRetrievalChainOpts?: Omit<MultiRouteChainInput, "defaultChain">;
          retrievalQAChainOpts?: Partial<Omit<RetrievalQAChainInput, "retriever" | "combineDocumentsChain">> & {
              prompt?: any;
          };
          retrieverPrompts?: PromptTemplate[];
      }
      • retrieverDescriptions: string[]
      • retrieverNames: string[]
      • retrievers: BaseRetrieverInterface[]
      • Optionaldefaults?: MultiRetrievalDefaults
      • OptionalmultiRetrievalChainOpts?: Omit<MultiRouteChainInput, "defaultChain">
      • OptionalretrievalQAChainOpts?: Partial<Omit<RetrievalQAChainInput, "retriever" | "combineDocumentsChain">> & {
            prompt?: any;
        }
      • OptionalretrieverPrompts?: PromptTemplate[]

    Returns MultiRetrievalQAChain

    A new instance of MultiRetrievalQAChain.