-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
chroma.ts
43 lines (42 loc) · 1.26 KB
/
chroma.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Chroma } from "@langchain/community/vectorstores/chroma";
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<T extends Chroma> extends BasicTranslator<T> {
constructor() {
super({
allowedOperators: [Operators.and, Operators.or],
allowedComparators: [
Comparators.eq,
Comparators.ne,
Comparators.gt,
Comparators.gte,
Comparators.lt,
Comparators.lte,
],
});
}
}