Class for question answering over an index. It retrieves relevant documents based on a query. It extends the BaseRetriever class and implements the SelfQueryRetrieverArgs interface.

Example

const selfQueryRetriever = await SelfQueryRetriever.fromLLM({
llm: new ChatOpenAI(),
vectorStore: await HNSWLib.fromDocuments(docs, new OpenAIEmbeddings()),
documentContents: "Brief summary of a movie",
attributeInfo: attributeInfo,
structuredQueryTranslator: new FunctionalTranslator(),
});
const relevantDocuments = await selfQueryRetriever.getRelevantDocuments(
"Which movies are directed by Greta Gerwig?",
);

Type Parameters

Hierarchy

Implements

Constructors

Properties

llmChain: LLMChain<string, any>
structuredQueryTranslator: BaseTranslator<T>
useOriginalQuery: boolean = false
vectorStore: T
searchParams?: {
    filter?: T["FilterType"];
    forceDefaultFilter?: boolean;
    k?: number;
    mergeFiltersOperator?: "and" | "or" | "replace";
} = ...

Type declaration

  • Optional filter?: T["FilterType"]
  • Optional forceDefaultFilter?: boolean
  • Optional k?: number
  • Optional mergeFiltersOperator?: "and" | "or" | "replace"
verbose?: boolean

Methods

  • Static method to create a new SelfQueryRetriever instance from a BaseLanguageModel and a VectorStore. It first loads a query constructor chain using the loadQueryConstructorChain function, then creates a new SelfQueryRetriever instance with the loaded chain and the provided options.

    Type Parameters

    • T extends VectorStore

    Parameters

    Returns SelfQueryRetriever<T>

    A new instance of SelfQueryRetriever.

Generated using TypeDoc