langchain 0.0.170 → 0.0.171

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.
Files changed (42) hide show
  1. package/chat_models/llama_cpp.cjs +1 -0
  2. package/chat_models/llama_cpp.d.ts +1 -0
  3. package/chat_models/llama_cpp.js +1 -0
  4. package/dist/agents/toolkits/openapi/openapi.cjs +1 -1
  5. package/dist/agents/toolkits/openapi/openapi.d.ts +1 -1
  6. package/dist/agents/toolkits/openapi/openapi.js +1 -1
  7. package/dist/chains/sql_db/sql_db_chain.cjs +2 -0
  8. package/dist/chains/sql_db/sql_db_chain.d.ts +2 -0
  9. package/dist/chains/sql_db/sql_db_chain.js +2 -0
  10. package/dist/chat_models/llama_cpp.cjs +243 -0
  11. package/dist/chat_models/llama_cpp.d.ts +94 -0
  12. package/dist/chat_models/llama_cpp.js +239 -0
  13. package/dist/document_loaders/web/pdf.cjs +23 -5
  14. package/dist/document_loaders/web/pdf.d.ts +9 -1
  15. package/dist/document_loaders/web/pdf.js +20 -2
  16. package/dist/graphs/neo4j_graph.cjs +14 -0
  17. package/dist/graphs/neo4j_graph.d.ts +14 -0
  18. package/dist/graphs/neo4j_graph.js +14 -0
  19. package/dist/llms/googlepalm.cjs +3 -0
  20. package/dist/llms/googlepalm.js +3 -0
  21. package/dist/load/import_constants.cjs +1 -0
  22. package/dist/load/import_constants.js +1 -0
  23. package/dist/retrievers/parent_document.cjs +22 -2
  24. package/dist/retrievers/parent_document.d.ts +8 -1
  25. package/dist/retrievers/parent_document.js +22 -2
  26. package/dist/schema/runnable/passthrough.cjs +3 -1
  27. package/dist/schema/runnable/passthrough.js +3 -1
  28. package/dist/sql_db.cjs +2 -0
  29. package/dist/sql_db.d.ts +2 -0
  30. package/dist/sql_db.js +2 -0
  31. package/dist/util/stream.cjs +3 -0
  32. package/dist/util/stream.js +3 -0
  33. package/dist/vectorstores/cassandra.cjs +25 -4
  34. package/dist/vectorstores/cassandra.d.ts +11 -1
  35. package/dist/vectorstores/cassandra.js +25 -4
  36. package/dist/vectorstores/momento_vector_index.cjs +3 -15
  37. package/dist/vectorstores/momento_vector_index.d.ts +0 -8
  38. package/dist/vectorstores/momento_vector_index.js +3 -15
  39. package/dist/vectorstores/neo4j_vector.cjs +14 -0
  40. package/dist/vectorstores/neo4j_vector.d.ts +14 -0
  41. package/dist/vectorstores/neo4j_vector.js +14 -0
  42. package/package.json +15 -7
@@ -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
- return `SELECT * FROM ${this.keyspace}.${this.table} ORDER BY vector ANN OF [${query}] LIMIT ${k || 1};`;
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
- ...MomentoVectorIndex.prepareMetadata(documents[idx].metadata),
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
- ...MomentoVectorIndex.prepareMetadata(documents[idx].metadata),
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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.0.170",
3
+ "version": "0.0.171",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -475,6 +475,9 @@
475
475
  "chat_models/minimax.cjs",
476
476
  "chat_models/minimax.js",
477
477
  "chat_models/minimax.d.ts",
478
+ "chat_models/llama_cpp.cjs",
479
+ "chat_models/llama_cpp.js",
480
+ "chat_models/llama_cpp.d.ts",
478
481
  "chat_models/yandex.cjs",
479
482
  "chat_models/yandex.js",
480
483
  "chat_models/yandex.d.ts",
@@ -765,8 +768,8 @@
765
768
  "@faker-js/faker": "^7.6.0",
766
769
  "@getmetal/metal-sdk": "^4.0.0",
767
770
  "@getzep/zep-js": "^0.8.0",
768
- "@gomomento/sdk": "^1.41.2",
769
- "@gomomento/sdk-core": "^1.41.2",
771
+ "@gomomento/sdk": "^1.44.1",
772
+ "@gomomento/sdk-core": "^1.44.1",
770
773
  "@google-ai/generativelanguage": "^0.2.1",
771
774
  "@google-cloud/storage": "^6.10.1",
772
775
  "@huggingface/inference": "^1.5.1",
@@ -853,7 +856,7 @@
853
856
  "mongodb": "^5.2.0",
854
857
  "mysql2": "^3.3.3",
855
858
  "neo4j-driver": "^5.12.0",
856
- "node-llama-cpp": "^2.1.2",
859
+ "node-llama-cpp": "2.7.3",
857
860
  "notion-to-md": "^3.1.0",
858
861
  "pdf-parse": "1.1.1",
859
862
  "peggy": "^3.0.2",
@@ -900,9 +903,9 @@
900
903
  "@elastic/elasticsearch": "^8.4.0",
901
904
  "@getmetal/metal-sdk": "*",
902
905
  "@getzep/zep-js": "^0.8.0",
903
- "@gomomento/sdk": "^1.41.2",
904
- "@gomomento/sdk-core": "^1.41.2",
905
- "@gomomento/sdk-web": "^1.41.2",
906
+ "@gomomento/sdk": "^1.44.1",
907
+ "@gomomento/sdk-core": "^1.44.1",
908
+ "@gomomento/sdk-web": "^1.44.1",
906
909
  "@google-ai/generativelanguage": "^0.2.1",
907
910
  "@google-cloud/storage": "^6.10.1",
908
911
  "@huggingface/inference": "^1.5.1",
@@ -2085,6 +2088,11 @@
2085
2088
  "import": "./chat_models/minimax.js",
2086
2089
  "require": "./chat_models/minimax.cjs"
2087
2090
  },
2091
+ "./chat_models/llama_cpp": {
2092
+ "types": "./chat_models/llama_cpp.d.ts",
2093
+ "import": "./chat_models/llama_cpp.js",
2094
+ "require": "./chat_models/llama_cpp.cjs"
2095
+ },
2088
2096
  "./chat_models/yandex": {
2089
2097
  "types": "./chat_models/yandex.d.ts",
2090
2098
  "import": "./chat_models/yandex.js",