37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import { BasicTranslator, Comparators, Operators, } from "@langchain/core/structured_query";
|
|
/**
|
|
* 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.
|
|
* @example
|
|
* ```typescript
|
|
* const chromaTranslator = new ChromaTranslator();
|
|
* const selfQueryRetriever = new SelfQueryRetriever({
|
|
* llm: new ChatOpenAI(),
|
|
* vectorStore: new Chroma(),
|
|
* documentContents: "Brief summary of a movie",
|
|
* attributeInfo: [],
|
|
* structuredQueryTranslator: chromaTranslator,
|
|
* });
|
|
*
|
|
* const relevantDocuments = await selfQueryRetriever.getRelevantDocuments(
|
|
* "Which movies are directed by Greta Gerwig?",
|
|
* );
|
|
* ```
|
|
*/
|
|
export class ChromaTranslator extends BasicTranslator {
|
|
constructor() {
|
|
super({
|
|
allowedOperators: [Operators.and, Operators.or],
|
|
allowedComparators: [
|
|
Comparators.eq,
|
|
Comparators.ne,
|
|
Comparators.gt,
|
|
Comparators.gte,
|
|
Comparators.lt,
|
|
Comparators.lte,
|
|
],
|
|
});
|
|
}
|
|
}
|