langchain 0.0.170 → 0.0.172
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/agents/format_scratchpad/log.cjs +1 -0
- package/agents/format_scratchpad/log.d.ts +1 -0
- package/agents/format_scratchpad/log.js +1 -0
- package/agents/format_scratchpad/log_to_message.cjs +1 -0
- package/agents/format_scratchpad/log_to_message.d.ts +1 -0
- package/agents/format_scratchpad/log_to_message.js +1 -0
- package/agents/format_scratchpad/xml.cjs +1 -0
- package/agents/format_scratchpad/xml.d.ts +1 -0
- package/agents/format_scratchpad/xml.js +1 -0
- package/agents/format_scratchpad.cjs +1 -1
- package/agents/format_scratchpad.d.ts +1 -1
- package/agents/format_scratchpad.js +1 -1
- package/agents/react/output_parser.cjs +1 -0
- package/agents/react/output_parser.d.ts +1 -0
- package/agents/react/output_parser.js +1 -0
- package/chat_models/llama_cpp.cjs +1 -0
- package/chat_models/llama_cpp.d.ts +1 -0
- package/chat_models/llama_cpp.js +1 -0
- package/dist/agents/format_scratchpad/log.cjs +16 -0
- package/dist/agents/format_scratchpad/log.d.ts +9 -0
- package/dist/agents/format_scratchpad/log.js +12 -0
- package/dist/agents/format_scratchpad/log_to_message.cjs +22 -0
- package/dist/agents/format_scratchpad/log_to_message.d.ts +2 -0
- package/dist/agents/format_scratchpad/log_to_message.js +18 -0
- package/dist/agents/{format_scratchpad.cjs → format_scratchpad/openai_functions.cjs} +3 -3
- package/dist/agents/{format_scratchpad.d.ts → format_scratchpad/openai_functions.d.ts} +1 -1
- package/dist/agents/{format_scratchpad.js → format_scratchpad/openai_functions.js} +3 -3
- package/dist/agents/format_scratchpad/xml.cjs +12 -0
- package/dist/agents/format_scratchpad/xml.d.ts +2 -0
- package/dist/agents/format_scratchpad/xml.js +8 -0
- package/dist/agents/react/output_parser.cjs +96 -0
- package/dist/agents/react/output_parser.d.ts +47 -0
- package/dist/agents/react/output_parser.js +92 -0
- package/dist/agents/react/prompt.cjs +13 -0
- package/dist/agents/react/prompt.d.ts +1 -0
- package/dist/agents/react/prompt.js +10 -0
- package/dist/agents/toolkits/openapi/openapi.cjs +1 -1
- package/dist/agents/toolkits/openapi/openapi.d.ts +1 -1
- package/dist/agents/toolkits/openapi/openapi.js +1 -1
- package/dist/chains/sql_db/sql_db_chain.cjs +2 -0
- package/dist/chains/sql_db/sql_db_chain.d.ts +2 -0
- package/dist/chains/sql_db/sql_db_chain.js +2 -0
- package/dist/chat_models/llama_cpp.cjs +243 -0
- package/dist/chat_models/llama_cpp.d.ts +94 -0
- package/dist/chat_models/llama_cpp.js +239 -0
- package/dist/document_loaders/web/pdf.cjs +23 -5
- package/dist/document_loaders/web/pdf.d.ts +9 -1
- package/dist/document_loaders/web/pdf.js +20 -2
- package/dist/embeddings/openai.cjs +11 -0
- package/dist/embeddings/openai.d.ts +2 -0
- package/dist/embeddings/openai.js +11 -0
- package/dist/graphs/neo4j_graph.cjs +14 -0
- package/dist/graphs/neo4j_graph.d.ts +14 -0
- package/dist/graphs/neo4j_graph.js +14 -0
- package/dist/llms/googlepalm.cjs +3 -0
- package/dist/llms/googlepalm.js +3 -0
- package/dist/load/import_constants.cjs +2 -0
- package/dist/load/import_constants.js +2 -0
- package/dist/load/import_map.cjs +8 -3
- package/dist/load/import_map.d.ts +6 -1
- package/dist/load/import_map.js +6 -1
- package/dist/retrievers/parent_document.cjs +22 -2
- package/dist/retrievers/parent_document.d.ts +8 -1
- package/dist/retrievers/parent_document.js +22 -2
- package/dist/schema/runnable/passthrough.cjs +3 -1
- package/dist/schema/runnable/passthrough.js +3 -1
- package/dist/sql_db.cjs +2 -0
- package/dist/sql_db.d.ts +2 -0
- package/dist/sql_db.js +2 -0
- package/dist/storage/file_system.cjs +147 -0
- package/dist/storage/file_system.d.ts +60 -0
- package/dist/storage/file_system.js +140 -0
- package/dist/tools/render.cjs +18 -0
- package/dist/tools/render.d.ts +13 -0
- package/dist/tools/render.js +14 -0
- package/dist/util/stream.cjs +3 -0
- package/dist/util/stream.js +3 -0
- package/dist/vectorstores/analyticdb.cjs +7 -3
- package/dist/vectorstores/analyticdb.d.ts +1 -1
- package/dist/vectorstores/analyticdb.js +7 -3
- package/dist/vectorstores/cassandra.cjs +25 -4
- package/dist/vectorstores/cassandra.d.ts +11 -1
- package/dist/vectorstores/cassandra.js +25 -4
- package/dist/vectorstores/momento_vector_index.cjs +3 -15
- package/dist/vectorstores/momento_vector_index.d.ts +0 -8
- package/dist/vectorstores/momento_vector_index.js +3 -15
- package/dist/vectorstores/neo4j_vector.cjs +14 -0
- package/dist/vectorstores/neo4j_vector.d.ts +14 -0
- package/dist/vectorstores/neo4j_vector.js +14 -0
- package/dist/vectorstores/qdrant.cjs +19 -11
- package/dist/vectorstores/qdrant.d.ts +1 -1
- package/dist/vectorstores/qdrant.js +19 -11
- package/dist/vectorstores/redis.cjs +4 -1
- package/dist/vectorstores/redis.d.ts +1 -1
- package/dist/vectorstores/redis.js +4 -1
- package/package.json +63 -7
- package/storage/file_system.cjs +1 -0
- package/storage/file_system.d.ts +1 -0
- package/storage/file_system.js +1 -0
- package/tools/render.cjs +1 -0
- package/tools/render.d.ts +1 -0
- package/tools/render.js +1 -0
|
@@ -50,6 +50,12 @@ export class CassandraStore extends VectorStore {
|
|
|
50
50
|
writable: true,
|
|
51
51
|
value: void 0
|
|
52
52
|
});
|
|
53
|
+
Object.defineProperty(this, "indices", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
|
53
59
|
Object.defineProperty(this, "isInitialized", {
|
|
54
60
|
enumerable: true,
|
|
55
61
|
configurable: true,
|
|
@@ -62,6 +68,7 @@ export class CassandraStore extends VectorStore {
|
|
|
62
68
|
this.table = args.table;
|
|
63
69
|
this.primaryKey = args.primaryKey;
|
|
64
70
|
this.metadataColumns = args.metadataColumns;
|
|
71
|
+
this.indices = args.indices;
|
|
65
72
|
}
|
|
66
73
|
/**
|
|
67
74
|
* Method to save vectors to the Cassandra database.
|
|
@@ -91,13 +98,14 @@ export class CassandraStore extends VectorStore {
|
|
|
91
98
|
* Method to search for vectors that are similar to a given query vector.
|
|
92
99
|
* @param query The query vector.
|
|
93
100
|
* @param k The number of similar vectors to return.
|
|
101
|
+
* @param filter
|
|
94
102
|
* @returns Promise that resolves with an array of tuples, each containing a Document and a score.
|
|
95
103
|
*/
|
|
96
|
-
async similaritySearchVectorWithScore(query, k) {
|
|
104
|
+
async similaritySearchVectorWithScore(query, k, filter) {
|
|
97
105
|
if (!this.isInitialized) {
|
|
98
106
|
await this.initialize();
|
|
99
107
|
}
|
|
100
|
-
const queryStr = this.buildSearchQuery(query, k);
|
|
108
|
+
const queryStr = this.buildSearchQuery(query, k, filter);
|
|
101
109
|
const queryResultSet = await this.client.execute(queryStr);
|
|
102
110
|
return queryResultSet?.rows.map((row, index) => {
|
|
103
111
|
const textContent = row.text;
|
|
@@ -170,6 +178,11 @@ export class CassandraStore extends VectorStore {
|
|
|
170
178
|
await this.client
|
|
171
179
|
.execute(`CREATE CUSTOM INDEX IF NOT EXISTS idx_vector_${this.table}
|
|
172
180
|
ON ${this.keyspace}.${this.table}(vector) USING 'StorageAttachedIndex';`);
|
|
181
|
+
for await (const { name, value } of this.indices) {
|
|
182
|
+
await this.client
|
|
183
|
+
.execute(`CREATE CUSTOM INDEX IF NOT EXISTS idx_${this.table}_${name}
|
|
184
|
+
ON ${this.keyspace}.${this.table} ${value} USING 'StorageAttachedIndex';`);
|
|
185
|
+
}
|
|
173
186
|
this.isInitialized = true;
|
|
174
187
|
}
|
|
175
188
|
/**
|
|
@@ -197,14 +210,22 @@ export class CassandraStore extends VectorStore {
|
|
|
197
210
|
}
|
|
198
211
|
return queries;
|
|
199
212
|
}
|
|
213
|
+
buildWhereClause(filter) {
|
|
214
|
+
const whereClause = Object.entries(filter)
|
|
215
|
+
.map(([key, value]) => `${key} = '${value}'`)
|
|
216
|
+
.join(" AND ");
|
|
217
|
+
return `WHERE ${whereClause}`;
|
|
218
|
+
}
|
|
200
219
|
/**
|
|
201
220
|
* Method to build an CQL query for searching for similar vectors in the
|
|
202
221
|
* Cassandra database.
|
|
203
222
|
* @param query The query vector.
|
|
204
223
|
* @param k The number of similar vectors to return.
|
|
224
|
+
* @param filter
|
|
205
225
|
* @returns The CQL query string.
|
|
206
226
|
*/
|
|
207
|
-
buildSearchQuery(query, k) {
|
|
208
|
-
|
|
227
|
+
buildSearchQuery(query, k = 1, filter = undefined) {
|
|
228
|
+
const whereClause = filter ? this.buildWhereClause(filter) : "";
|
|
229
|
+
return `SELECT * FROM ${this.keyspace}.${this.table} ${whereClause} ORDER BY vector ANN OF [${query}] LIMIT ${k}`;
|
|
209
230
|
}
|
|
210
231
|
}
|
|
@@ -104,16 +104,6 @@ class MomentoVectorIndex extends base_js_1.VectorStore {
|
|
|
104
104
|
throw new Error(`Unknown response type: ${response.toString()}`);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Converts the metadata to a format that can be stored in the index.
|
|
109
|
-
*
|
|
110
|
-
* @remarks stringifies all values in the metadata object
|
|
111
|
-
* @param metadata The metadata to convert.
|
|
112
|
-
* @returns The converted metadata.
|
|
113
|
-
*/
|
|
114
|
-
static prepareMetadata(metadata) {
|
|
115
|
-
return Object.fromEntries(Object.entries(metadata).map(([key, val]) => [key, JSON.stringify(val)]));
|
|
116
|
-
}
|
|
117
107
|
/**
|
|
118
108
|
* Converts the documents to a format that can be stored in the index.
|
|
119
109
|
*
|
|
@@ -129,7 +119,7 @@ class MomentoVectorIndex extends base_js_1.VectorStore {
|
|
|
129
119
|
id: ids[idx],
|
|
130
120
|
vector,
|
|
131
121
|
metadata: {
|
|
132
|
-
...
|
|
122
|
+
...documents[idx].metadata,
|
|
133
123
|
[this.textField]: documents[idx].pageContent,
|
|
134
124
|
},
|
|
135
125
|
}));
|
|
@@ -231,10 +221,8 @@ class MomentoVectorIndex extends base_js_1.VectorStore {
|
|
|
231
221
|
}
|
|
232
222
|
return response.hits().map((hit) => [
|
|
233
223
|
new document_js_1.Document({
|
|
234
|
-
pageContent: hit.metadata[this.textField] ?? "",
|
|
235
|
-
metadata: Object.fromEntries(Object.entries(hit.metadata)
|
|
236
|
-
.filter(([key]) => key !== this.textField)
|
|
237
|
-
.map(([key, val]) => [key, JSON.parse(val)])),
|
|
224
|
+
pageContent: hit.metadata[this.textField]?.toString() ?? "",
|
|
225
|
+
metadata: Object.fromEntries(Object.entries(hit.metadata).filter(([key]) => key !== this.textField)),
|
|
238
226
|
}),
|
|
239
227
|
hit.distance,
|
|
240
228
|
]);
|
|
@@ -61,14 +61,6 @@ export declare class MomentoVectorIndex extends VectorStore {
|
|
|
61
61
|
* @returns Promise that resolves to true if the index was created, false if it already existed.
|
|
62
62
|
*/
|
|
63
63
|
private ensureIndexExists;
|
|
64
|
-
/**
|
|
65
|
-
* Converts the metadata to a format that can be stored in the index.
|
|
66
|
-
*
|
|
67
|
-
* @remarks stringifies all values in the metadata object
|
|
68
|
-
* @param metadata The metadata to convert.
|
|
69
|
-
* @returns The converted metadata.
|
|
70
|
-
*/
|
|
71
|
-
private static prepareMetadata;
|
|
72
64
|
/**
|
|
73
65
|
* Converts the documents to a format that can be stored in the index.
|
|
74
66
|
*
|
|
@@ -78,16 +78,6 @@ export class MomentoVectorIndex extends VectorStore {
|
|
|
78
78
|
throw new Error(`Unknown response type: ${response.toString()}`);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Converts the metadata to a format that can be stored in the index.
|
|
83
|
-
*
|
|
84
|
-
* @remarks stringifies all values in the metadata object
|
|
85
|
-
* @param metadata The metadata to convert.
|
|
86
|
-
* @returns The converted metadata.
|
|
87
|
-
*/
|
|
88
|
-
static prepareMetadata(metadata) {
|
|
89
|
-
return Object.fromEntries(Object.entries(metadata).map(([key, val]) => [key, JSON.stringify(val)]));
|
|
90
|
-
}
|
|
91
81
|
/**
|
|
92
82
|
* Converts the documents to a format that can be stored in the index.
|
|
93
83
|
*
|
|
@@ -103,7 +93,7 @@ export class MomentoVectorIndex extends VectorStore {
|
|
|
103
93
|
id: ids[idx],
|
|
104
94
|
vector,
|
|
105
95
|
metadata: {
|
|
106
|
-
...
|
|
96
|
+
...documents[idx].metadata,
|
|
107
97
|
[this.textField]: documents[idx].pageContent,
|
|
108
98
|
},
|
|
109
99
|
}));
|
|
@@ -205,10 +195,8 @@ export class MomentoVectorIndex extends VectorStore {
|
|
|
205
195
|
}
|
|
206
196
|
return response.hits().map((hit) => [
|
|
207
197
|
new Document({
|
|
208
|
-
pageContent: hit.metadata[this.textField] ?? "",
|
|
209
|
-
metadata: Object.fromEntries(Object.entries(hit.metadata)
|
|
210
|
-
.filter(([key]) => key !== this.textField)
|
|
211
|
-
.map(([key, val]) => [key, JSON.parse(val)])),
|
|
198
|
+
pageContent: hit.metadata[this.textField]?.toString() ?? "",
|
|
199
|
+
metadata: Object.fromEntries(Object.entries(hit.metadata).filter(([key]) => key !== this.textField)),
|
|
212
200
|
}),
|
|
213
201
|
hit.distance,
|
|
214
202
|
]);
|
|
@@ -33,6 +33,20 @@ const document_js_1 = require("../document.cjs");
|
|
|
33
33
|
const base_js_1 = require("./base.cjs");
|
|
34
34
|
const DEFAULT_SEARCH_TYPE = "vector";
|
|
35
35
|
const DEFAULT_DISTANCE_STRATEGY = "cosine";
|
|
36
|
+
/**
|
|
37
|
+
* @security *Security note*: Make sure that the database connection uses credentials
|
|
38
|
+
* that are narrowly-scoped to only include necessary permissions.
|
|
39
|
+
* Failure to do so may result in data corruption or loss, since the calling
|
|
40
|
+
* code may attempt commands that would result in deletion, mutation
|
|
41
|
+
* of data if appropriately prompted or reading sensitive data if such
|
|
42
|
+
* data is present in the database.
|
|
43
|
+
* The best way to guard against such negative outcomes is to (as appropriate)
|
|
44
|
+
* limit the permissions granted to the credentials used with this tool.
|
|
45
|
+
* For example, creating read only users for the database is a good way to
|
|
46
|
+
* ensure that the calling code cannot mutate or delete data.
|
|
47
|
+
*
|
|
48
|
+
* @link See https://js.langchain.com/docs/security for more information.
|
|
49
|
+
*/
|
|
36
50
|
class Neo4jVectorStore extends base_js_1.VectorStore {
|
|
37
51
|
_vectorstoreType() {
|
|
38
52
|
return "neo4jvector";
|
|
@@ -19,6 +19,20 @@ interface Neo4jVectorStoreArgs {
|
|
|
19
19
|
nodeLabel?: string;
|
|
20
20
|
createIdIndex?: boolean;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* @security *Security note*: Make sure that the database connection uses credentials
|
|
24
|
+
* that are narrowly-scoped to only include necessary permissions.
|
|
25
|
+
* Failure to do so may result in data corruption or loss, since the calling
|
|
26
|
+
* code may attempt commands that would result in deletion, mutation
|
|
27
|
+
* of data if appropriately prompted or reading sensitive data if such
|
|
28
|
+
* data is present in the database.
|
|
29
|
+
* The best way to guard against such negative outcomes is to (as appropriate)
|
|
30
|
+
* limit the permissions granted to the credentials used with this tool.
|
|
31
|
+
* For example, creating read only users for the database is a good way to
|
|
32
|
+
* ensure that the calling code cannot mutate or delete data.
|
|
33
|
+
*
|
|
34
|
+
* @link See https://js.langchain.com/docs/security for more information.
|
|
35
|
+
*/
|
|
22
36
|
export declare class Neo4jVectorStore extends VectorStore {
|
|
23
37
|
private driver;
|
|
24
38
|
private database;
|
|
@@ -4,6 +4,20 @@ import { Document } from "../document.js";
|
|
|
4
4
|
import { VectorStore } from "./base.js";
|
|
5
5
|
const DEFAULT_SEARCH_TYPE = "vector";
|
|
6
6
|
const DEFAULT_DISTANCE_STRATEGY = "cosine";
|
|
7
|
+
/**
|
|
8
|
+
* @security *Security note*: Make sure that the database connection uses credentials
|
|
9
|
+
* that are narrowly-scoped to only include necessary permissions.
|
|
10
|
+
* Failure to do so may result in data corruption or loss, since the calling
|
|
11
|
+
* code may attempt commands that would result in deletion, mutation
|
|
12
|
+
* of data if appropriately prompted or reading sensitive data if such
|
|
13
|
+
* data is present in the database.
|
|
14
|
+
* The best way to guard against such negative outcomes is to (as appropriate)
|
|
15
|
+
* limit the permissions granted to the credentials used with this tool.
|
|
16
|
+
* For example, creating read only users for the database is a good way to
|
|
17
|
+
* ensure that the calling code cannot mutate or delete data.
|
|
18
|
+
*
|
|
19
|
+
* @link See https://js.langchain.com/docs/security for more information.
|
|
20
|
+
*/
|
|
7
21
|
export class Neo4jVectorStore extends VectorStore {
|
|
8
22
|
_vectorstoreType() {
|
|
9
23
|
return "neo4jvector";
|
|
@@ -54,12 +54,7 @@ class QdrantVectorStore extends base_js_1.VectorStore {
|
|
|
54
54
|
apiKey,
|
|
55
55
|
});
|
|
56
56
|
this.collectionName = args.collectionName ?? "documents";
|
|
57
|
-
this.collectionConfig = args.collectionConfig
|
|
58
|
-
vectors: {
|
|
59
|
-
size: 1536,
|
|
60
|
-
distance: "Cosine",
|
|
61
|
-
},
|
|
62
|
-
};
|
|
57
|
+
this.collectionConfig = args.collectionConfig;
|
|
63
58
|
}
|
|
64
59
|
/**
|
|
65
60
|
* Method to add documents to the Qdrant database. It generates vectors
|
|
@@ -93,10 +88,17 @@ class QdrantVectorStore extends base_js_1.VectorStore {
|
|
|
93
88
|
metadata: documents[idx].metadata,
|
|
94
89
|
},
|
|
95
90
|
}));
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
try {
|
|
92
|
+
await this.client.upsert(this.collectionName, {
|
|
93
|
+
wait: true,
|
|
94
|
+
points,
|
|
95
|
+
});
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
const error = new Error(`${e?.status ?? "Undefined error code"} ${e?.message}: ${e?.data?.status?.error}`);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
100
102
|
}
|
|
101
103
|
/**
|
|
102
104
|
* Method to search for vectors in the Qdrant database that are similar to
|
|
@@ -135,7 +137,13 @@ class QdrantVectorStore extends base_js_1.VectorStore {
|
|
|
135
137
|
const response = await this.client.getCollections();
|
|
136
138
|
const collectionNames = response.collections.map((collection) => collection.name);
|
|
137
139
|
if (!collectionNames.includes(this.collectionName)) {
|
|
138
|
-
|
|
140
|
+
const collectionConfig = this.collectionConfig ?? {
|
|
141
|
+
vectors: {
|
|
142
|
+
size: (await this.embeddings.embedQuery("test")).length,
|
|
143
|
+
distance: "Cosine",
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
await this.client.createCollection(this.collectionName, collectionConfig);
|
|
139
147
|
}
|
|
140
148
|
}
|
|
141
149
|
/**
|
|
@@ -28,7 +28,7 @@ export declare class QdrantVectorStore extends VectorStore {
|
|
|
28
28
|
};
|
|
29
29
|
client: QdrantClient;
|
|
30
30
|
collectionName: string;
|
|
31
|
-
collectionConfig
|
|
31
|
+
collectionConfig?: QdrantSchemas["CreateCollection"];
|
|
32
32
|
_vectorstoreType(): string;
|
|
33
33
|
constructor(embeddings: Embeddings, args: QdrantLibArgs);
|
|
34
34
|
/**
|
|
@@ -51,12 +51,7 @@ export class QdrantVectorStore extends VectorStore {
|
|
|
51
51
|
apiKey,
|
|
52
52
|
});
|
|
53
53
|
this.collectionName = args.collectionName ?? "documents";
|
|
54
|
-
this.collectionConfig = args.collectionConfig
|
|
55
|
-
vectors: {
|
|
56
|
-
size: 1536,
|
|
57
|
-
distance: "Cosine",
|
|
58
|
-
},
|
|
59
|
-
};
|
|
54
|
+
this.collectionConfig = args.collectionConfig;
|
|
60
55
|
}
|
|
61
56
|
/**
|
|
62
57
|
* Method to add documents to the Qdrant database. It generates vectors
|
|
@@ -90,10 +85,17 @@ export class QdrantVectorStore extends VectorStore {
|
|
|
90
85
|
metadata: documents[idx].metadata,
|
|
91
86
|
},
|
|
92
87
|
}));
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
try {
|
|
89
|
+
await this.client.upsert(this.collectionName, {
|
|
90
|
+
wait: true,
|
|
91
|
+
points,
|
|
92
|
+
});
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
const error = new Error(`${e?.status ?? "Undefined error code"} ${e?.message}: ${e?.data?.status?.error}`);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
97
99
|
}
|
|
98
100
|
/**
|
|
99
101
|
* Method to search for vectors in the Qdrant database that are similar to
|
|
@@ -132,7 +134,13 @@ export class QdrantVectorStore extends VectorStore {
|
|
|
132
134
|
const response = await this.client.getCollections();
|
|
133
135
|
const collectionNames = response.collections.map((collection) => collection.name);
|
|
134
136
|
if (!collectionNames.includes(this.collectionName)) {
|
|
135
|
-
|
|
137
|
+
const collectionConfig = this.collectionConfig ?? {
|
|
138
|
+
vectors: {
|
|
139
|
+
size: (await this.embeddings.embedQuery("test")).length,
|
|
140
|
+
distance: "Cosine",
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
await this.client.createCollection(this.collectionName, collectionConfig);
|
|
136
144
|
}
|
|
137
145
|
}
|
|
138
146
|
/**
|
|
@@ -108,6 +108,9 @@ class RedisVectorStore extends base_js_1.VectorStore {
|
|
|
108
108
|
* @returns A promise that resolves when the vectors have been added.
|
|
109
109
|
*/
|
|
110
110
|
async addVectors(vectors, documents, { keys, batchSize = 1000 } = {}) {
|
|
111
|
+
if (!vectors.length || !vectors[0].length) {
|
|
112
|
+
throw new Error("No vectors provided");
|
|
113
|
+
}
|
|
111
114
|
// check if the index exists and create it if it doesn't
|
|
112
115
|
await this.createIndex(vectors[0].length);
|
|
113
116
|
const info = await this.redisClient.ft.info(this.indexName);
|
|
@@ -222,7 +225,7 @@ class RedisVectorStore extends base_js_1.VectorStore {
|
|
|
222
225
|
/**
|
|
223
226
|
* Method for creating an index in the RedisVectorStore. If the index
|
|
224
227
|
* already exists, it does nothing.
|
|
225
|
-
* @param dimensions The dimensions of the index
|
|
228
|
+
* @param dimensions The dimensions of the index
|
|
226
229
|
* @returns A promise that resolves when the index has been created.
|
|
227
230
|
*/
|
|
228
231
|
async createIndex(dimensions = 1536) {
|
|
@@ -137,7 +137,7 @@ export declare class RedisVectorStore extends VectorStore {
|
|
|
137
137
|
/**
|
|
138
138
|
* Method for creating an index in the RedisVectorStore. If the index
|
|
139
139
|
* already exists, it does nothing.
|
|
140
|
-
* @param dimensions The dimensions of the index
|
|
140
|
+
* @param dimensions The dimensions of the index
|
|
141
141
|
* @returns A promise that resolves when the index has been created.
|
|
142
142
|
*/
|
|
143
143
|
createIndex(dimensions?: number): Promise<void>;
|
|
@@ -105,6 +105,9 @@ export class RedisVectorStore extends VectorStore {
|
|
|
105
105
|
* @returns A promise that resolves when the vectors have been added.
|
|
106
106
|
*/
|
|
107
107
|
async addVectors(vectors, documents, { keys, batchSize = 1000 } = {}) {
|
|
108
|
+
if (!vectors.length || !vectors[0].length) {
|
|
109
|
+
throw new Error("No vectors provided");
|
|
110
|
+
}
|
|
108
111
|
// check if the index exists and create it if it doesn't
|
|
109
112
|
await this.createIndex(vectors[0].length);
|
|
110
113
|
const info = await this.redisClient.ft.info(this.indexName);
|
|
@@ -219,7 +222,7 @@ export class RedisVectorStore extends VectorStore {
|
|
|
219
222
|
/**
|
|
220
223
|
* Method for creating an index in the RedisVectorStore. If the index
|
|
221
224
|
* already exists, it does nothing.
|
|
222
|
-
* @param dimensions The dimensions of the index
|
|
225
|
+
* @param dimensions The dimensions of the index
|
|
223
226
|
* @returns A promise that resolves when the index has been created.
|
|
224
227
|
*/
|
|
225
228
|
async createIndex(dimensions = 1536) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.172",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -34,6 +34,18 @@
|
|
|
34
34
|
"agents/format_scratchpad.cjs",
|
|
35
35
|
"agents/format_scratchpad.js",
|
|
36
36
|
"agents/format_scratchpad.d.ts",
|
|
37
|
+
"agents/format_scratchpad/log.cjs",
|
|
38
|
+
"agents/format_scratchpad/log.js",
|
|
39
|
+
"agents/format_scratchpad/log.d.ts",
|
|
40
|
+
"agents/format_scratchpad/xml.cjs",
|
|
41
|
+
"agents/format_scratchpad/xml.js",
|
|
42
|
+
"agents/format_scratchpad/xml.d.ts",
|
|
43
|
+
"agents/format_scratchpad/log_to_message.cjs",
|
|
44
|
+
"agents/format_scratchpad/log_to_message.js",
|
|
45
|
+
"agents/format_scratchpad/log_to_message.d.ts",
|
|
46
|
+
"agents/react/output_parser.cjs",
|
|
47
|
+
"agents/react/output_parser.js",
|
|
48
|
+
"agents/react/output_parser.d.ts",
|
|
37
49
|
"base_language.cjs",
|
|
38
50
|
"base_language.js",
|
|
39
51
|
"base_language.d.ts",
|
|
@@ -49,6 +61,9 @@
|
|
|
49
61
|
"tools/calculator.cjs",
|
|
50
62
|
"tools/calculator.js",
|
|
51
63
|
"tools/calculator.d.ts",
|
|
64
|
+
"tools/render.cjs",
|
|
65
|
+
"tools/render.js",
|
|
66
|
+
"tools/render.d.ts",
|
|
52
67
|
"tools/sql.cjs",
|
|
53
68
|
"tools/sql.js",
|
|
54
69
|
"tools/sql.d.ts",
|
|
@@ -475,6 +490,9 @@
|
|
|
475
490
|
"chat_models/minimax.cjs",
|
|
476
491
|
"chat_models/minimax.js",
|
|
477
492
|
"chat_models/minimax.d.ts",
|
|
493
|
+
"chat_models/llama_cpp.cjs",
|
|
494
|
+
"chat_models/llama_cpp.js",
|
|
495
|
+
"chat_models/llama_cpp.d.ts",
|
|
478
496
|
"chat_models/yandex.cjs",
|
|
479
497
|
"chat_models/yandex.js",
|
|
480
498
|
"chat_models/yandex.d.ts",
|
|
@@ -670,6 +688,9 @@
|
|
|
670
688
|
"storage/upstash_redis.cjs",
|
|
671
689
|
"storage/upstash_redis.js",
|
|
672
690
|
"storage/upstash_redis.d.ts",
|
|
691
|
+
"storage/file_system.cjs",
|
|
692
|
+
"storage/file_system.js",
|
|
693
|
+
"storage/file_system.d.ts",
|
|
673
694
|
"graphs/neo4j_graph.cjs",
|
|
674
695
|
"graphs/neo4j_graph.js",
|
|
675
696
|
"graphs/neo4j_graph.d.ts",
|
|
@@ -765,8 +786,8 @@
|
|
|
765
786
|
"@faker-js/faker": "^7.6.0",
|
|
766
787
|
"@getmetal/metal-sdk": "^4.0.0",
|
|
767
788
|
"@getzep/zep-js": "^0.8.0",
|
|
768
|
-
"@gomomento/sdk": "^1.
|
|
769
|
-
"@gomomento/sdk-core": "^1.
|
|
789
|
+
"@gomomento/sdk": "^1.44.1",
|
|
790
|
+
"@gomomento/sdk-core": "^1.44.1",
|
|
770
791
|
"@google-ai/generativelanguage": "^0.2.1",
|
|
771
792
|
"@google-cloud/storage": "^6.10.1",
|
|
772
793
|
"@huggingface/inference": "^1.5.1",
|
|
@@ -853,7 +874,7 @@
|
|
|
853
874
|
"mongodb": "^5.2.0",
|
|
854
875
|
"mysql2": "^3.3.3",
|
|
855
876
|
"neo4j-driver": "^5.12.0",
|
|
856
|
-
"node-llama-cpp": "
|
|
877
|
+
"node-llama-cpp": "2.7.3",
|
|
857
878
|
"notion-to-md": "^3.1.0",
|
|
858
879
|
"pdf-parse": "1.1.1",
|
|
859
880
|
"peggy": "^3.0.2",
|
|
@@ -900,9 +921,9 @@
|
|
|
900
921
|
"@elastic/elasticsearch": "^8.4.0",
|
|
901
922
|
"@getmetal/metal-sdk": "*",
|
|
902
923
|
"@getzep/zep-js": "^0.8.0",
|
|
903
|
-
"@gomomento/sdk": "^1.
|
|
904
|
-
"@gomomento/sdk-core": "^1.
|
|
905
|
-
"@gomomento/sdk-web": "^1.
|
|
924
|
+
"@gomomento/sdk": "^1.44.1",
|
|
925
|
+
"@gomomento/sdk-core": "^1.44.1",
|
|
926
|
+
"@gomomento/sdk-web": "^1.44.1",
|
|
906
927
|
"@google-ai/generativelanguage": "^0.2.1",
|
|
907
928
|
"@google-cloud/storage": "^6.10.1",
|
|
908
929
|
"@huggingface/inference": "^1.5.1",
|
|
@@ -1350,6 +1371,26 @@
|
|
|
1350
1371
|
"import": "./agents/format_scratchpad.js",
|
|
1351
1372
|
"require": "./agents/format_scratchpad.cjs"
|
|
1352
1373
|
},
|
|
1374
|
+
"./agents/format_scratchpad/log": {
|
|
1375
|
+
"types": "./agents/format_scratchpad/log.d.ts",
|
|
1376
|
+
"import": "./agents/format_scratchpad/log.js",
|
|
1377
|
+
"require": "./agents/format_scratchpad/log.cjs"
|
|
1378
|
+
},
|
|
1379
|
+
"./agents/format_scratchpad/xml": {
|
|
1380
|
+
"types": "./agents/format_scratchpad/xml.d.ts",
|
|
1381
|
+
"import": "./agents/format_scratchpad/xml.js",
|
|
1382
|
+
"require": "./agents/format_scratchpad/xml.cjs"
|
|
1383
|
+
},
|
|
1384
|
+
"./agents/format_scratchpad/log_to_message": {
|
|
1385
|
+
"types": "./agents/format_scratchpad/log_to_message.d.ts",
|
|
1386
|
+
"import": "./agents/format_scratchpad/log_to_message.js",
|
|
1387
|
+
"require": "./agents/format_scratchpad/log_to_message.cjs"
|
|
1388
|
+
},
|
|
1389
|
+
"./agents/react/output_parser": {
|
|
1390
|
+
"types": "./agents/react/output_parser.d.ts",
|
|
1391
|
+
"import": "./agents/react/output_parser.js",
|
|
1392
|
+
"require": "./agents/react/output_parser.cjs"
|
|
1393
|
+
},
|
|
1353
1394
|
"./base_language": {
|
|
1354
1395
|
"types": "./base_language.d.ts",
|
|
1355
1396
|
"import": "./base_language.js",
|
|
@@ -1375,6 +1416,11 @@
|
|
|
1375
1416
|
"import": "./tools/calculator.js",
|
|
1376
1417
|
"require": "./tools/calculator.cjs"
|
|
1377
1418
|
},
|
|
1419
|
+
"./tools/render": {
|
|
1420
|
+
"types": "./tools/render.d.ts",
|
|
1421
|
+
"import": "./tools/render.js",
|
|
1422
|
+
"require": "./tools/render.cjs"
|
|
1423
|
+
},
|
|
1378
1424
|
"./tools/sql": {
|
|
1379
1425
|
"types": "./tools/sql.d.ts",
|
|
1380
1426
|
"import": "./tools/sql.js",
|
|
@@ -2085,6 +2131,11 @@
|
|
|
2085
2131
|
"import": "./chat_models/minimax.js",
|
|
2086
2132
|
"require": "./chat_models/minimax.cjs"
|
|
2087
2133
|
},
|
|
2134
|
+
"./chat_models/llama_cpp": {
|
|
2135
|
+
"types": "./chat_models/llama_cpp.d.ts",
|
|
2136
|
+
"import": "./chat_models/llama_cpp.js",
|
|
2137
|
+
"require": "./chat_models/llama_cpp.cjs"
|
|
2138
|
+
},
|
|
2088
2139
|
"./chat_models/yandex": {
|
|
2089
2140
|
"types": "./chat_models/yandex.d.ts",
|
|
2090
2141
|
"import": "./chat_models/yandex.js",
|
|
@@ -2410,6 +2461,11 @@
|
|
|
2410
2461
|
"import": "./storage/upstash_redis.js",
|
|
2411
2462
|
"require": "./storage/upstash_redis.cjs"
|
|
2412
2463
|
},
|
|
2464
|
+
"./storage/file_system": {
|
|
2465
|
+
"types": "./storage/file_system.d.ts",
|
|
2466
|
+
"import": "./storage/file_system.js",
|
|
2467
|
+
"require": "./storage/file_system.cjs"
|
|
2468
|
+
},
|
|
2413
2469
|
"./graphs/neo4j_graph": {
|
|
2414
2470
|
"types": "./graphs/neo4j_graph.d.ts",
|
|
2415
2471
|
"import": "./graphs/neo4j_graph.js",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/storage/file_system.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/storage/file_system.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/storage/file_system.js'
|
package/tools/render.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/tools/render.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/tools/render.js'
|
package/tools/render.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/tools/render.js'
|