langchain.js
    Preparing search index...

    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({ model: "gpt-4o-mini" }),
    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 Summary)

    Implements

    Index

    Constructors

    Properties

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

    Accessors

    • get lc_namespace(): string[]

      Returns string[]

    Methods

    • Parameters

      • query: string
      • OptionalrunManager: any

      Returns Promise<Document<Record<string, unknown>>[]>

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

    • Returns string