Specialized translator for the Chroma vector database. It extends the BasicTranslator class and translates internal query language elements to valid filters. The class defines a subset of allowed logical operators and comparators that can be used in the translation process.

const chromaTranslator = new ChromaTranslator();
const selfQueryRetriever = new SelfQueryRetriever({
llm: new ChatOpenAI({ model: "gpt-4o-mini" }),
vectorStore: new Chroma(),
documentContents: "Brief summary of a movie",
attributeInfo: [],
structuredQueryTranslator: chromaTranslator,
});

const relevantDocuments = await selfQueryRetriever.getRelevantDocuments(
"Which movies are directed by Greta Gerwig?",
);

Type Parameters

Hierarchy (view full)

Constructors

Properties

VisitComparisonOutput: T["FilterType"]
VisitOperationOutput: T["FilterType"]
VisitStructuredQueryOutput: {
    filter?: T["FilterType"];
}
allowedComparators: Comparator[] = ...
allowedOperators: Operator[] = ...

Methods

  • Merges two filters into one, using a specified merge type.

    Parameters

    • defaultFilter: undefined | T["FilterType"]

      The default filter.

    • generatedFilter: undefined | T["FilterType"]

      The generated filter.

    • mergeType: "replace" | "or" | "and" = "and"

      The type of merge to perform. Can be 'and', 'or', or 'replace'.

    • forceDefaultFilter: boolean = false

      If true, the default filter will be used even if the generated filter is not empty.

    Returns undefined | T["FilterType"]

    The merged filter, or undefined if both filters are empty.