langchain 0.0.143 → 0.0.145
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/callbacks/handlers/llmonitor.cjs +1 -0
- package/callbacks/handlers/llmonitor.d.ts +1 -0
- package/callbacks/handlers/llmonitor.js +1 -0
- package/dist/agents/mrkl/outputParser.cjs +1 -1
- package/dist/agents/mrkl/outputParser.js +1 -1
- package/dist/base_language/index.cjs +2 -1
- package/dist/base_language/index.d.ts +7 -2
- package/dist/base_language/index.js +2 -1
- package/dist/callbacks/handlers/llmonitor.cjs +223 -0
- package/dist/callbacks/handlers/llmonitor.d.ts +35 -0
- package/dist/callbacks/handlers/llmonitor.js +215 -0
- package/dist/chains/openai_functions/extraction.d.ts +4 -4
- package/dist/chains/openai_functions/openapi.d.ts +3 -3
- package/dist/chains/openai_functions/structured_output.d.ts +5 -4
- package/dist/chains/openai_functions/tagging.d.ts +4 -4
- package/dist/chains/openai_moderation.cjs +1 -0
- package/dist/chains/openai_moderation.js +1 -0
- package/dist/chat_models/base.cjs +4 -3
- package/dist/chat_models/base.d.ts +3 -3
- package/dist/chat_models/base.js +5 -4
- package/dist/chat_models/minimax.d.ts +6 -28
- package/dist/chat_models/openai.d.ts +2 -3
- package/dist/document_loaders/fs/openai_whisper_audio.cjs +32 -0
- package/dist/document_loaders/fs/openai_whisper_audio.d.ts +11 -0
- package/dist/document_loaders/fs/openai_whisper_audio.js +28 -0
- package/dist/document_loaders/web/github.cjs +210 -24
- package/dist/document_loaders/web/github.d.ts +44 -1
- package/dist/document_loaders/web/github.js +210 -24
- package/dist/document_loaders/web/recursive_url.cjs +13 -0
- package/dist/document_loaders/web/recursive_url.js +13 -0
- package/dist/embeddings/hf_transformers.cjs +71 -0
- package/dist/embeddings/hf_transformers.d.ts +29 -0
- package/dist/embeddings/hf_transformers.js +67 -0
- package/dist/embeddings/ollama.cjs +114 -0
- package/dist/embeddings/ollama.d.ts +34 -0
- package/dist/embeddings/ollama.js +110 -0
- package/dist/experimental/chat_models/anthropic_functions.d.ts +2 -5
- package/dist/load/import_constants.cjs +3 -0
- package/dist/load/import_constants.js +3 -0
- package/dist/load/import_map.cjs +3 -2
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/prompts/chat.cjs +27 -1
- package/dist/prompts/chat.d.ts +3 -2
- package/dist/prompts/chat.js +28 -2
- package/dist/schema/index.cjs +44 -1
- package/dist/schema/index.d.ts +10 -0
- package/dist/schema/index.js +41 -0
- package/dist/tools/serpapi.cjs +108 -13
- package/dist/tools/serpapi.js +108 -13
- package/dist/vectorstores/redis.cjs +12 -4
- package/dist/vectorstores/redis.d.ts +8 -0
- package/dist/vectorstores/redis.js +12 -4
- package/dist/vectorstores/tigris.cjs +2 -0
- package/dist/vectorstores/tigris.d.ts +2 -3
- package/dist/vectorstores/tigris.js +2 -0
- package/dist/vectorstores/vectara.cjs +30 -12
- package/dist/vectorstores/vectara.d.ts +1 -1
- package/dist/vectorstores/vectara.js +30 -12
- package/document_loaders/fs/openai_whisper_audio.cjs +1 -0
- package/document_loaders/fs/openai_whisper_audio.d.ts +1 -0
- package/document_loaders/fs/openai_whisper_audio.js +1 -0
- package/embeddings/hf_transformers.cjs +1 -0
- package/embeddings/hf_transformers.d.ts +1 -0
- package/embeddings/hf_transformers.js +1 -0
- package/embeddings/ollama.cjs +1 -0
- package/embeddings/ollama.d.ts +1 -0
- package/embeddings/ollama.js +1 -0
- package/package.json +52 -14
package/dist/tools/serpapi.cjs
CHANGED
|
@@ -82,25 +82,120 @@ class SerpAPI extends base_js_1.Tool {
|
|
|
82
82
|
if (res.error) {
|
|
83
83
|
throw new Error(`Got error from serpAPI: ${res.error}`);
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
const answer_box = res.answer_box_list
|
|
86
|
+
? res.answer_box_list[0]
|
|
87
|
+
: res.answer_box;
|
|
88
|
+
if (answer_box) {
|
|
89
|
+
if (answer_box.result) {
|
|
90
|
+
return answer_box.result;
|
|
91
|
+
}
|
|
92
|
+
else if (answer_box.answer) {
|
|
93
|
+
return answer_box.answer;
|
|
94
|
+
}
|
|
95
|
+
else if (answer_box.snippet) {
|
|
96
|
+
return answer_box.snippet;
|
|
97
|
+
}
|
|
98
|
+
else if (answer_box.snippet_highlighted_words) {
|
|
99
|
+
return answer_box.snippet_highlighted_words.toString();
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const answer = {};
|
|
103
|
+
Object.keys(answer_box)
|
|
104
|
+
.filter((k) => !Array.isArray(answer_box[k]) &&
|
|
105
|
+
typeof answer_box[k] !== "object" &&
|
|
106
|
+
!(typeof answer_box[k] === "string" &&
|
|
107
|
+
answer_box[k].startsWith("http")))
|
|
108
|
+
.forEach((k) => {
|
|
109
|
+
answer[k] = answer_box[k];
|
|
110
|
+
});
|
|
111
|
+
return JSON.stringify(answer);
|
|
112
|
+
}
|
|
87
113
|
}
|
|
88
|
-
if (res.
|
|
89
|
-
return res.
|
|
114
|
+
if (res.events_results) {
|
|
115
|
+
return JSON.stringify(res.events_results);
|
|
90
116
|
}
|
|
91
|
-
if (res.
|
|
92
|
-
return res.
|
|
117
|
+
if (res.sports_results) {
|
|
118
|
+
return JSON.stringify(res.sports_results);
|
|
93
119
|
}
|
|
94
|
-
if (res.
|
|
95
|
-
return res.
|
|
120
|
+
if (res.top_stories) {
|
|
121
|
+
return JSON.stringify(res.top_stories);
|
|
96
122
|
}
|
|
97
|
-
if (res.
|
|
98
|
-
return res.
|
|
123
|
+
if (res.news_results) {
|
|
124
|
+
return JSON.stringify(res.news_results);
|
|
99
125
|
}
|
|
100
|
-
if (res.
|
|
101
|
-
return res.
|
|
126
|
+
if (res.jobs_results?.jobs) {
|
|
127
|
+
return JSON.stringify(res.jobs_results.jobs);
|
|
128
|
+
}
|
|
129
|
+
if (res.questions_and_answers) {
|
|
130
|
+
return JSON.stringify(res.questions_and_answers);
|
|
131
|
+
}
|
|
132
|
+
if (res.popular_destinations?.destinations) {
|
|
133
|
+
return JSON.stringify(res.popular_destinations.destinations);
|
|
134
|
+
}
|
|
135
|
+
if (res.top_sights?.sights) {
|
|
136
|
+
const sights = res.top_sights.sights
|
|
137
|
+
.map((s) => ({
|
|
138
|
+
title: s.title,
|
|
139
|
+
description: s.description,
|
|
140
|
+
price: s.price,
|
|
141
|
+
}))
|
|
142
|
+
.slice(0, 8);
|
|
143
|
+
return JSON.stringify(sights);
|
|
144
|
+
}
|
|
145
|
+
if (res.shopping_results && res.shopping_results[0]?.title) {
|
|
146
|
+
return JSON.stringify(res.shopping_results.slice(0, 3));
|
|
147
|
+
}
|
|
148
|
+
if (res.images_results && res.images_results[0]?.thumbnail) {
|
|
149
|
+
return res.images_results
|
|
150
|
+
.map((ir) => ir.thumbnail)
|
|
151
|
+
.slice(0, 10)
|
|
152
|
+
.toString();
|
|
153
|
+
}
|
|
154
|
+
const snippets = [];
|
|
155
|
+
if (res.knowledge_graph) {
|
|
156
|
+
if (res.knowledge_graph.description) {
|
|
157
|
+
snippets.push(res.knowledge_graph.description);
|
|
158
|
+
}
|
|
159
|
+
const title = res.knowledge_graph.title || "";
|
|
160
|
+
Object.keys(res.knowledge_graph)
|
|
161
|
+
.filter((k) => typeof res.knowledge_graph[k] === "string" &&
|
|
162
|
+
k !== "title" &&
|
|
163
|
+
k !== "description" &&
|
|
164
|
+
!k.endsWith("_stick") &&
|
|
165
|
+
!k.endsWith("_link") &&
|
|
166
|
+
!k.startsWith("http"))
|
|
167
|
+
.forEach((k) => snippets.push(`${title} ${k}: ${res.knowledge_graph[k]}`));
|
|
168
|
+
}
|
|
169
|
+
const first_organic_result = res.organic_results?.[0];
|
|
170
|
+
if (first_organic_result) {
|
|
171
|
+
if (first_organic_result.snippet) {
|
|
172
|
+
snippets.push(first_organic_result.snippet);
|
|
173
|
+
}
|
|
174
|
+
else if (first_organic_result.snippet_highlighted_words) {
|
|
175
|
+
snippets.push(first_organic_result.snippet_highlighted_words);
|
|
176
|
+
}
|
|
177
|
+
else if (first_organic_result.rich_snippet) {
|
|
178
|
+
snippets.push(first_organic_result.rich_snippet);
|
|
179
|
+
}
|
|
180
|
+
else if (first_organic_result.rich_snippet_table) {
|
|
181
|
+
snippets.push(first_organic_result.rich_snippet_table);
|
|
182
|
+
}
|
|
183
|
+
else if (first_organic_result.link) {
|
|
184
|
+
snippets.push(first_organic_result.link);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (res.buying_guide) {
|
|
188
|
+
snippets.push(res.buying_guide);
|
|
189
|
+
}
|
|
190
|
+
if (res.local_results?.places) {
|
|
191
|
+
snippets.push(res.local_results.places);
|
|
192
|
+
}
|
|
193
|
+
if (snippets.length > 0) {
|
|
194
|
+
return JSON.stringify(snippets);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
return "No good search result found";
|
|
102
198
|
}
|
|
103
|
-
return "No good search result found";
|
|
104
199
|
}
|
|
105
200
|
}
|
|
106
201
|
exports.SerpAPI = SerpAPI;
|
package/dist/tools/serpapi.js
CHANGED
|
@@ -79,24 +79,119 @@ export class SerpAPI extends Tool {
|
|
|
79
79
|
if (res.error) {
|
|
80
80
|
throw new Error(`Got error from serpAPI: ${res.error}`);
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
const answer_box = res.answer_box_list
|
|
83
|
+
? res.answer_box_list[0]
|
|
84
|
+
: res.answer_box;
|
|
85
|
+
if (answer_box) {
|
|
86
|
+
if (answer_box.result) {
|
|
87
|
+
return answer_box.result;
|
|
88
|
+
}
|
|
89
|
+
else if (answer_box.answer) {
|
|
90
|
+
return answer_box.answer;
|
|
91
|
+
}
|
|
92
|
+
else if (answer_box.snippet) {
|
|
93
|
+
return answer_box.snippet;
|
|
94
|
+
}
|
|
95
|
+
else if (answer_box.snippet_highlighted_words) {
|
|
96
|
+
return answer_box.snippet_highlighted_words.toString();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const answer = {};
|
|
100
|
+
Object.keys(answer_box)
|
|
101
|
+
.filter((k) => !Array.isArray(answer_box[k]) &&
|
|
102
|
+
typeof answer_box[k] !== "object" &&
|
|
103
|
+
!(typeof answer_box[k] === "string" &&
|
|
104
|
+
answer_box[k].startsWith("http")))
|
|
105
|
+
.forEach((k) => {
|
|
106
|
+
answer[k] = answer_box[k];
|
|
107
|
+
});
|
|
108
|
+
return JSON.stringify(answer);
|
|
109
|
+
}
|
|
84
110
|
}
|
|
85
|
-
if (res.
|
|
86
|
-
return res.
|
|
111
|
+
if (res.events_results) {
|
|
112
|
+
return JSON.stringify(res.events_results);
|
|
87
113
|
}
|
|
88
|
-
if (res.
|
|
89
|
-
return res.
|
|
114
|
+
if (res.sports_results) {
|
|
115
|
+
return JSON.stringify(res.sports_results);
|
|
90
116
|
}
|
|
91
|
-
if (res.
|
|
92
|
-
return res.
|
|
117
|
+
if (res.top_stories) {
|
|
118
|
+
return JSON.stringify(res.top_stories);
|
|
93
119
|
}
|
|
94
|
-
if (res.
|
|
95
|
-
return res.
|
|
120
|
+
if (res.news_results) {
|
|
121
|
+
return JSON.stringify(res.news_results);
|
|
96
122
|
}
|
|
97
|
-
if (res.
|
|
98
|
-
return res.
|
|
123
|
+
if (res.jobs_results?.jobs) {
|
|
124
|
+
return JSON.stringify(res.jobs_results.jobs);
|
|
125
|
+
}
|
|
126
|
+
if (res.questions_and_answers) {
|
|
127
|
+
return JSON.stringify(res.questions_and_answers);
|
|
128
|
+
}
|
|
129
|
+
if (res.popular_destinations?.destinations) {
|
|
130
|
+
return JSON.stringify(res.popular_destinations.destinations);
|
|
131
|
+
}
|
|
132
|
+
if (res.top_sights?.sights) {
|
|
133
|
+
const sights = res.top_sights.sights
|
|
134
|
+
.map((s) => ({
|
|
135
|
+
title: s.title,
|
|
136
|
+
description: s.description,
|
|
137
|
+
price: s.price,
|
|
138
|
+
}))
|
|
139
|
+
.slice(0, 8);
|
|
140
|
+
return JSON.stringify(sights);
|
|
141
|
+
}
|
|
142
|
+
if (res.shopping_results && res.shopping_results[0]?.title) {
|
|
143
|
+
return JSON.stringify(res.shopping_results.slice(0, 3));
|
|
144
|
+
}
|
|
145
|
+
if (res.images_results && res.images_results[0]?.thumbnail) {
|
|
146
|
+
return res.images_results
|
|
147
|
+
.map((ir) => ir.thumbnail)
|
|
148
|
+
.slice(0, 10)
|
|
149
|
+
.toString();
|
|
150
|
+
}
|
|
151
|
+
const snippets = [];
|
|
152
|
+
if (res.knowledge_graph) {
|
|
153
|
+
if (res.knowledge_graph.description) {
|
|
154
|
+
snippets.push(res.knowledge_graph.description);
|
|
155
|
+
}
|
|
156
|
+
const title = res.knowledge_graph.title || "";
|
|
157
|
+
Object.keys(res.knowledge_graph)
|
|
158
|
+
.filter((k) => typeof res.knowledge_graph[k] === "string" &&
|
|
159
|
+
k !== "title" &&
|
|
160
|
+
k !== "description" &&
|
|
161
|
+
!k.endsWith("_stick") &&
|
|
162
|
+
!k.endsWith("_link") &&
|
|
163
|
+
!k.startsWith("http"))
|
|
164
|
+
.forEach((k) => snippets.push(`${title} ${k}: ${res.knowledge_graph[k]}`));
|
|
165
|
+
}
|
|
166
|
+
const first_organic_result = res.organic_results?.[0];
|
|
167
|
+
if (first_organic_result) {
|
|
168
|
+
if (first_organic_result.snippet) {
|
|
169
|
+
snippets.push(first_organic_result.snippet);
|
|
170
|
+
}
|
|
171
|
+
else if (first_organic_result.snippet_highlighted_words) {
|
|
172
|
+
snippets.push(first_organic_result.snippet_highlighted_words);
|
|
173
|
+
}
|
|
174
|
+
else if (first_organic_result.rich_snippet) {
|
|
175
|
+
snippets.push(first_organic_result.rich_snippet);
|
|
176
|
+
}
|
|
177
|
+
else if (first_organic_result.rich_snippet_table) {
|
|
178
|
+
snippets.push(first_organic_result.rich_snippet_table);
|
|
179
|
+
}
|
|
180
|
+
else if (first_organic_result.link) {
|
|
181
|
+
snippets.push(first_organic_result.link);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (res.buying_guide) {
|
|
185
|
+
snippets.push(res.buying_guide);
|
|
186
|
+
}
|
|
187
|
+
if (res.local_results?.places) {
|
|
188
|
+
snippets.push(res.local_results.places);
|
|
189
|
+
}
|
|
190
|
+
if (snippets.length > 0) {
|
|
191
|
+
return JSON.stringify(snippets);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
return "No good search result found";
|
|
99
195
|
}
|
|
100
|
-
return "No good search result found";
|
|
101
196
|
}
|
|
102
197
|
}
|
|
@@ -33,6 +33,12 @@ class RedisVectorStore extends base_js_1.VectorStore {
|
|
|
33
33
|
writable: true,
|
|
34
34
|
value: void 0
|
|
35
35
|
});
|
|
36
|
+
Object.defineProperty(this, "createIndexOptions", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: void 0
|
|
41
|
+
});
|
|
36
42
|
Object.defineProperty(this, "keyPrefix", {
|
|
37
43
|
enumerable: true,
|
|
38
44
|
configurable: true,
|
|
@@ -74,6 +80,11 @@ class RedisVectorStore extends base_js_1.VectorStore {
|
|
|
74
80
|
this.metadataKey = _dbConfig.metadataKey ?? "metadata";
|
|
75
81
|
this.vectorKey = _dbConfig.vectorKey ?? "content_vector";
|
|
76
82
|
this.filter = _dbConfig.filter;
|
|
83
|
+
this.createIndexOptions = {
|
|
84
|
+
ON: "HASH",
|
|
85
|
+
PREFIX: this.keyPrefix,
|
|
86
|
+
..._dbConfig.createIndexOptions,
|
|
87
|
+
};
|
|
77
88
|
}
|
|
78
89
|
/**
|
|
79
90
|
* Method for adding documents to the RedisVectorStore. It first converts
|
|
@@ -228,10 +239,7 @@ class RedisVectorStore extends base_js_1.VectorStore {
|
|
|
228
239
|
[this.contentKey]: redis_1.SchemaFieldTypes.TEXT,
|
|
229
240
|
[this.metadataKey]: redis_1.SchemaFieldTypes.TEXT,
|
|
230
241
|
};
|
|
231
|
-
await this.redisClient.ft.create(this.indexName, schema,
|
|
232
|
-
ON: "HASH",
|
|
233
|
-
PREFIX: this.keyPrefix,
|
|
234
|
-
});
|
|
242
|
+
await this.redisClient.ft.create(this.indexName, schema, this.createIndexOptions);
|
|
235
243
|
}
|
|
236
244
|
/**
|
|
237
245
|
* Method for dropping an index from the RedisVectorStore.
|
|
@@ -29,6 +29,11 @@ export type CreateSchemaHNSWVectorField = CreateSchemaVectorField<VectorAlgorith
|
|
|
29
29
|
EF_CONSTRUCTION?: number;
|
|
30
30
|
EF_RUNTIME?: number;
|
|
31
31
|
}>;
|
|
32
|
+
type CreateIndexOptions = NonNullable<Parameters<ReturnType<typeof createClient>["ft"]["create"]>[3]>;
|
|
33
|
+
export type RedisSearchLanguages = `${NonNullable<CreateIndexOptions["LANGUAGE"]>}`;
|
|
34
|
+
export type RedisVectorStoreIndexOptions = Omit<CreateIndexOptions, "LANGUAGE"> & {
|
|
35
|
+
LANGUAGE?: RedisSearchLanguages;
|
|
36
|
+
};
|
|
32
37
|
/**
|
|
33
38
|
* Interface for the configuration of the RedisVectorStore. It includes
|
|
34
39
|
* the Redis client, index name, index options, key prefix, content key,
|
|
@@ -38,6 +43,7 @@ export interface RedisVectorStoreConfig {
|
|
|
38
43
|
redisClient: ReturnType<typeof createClient> | ReturnType<typeof createCluster>;
|
|
39
44
|
indexName: string;
|
|
40
45
|
indexOptions?: CreateSchemaFlatVectorField | CreateSchemaHNSWVectorField;
|
|
46
|
+
createIndexOptions?: Omit<RedisVectorStoreIndexOptions, "PREFIX">;
|
|
41
47
|
keyPrefix?: string;
|
|
42
48
|
contentKey?: string;
|
|
43
49
|
metadataKey?: string;
|
|
@@ -67,6 +73,7 @@ export declare class RedisVectorStore extends VectorStore {
|
|
|
67
73
|
private redisClient;
|
|
68
74
|
indexName: string;
|
|
69
75
|
indexOptions: CreateSchemaFlatVectorField | CreateSchemaHNSWVectorField;
|
|
76
|
+
createIndexOptions: CreateIndexOptions;
|
|
70
77
|
keyPrefix: string;
|
|
71
78
|
contentKey: string;
|
|
72
79
|
metadataKey: string;
|
|
@@ -176,3 +183,4 @@ export declare class RedisVectorStore extends VectorStore {
|
|
|
176
183
|
*/
|
|
177
184
|
private getFloat32Buffer;
|
|
178
185
|
}
|
|
186
|
+
export {};
|
|
@@ -30,6 +30,12 @@ export class RedisVectorStore extends VectorStore {
|
|
|
30
30
|
writable: true,
|
|
31
31
|
value: void 0
|
|
32
32
|
});
|
|
33
|
+
Object.defineProperty(this, "createIndexOptions", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
33
39
|
Object.defineProperty(this, "keyPrefix", {
|
|
34
40
|
enumerable: true,
|
|
35
41
|
configurable: true,
|
|
@@ -71,6 +77,11 @@ export class RedisVectorStore extends VectorStore {
|
|
|
71
77
|
this.metadataKey = _dbConfig.metadataKey ?? "metadata";
|
|
72
78
|
this.vectorKey = _dbConfig.vectorKey ?? "content_vector";
|
|
73
79
|
this.filter = _dbConfig.filter;
|
|
80
|
+
this.createIndexOptions = {
|
|
81
|
+
ON: "HASH",
|
|
82
|
+
PREFIX: this.keyPrefix,
|
|
83
|
+
..._dbConfig.createIndexOptions,
|
|
84
|
+
};
|
|
74
85
|
}
|
|
75
86
|
/**
|
|
76
87
|
* Method for adding documents to the RedisVectorStore. It first converts
|
|
@@ -225,10 +236,7 @@ export class RedisVectorStore extends VectorStore {
|
|
|
225
236
|
[this.contentKey]: SchemaFieldTypes.TEXT,
|
|
226
237
|
[this.metadataKey]: SchemaFieldTypes.TEXT,
|
|
227
238
|
};
|
|
228
|
-
await this.redisClient.ft.create(this.indexName, schema,
|
|
229
|
-
ON: "HASH",
|
|
230
|
-
PREFIX: this.keyPrefix,
|
|
231
|
-
});
|
|
239
|
+
await this.redisClient.ft.create(this.indexName, schema, this.createIndexOptions);
|
|
232
240
|
}
|
|
233
241
|
/**
|
|
234
242
|
* Method for dropping an index from the RedisVectorStore.
|
|
@@ -37,6 +37,7 @@ class TigrisVectorStore extends base_js_1.VectorStore {
|
|
|
37
37
|
}
|
|
38
38
|
constructor(embeddings, args) {
|
|
39
39
|
super(embeddings, args);
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
41
|
Object.defineProperty(this, "index", {
|
|
41
42
|
enumerable: true,
|
|
42
43
|
configurable: true,
|
|
@@ -98,6 +99,7 @@ class TigrisVectorStore extends base_js_1.VectorStore {
|
|
|
98
99
|
if (!result) {
|
|
99
100
|
return [];
|
|
100
101
|
}
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
103
|
return result.map(([document, score]) => [
|
|
102
104
|
new document_js_1.Document({
|
|
103
105
|
pageContent: document.content,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { VectorDocumentStore as VectorDocumentStoreT } from "@tigrisdata/vector";
|
|
2
1
|
import { Embeddings } from "../embeddings/base.js";
|
|
3
2
|
import { VectorStore } from "./base.js";
|
|
4
3
|
import { Document } from "../document.js";
|
|
@@ -7,14 +6,14 @@ import { Document } from "../document.js";
|
|
|
7
6
|
* TigrisVectorStore instance.
|
|
8
7
|
*/
|
|
9
8
|
export type TigrisLibArgs = {
|
|
10
|
-
index:
|
|
9
|
+
index: any;
|
|
11
10
|
};
|
|
12
11
|
/**
|
|
13
12
|
* Class for managing and operating vector search applications with
|
|
14
13
|
* Tigris, an open-source Serverless NoSQL Database and Search Platform.
|
|
15
14
|
*/
|
|
16
15
|
export declare class TigrisVectorStore extends VectorStore {
|
|
17
|
-
index?:
|
|
16
|
+
index?: any;
|
|
18
17
|
_vectorstoreType(): string;
|
|
19
18
|
constructor(embeddings: Embeddings, args: TigrisLibArgs);
|
|
20
19
|
/**
|
|
@@ -11,6 +11,7 @@ export class TigrisVectorStore extends VectorStore {
|
|
|
11
11
|
}
|
|
12
12
|
constructor(embeddings, args) {
|
|
13
13
|
super(embeddings, args);
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
15
|
Object.defineProperty(this, "index", {
|
|
15
16
|
enumerable: true,
|
|
16
17
|
configurable: true,
|
|
@@ -72,6 +73,7 @@ export class TigrisVectorStore extends VectorStore {
|
|
|
72
73
|
if (!result) {
|
|
73
74
|
return [];
|
|
74
75
|
}
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
77
|
return result.map(([document, score]) => [
|
|
76
78
|
new Document({
|
|
77
79
|
pageContent: document.content,
|
|
@@ -72,11 +72,26 @@ class VectaraStore extends base_js_1.VectorStore {
|
|
|
72
72
|
throw new Error("Vectara api key is not provided.");
|
|
73
73
|
}
|
|
74
74
|
this.apiKey = apiKey;
|
|
75
|
-
const corpusId = args.corpusId ??
|
|
75
|
+
const corpusId = args.corpusId ??
|
|
76
|
+
(0, env_js_1.getEnvironmentVariable)("VECTARA_CORPUS_ID")
|
|
77
|
+
?.split(",")
|
|
78
|
+
.map((id) => {
|
|
79
|
+
const num = Number(id);
|
|
80
|
+
if (Number.isNaN(num))
|
|
81
|
+
throw new Error("Vectara corpus id is not a number.");
|
|
82
|
+
return num;
|
|
83
|
+
});
|
|
76
84
|
if (!corpusId) {
|
|
77
85
|
throw new Error("Vectara corpus id is not provided.");
|
|
78
86
|
}
|
|
79
|
-
|
|
87
|
+
if (typeof corpusId === "number") {
|
|
88
|
+
this.corpusId = [corpusId];
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (corpusId.length === 0)
|
|
92
|
+
throw new Error("Vectara corpus id is not provided.");
|
|
93
|
+
this.corpusId = corpusId;
|
|
94
|
+
}
|
|
80
95
|
const customerId = args.customerId ?? (0, env_js_1.getEnvironmentVariable)("VECTARA_CUSTOMER_ID");
|
|
81
96
|
if (!customerId) {
|
|
82
97
|
throw new Error("Vectara customer id is not provided.");
|
|
@@ -113,12 +128,14 @@ class VectaraStore extends base_js_1.VectorStore {
|
|
|
113
128
|
* @returns A Promise that resolves when the documents have been added.
|
|
114
129
|
*/
|
|
115
130
|
async addDocuments(documents) {
|
|
131
|
+
if (this.corpusId.length > 1)
|
|
132
|
+
throw new Error("addDocuments does not support multiple corpus ids");
|
|
116
133
|
const headers = await this.getJsonHeader();
|
|
117
134
|
let countAdded = 0;
|
|
118
135
|
for (const [index, document] of documents.entries()) {
|
|
119
136
|
const data = {
|
|
120
137
|
customer_id: this.customerId,
|
|
121
|
-
corpus_id: this.corpusId,
|
|
138
|
+
corpus_id: this.corpusId[0],
|
|
122
139
|
document: {
|
|
123
140
|
document_id: document.metadata?.document_id ?? `${Date.now()}${index}`,
|
|
124
141
|
title: document.metadata?.title ?? "",
|
|
@@ -173,6 +190,8 @@ class VectaraStore extends base_js_1.VectorStore {
|
|
|
173
190
|
* @returns A Promise that resolves to the number of successfully uploaded files.
|
|
174
191
|
*/
|
|
175
192
|
async addFiles(filePaths, metadatas = undefined) {
|
|
193
|
+
if (this.corpusId.length > 1)
|
|
194
|
+
throw new Error("addFiles does not support multiple corpus ids");
|
|
176
195
|
let numDocs = 0;
|
|
177
196
|
for (const [index, fileBlob] of filePaths.entries()) {
|
|
178
197
|
const md = metadatas ? metadatas[index] : {};
|
|
@@ -180,7 +199,7 @@ class VectaraStore extends base_js_1.VectorStore {
|
|
|
180
199
|
data.append("file", fileBlob, `file_${index}`);
|
|
181
200
|
data.append("doc-metadata", JSON.stringify(md));
|
|
182
201
|
try {
|
|
183
|
-
const response = await fetch(`https://api.vectara.io/v1/upload?c=${this.customerId}&o=${this.corpusId}`, {
|
|
202
|
+
const response = await fetch(`https://api.vectara.io/v1/upload?c=${this.customerId}&o=${this.corpusId[0]}`, {
|
|
184
203
|
method: "POST",
|
|
185
204
|
headers: {
|
|
186
205
|
"x-api-key": this.apiKey,
|
|
@@ -215,6 +234,12 @@ class VectaraStore extends base_js_1.VectorStore {
|
|
|
215
234
|
*/
|
|
216
235
|
async similaritySearchWithScore(query, k = 10, filter = undefined) {
|
|
217
236
|
const headers = await this.getJsonHeader();
|
|
237
|
+
const corpusKeys = this.corpusId.map((corpusId) => ({
|
|
238
|
+
customerId: this.customerId,
|
|
239
|
+
corpusId,
|
|
240
|
+
metadataFilter: filter?.filter ?? "",
|
|
241
|
+
lexicalInterpolationConfig: { lambda: filter?.lambda ?? 0.025 },
|
|
242
|
+
}));
|
|
218
243
|
const data = {
|
|
219
244
|
query: [
|
|
220
245
|
{
|
|
@@ -224,14 +249,7 @@ class VectaraStore extends base_js_1.VectorStore {
|
|
|
224
249
|
sentencesAfter: filter?.contextConfig?.sentencesAfter ?? 2,
|
|
225
250
|
sentencesBefore: filter?.contextConfig?.sentencesBefore ?? 2,
|
|
226
251
|
},
|
|
227
|
-
corpusKey:
|
|
228
|
-
{
|
|
229
|
-
customerId: this.customerId,
|
|
230
|
-
corpusId: this.corpusId,
|
|
231
|
-
metadataFilter: filter?.filter ?? "",
|
|
232
|
-
lexicalInterpolationConfig: { lambda: filter?.lambda ?? 0.025 },
|
|
233
|
-
},
|
|
234
|
-
],
|
|
252
|
+
corpusKey: corpusKeys,
|
|
235
253
|
},
|
|
236
254
|
],
|
|
237
255
|
};
|
|
@@ -69,11 +69,26 @@ export class VectaraStore extends VectorStore {
|
|
|
69
69
|
throw new Error("Vectara api key is not provided.");
|
|
70
70
|
}
|
|
71
71
|
this.apiKey = apiKey;
|
|
72
|
-
const corpusId = args.corpusId ??
|
|
72
|
+
const corpusId = args.corpusId ??
|
|
73
|
+
getEnvironmentVariable("VECTARA_CORPUS_ID")
|
|
74
|
+
?.split(",")
|
|
75
|
+
.map((id) => {
|
|
76
|
+
const num = Number(id);
|
|
77
|
+
if (Number.isNaN(num))
|
|
78
|
+
throw new Error("Vectara corpus id is not a number.");
|
|
79
|
+
return num;
|
|
80
|
+
});
|
|
73
81
|
if (!corpusId) {
|
|
74
82
|
throw new Error("Vectara corpus id is not provided.");
|
|
75
83
|
}
|
|
76
|
-
|
|
84
|
+
if (typeof corpusId === "number") {
|
|
85
|
+
this.corpusId = [corpusId];
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (corpusId.length === 0)
|
|
89
|
+
throw new Error("Vectara corpus id is not provided.");
|
|
90
|
+
this.corpusId = corpusId;
|
|
91
|
+
}
|
|
77
92
|
const customerId = args.customerId ?? getEnvironmentVariable("VECTARA_CUSTOMER_ID");
|
|
78
93
|
if (!customerId) {
|
|
79
94
|
throw new Error("Vectara customer id is not provided.");
|
|
@@ -110,12 +125,14 @@ export class VectaraStore extends VectorStore {
|
|
|
110
125
|
* @returns A Promise that resolves when the documents have been added.
|
|
111
126
|
*/
|
|
112
127
|
async addDocuments(documents) {
|
|
128
|
+
if (this.corpusId.length > 1)
|
|
129
|
+
throw new Error("addDocuments does not support multiple corpus ids");
|
|
113
130
|
const headers = await this.getJsonHeader();
|
|
114
131
|
let countAdded = 0;
|
|
115
132
|
for (const [index, document] of documents.entries()) {
|
|
116
133
|
const data = {
|
|
117
134
|
customer_id: this.customerId,
|
|
118
|
-
corpus_id: this.corpusId,
|
|
135
|
+
corpus_id: this.corpusId[0],
|
|
119
136
|
document: {
|
|
120
137
|
document_id: document.metadata?.document_id ?? `${Date.now()}${index}`,
|
|
121
138
|
title: document.metadata?.title ?? "",
|
|
@@ -170,6 +187,8 @@ export class VectaraStore extends VectorStore {
|
|
|
170
187
|
* @returns A Promise that resolves to the number of successfully uploaded files.
|
|
171
188
|
*/
|
|
172
189
|
async addFiles(filePaths, metadatas = undefined) {
|
|
190
|
+
if (this.corpusId.length > 1)
|
|
191
|
+
throw new Error("addFiles does not support multiple corpus ids");
|
|
173
192
|
let numDocs = 0;
|
|
174
193
|
for (const [index, fileBlob] of filePaths.entries()) {
|
|
175
194
|
const md = metadatas ? metadatas[index] : {};
|
|
@@ -177,7 +196,7 @@ export class VectaraStore extends VectorStore {
|
|
|
177
196
|
data.append("file", fileBlob, `file_${index}`);
|
|
178
197
|
data.append("doc-metadata", JSON.stringify(md));
|
|
179
198
|
try {
|
|
180
|
-
const response = await fetch(`https://api.vectara.io/v1/upload?c=${this.customerId}&o=${this.corpusId}`, {
|
|
199
|
+
const response = await fetch(`https://api.vectara.io/v1/upload?c=${this.customerId}&o=${this.corpusId[0]}`, {
|
|
181
200
|
method: "POST",
|
|
182
201
|
headers: {
|
|
183
202
|
"x-api-key": this.apiKey,
|
|
@@ -212,6 +231,12 @@ export class VectaraStore extends VectorStore {
|
|
|
212
231
|
*/
|
|
213
232
|
async similaritySearchWithScore(query, k = 10, filter = undefined) {
|
|
214
233
|
const headers = await this.getJsonHeader();
|
|
234
|
+
const corpusKeys = this.corpusId.map((corpusId) => ({
|
|
235
|
+
customerId: this.customerId,
|
|
236
|
+
corpusId,
|
|
237
|
+
metadataFilter: filter?.filter ?? "",
|
|
238
|
+
lexicalInterpolationConfig: { lambda: filter?.lambda ?? 0.025 },
|
|
239
|
+
}));
|
|
215
240
|
const data = {
|
|
216
241
|
query: [
|
|
217
242
|
{
|
|
@@ -221,14 +246,7 @@ export class VectaraStore extends VectorStore {
|
|
|
221
246
|
sentencesAfter: filter?.contextConfig?.sentencesAfter ?? 2,
|
|
222
247
|
sentencesBefore: filter?.contextConfig?.sentencesBefore ?? 2,
|
|
223
248
|
},
|
|
224
|
-
corpusKey:
|
|
225
|
-
{
|
|
226
|
-
customerId: this.customerId,
|
|
227
|
-
corpusId: this.corpusId,
|
|
228
|
-
metadataFilter: filter?.filter ?? "",
|
|
229
|
-
lexicalInterpolationConfig: { lambda: filter?.lambda ?? 0.025 },
|
|
230
|
-
},
|
|
231
|
-
],
|
|
249
|
+
corpusKey: corpusKeys,
|
|
232
250
|
},
|
|
233
251
|
],
|
|
234
252
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/document_loaders/fs/openai_whisper_audio.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/document_loaders/fs/openai_whisper_audio.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/document_loaders/fs/openai_whisper_audio.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/embeddings/hf_transformers.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/embeddings/hf_transformers.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/embeddings/hf_transformers.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/embeddings/ollama.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/embeddings/ollama.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/embeddings/ollama.js'
|