Class MultiRetrievalQAChain

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.

Example

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

Constructors

Properties

defaultChain: BaseChain<ChainValues, ChainValues>
destinationChains: {
    [name: string]: BaseChain;
}

Type declaration

routerChain: RouterChain
silentErrors: boolean = false
memory?: BaseMemory

Accessors

  • get inputKeys(): string[]
  • Returns string[]

  • get outputKeys(): string[]
  • Returns string[]

Methods

  • Call the chain on all inputs in the list

    Parameters

    • inputs: ChainValues[]
    • Optional config: (BaseCallbackConfig | Callbacks)[]

    Returns Promise<ChainValues[]>

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

    Wraps _call and handles memory.

    Parameters

    • values: ChainValues & {
          signal?: AbortSignal;
          timeout?: number;
      }
    • Optional config: BaseCallbackConfig | Callbacks
    • Optional tags: string[]

      Deprecated

    Returns Promise<ChainValues>

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

    Parameters

    • input: ChainValues

      Input values for the chain run.

    • Optional config: BaseCallbackConfig

      Optional configuration for the Runnable.

    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>>

  • Parameters

    • input: any
    • Optional config: BaseCallbackConfig | Callbacks

    Returns Promise<string>

  • Load a chain from a json-like object describing it.

    Parameters

    Returns Promise<BaseChain<ChainValues, ChainValues>>

  • 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: BaseLanguageModel<any, BaseLanguageModelCallOptions>

      A BaseLanguageModel instance.

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

    Returns MultiRetrievalQAChain

    A new instance of MultiRetrievalQAChain.

  • Parameters

    • llm: BaseLanguageModel<any, BaseLanguageModelCallOptions>
    • retrieverNames: string[]
    • retrieverDescriptions: string[]
    • retrievers: BaseRetriever[]
    • Optional retrieverPrompts: PromptTemplate<any, any>[]
    • Optional defaults: MultiRetrievalDefaults
    • Optional options: Omit<MultiRouteChainInput, "defaultChain">

    Returns MultiRetrievalQAChain

    Deprecated

    Use fromRetrieversAndPrompts instead

Generated using TypeDoc