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

  • BaseRetriever
    • SelfQueryRetriever

Implements

Constructors

Properties

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

Type declaration

  • Optional filter?: T["FilterType"]
  • Optional forceDefaultFilter?: boolean
  • Optional k?: number
  • Optional mergeFiltersOperator?: "replace" | "and" | "or"
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

    Parameters

    Returns SelfQueryRetriever<T>

    A new instance of SelfQueryRetriever.

Generated using TypeDoc