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.

const selfQueryRetriever = 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 (view full)

Implements

Constructors

Properties

queryConstructor: RunnableInterface<{
    query: string;
}, StructuredQuery>
structuredQueryTranslator: BaseTranslator<T>
useOriginalQuery: boolean = false
vectorStore: T
searchParams?: {
    filter?: T["FilterType"];
    forceDefaultFilter?: boolean;
    k?: number;
    mergeFiltersOperator?: "replace" | "or" | "and";
} = ...
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.