-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
chroma.ts
53 lines (51 loc) · 1.6 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
44
45
46
47
48
49
50
51
52
53
import {
BasicTranslator,
Comparators,
Operators,
} from "@langchain/core/structured_query";
import { VectorStore } from "@langchain/core/vectorstores";
import { logVersion020MigrationWarning } from "../../util/entrypoint_deprecation.js";
/* #__PURE__ */ logVersion020MigrationWarning({
oldEntrypointName: "retrievers/self_query/chroma",
newEntrypointName: "structured_query/chroma",
newPackageName: "@langchain/community",
});
/**
* 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?",
* );
* ```
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export class ChromaTranslator<
T extends VectorStore
> extends BasicTranslator<T> {
constructor() {
super({
allowedOperators: [Operators.and, Operators.or],
allowedComparators: [
Comparators.eq,
Comparators.ne,
Comparators.gt,
Comparators.gte,
Comparators.lt,
Comparators.lte,
],
});
}
}