-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
pinecone.ts
45 lines (44 loc) · 1.28 KB
/
pinecone.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
import type { VectorStoreInterface } from "@langchain/core/vectorstores";
import {
BasicTranslator,
Comparators,
Operators,
} from "@langchain/core/structured_query";
/**
* Specialized translator class that extends the BasicTranslator. It is
* designed to work with PineconeStore, a type of vector store in
* LangChain. The class is initialized with a set of allowed operators and
* comparators, which are used in the translation process to construct
* queries and compare results.
* @example
* ```typescript
* const selfQueryRetriever = SelfQueryRetriever.fromLLM({
* llm: new ChatOpenAI(),
* vectorStore: new PineconeStore(),
* documentContents: "Brief summary of a movie",
* attributeInfo: [],
* structuredQueryTranslator: new PineconeTranslator(),
* });
*
* const queryResult = await selfQueryRetriever.getRelevantDocuments(
* "Which movies are directed by Greta Gerwig?",
* );
* ```
*/
export class PineconeTranslator<
T extends VectorStoreInterface
> extends BasicTranslator<T> {
constructor() {
super({
allowedOperators: [Operators.and, Operators.or],
allowedComparators: [
Comparators.eq,
Comparators.ne,
Comparators.gt,
Comparators.gte,
Comparators.lt,
Comparators.lte,
],
});
}
}