langchain 0.0.169 → 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 (97) hide show
  1. package/README.md +2 -2
  2. package/agents/format_scratchpad.cjs +1 -0
  3. package/agents/format_scratchpad.d.ts +1 -0
  4. package/agents/format_scratchpad.js +1 -0
  5. package/chat_models/llama_cpp.cjs +1 -0
  6. package/chat_models/llama_cpp.d.ts +1 -0
  7. package/chat_models/llama_cpp.js +1 -0
  8. package/dist/agents/agent.cjs +49 -1
  9. package/dist/agents/agent.d.ts +19 -1
  10. package/dist/agents/agent.js +47 -0
  11. package/dist/agents/executor.cjs +10 -1
  12. package/dist/agents/executor.d.ts +22 -8
  13. package/dist/agents/executor.js +11 -2
  14. package/dist/agents/format_scratchpad.cjs +25 -0
  15. package/dist/agents/format_scratchpad.d.ts +10 -0
  16. package/dist/agents/format_scratchpad.js +21 -0
  17. package/dist/agents/toolkits/aws_sfn.d.ts +4 -1
  18. package/dist/agents/toolkits/conversational_retrieval/openai_functions.d.ts +1 -1
  19. package/dist/agents/toolkits/json/json.d.ts +4 -1
  20. package/dist/agents/toolkits/openapi/openapi.cjs +8 -0
  21. package/dist/agents/toolkits/openapi/openapi.d.ts +12 -1
  22. package/dist/agents/toolkits/openapi/openapi.js +8 -0
  23. package/dist/agents/toolkits/sql/sql.d.ts +4 -1
  24. package/dist/agents/toolkits/vectorstore/vectorstore.d.ts +8 -2
  25. package/dist/agents/types.d.ts +13 -1
  26. package/dist/chains/sql_db/sql_db_chain.cjs +11 -0
  27. package/dist/chains/sql_db/sql_db_chain.d.ts +11 -0
  28. package/dist/chains/sql_db/sql_db_chain.js +11 -0
  29. package/dist/chat_models/baiduwenxin.cjs +12 -1
  30. package/dist/chat_models/baiduwenxin.d.ts +3 -1
  31. package/dist/chat_models/baiduwenxin.js +12 -1
  32. package/dist/chat_models/llama_cpp.cjs +243 -0
  33. package/dist/chat_models/llama_cpp.d.ts +94 -0
  34. package/dist/chat_models/llama_cpp.js +239 -0
  35. package/dist/document_loaders/web/assemblyai.cjs +63 -114
  36. package/dist/document_loaders/web/assemblyai.d.ts +38 -57
  37. package/dist/document_loaders/web/assemblyai.js +63 -100
  38. package/dist/document_loaders/web/pdf.cjs +23 -5
  39. package/dist/document_loaders/web/pdf.d.ts +9 -1
  40. package/dist/document_loaders/web/pdf.js +20 -2
  41. package/dist/graphs/neo4j_graph.cjs +14 -0
  42. package/dist/graphs/neo4j_graph.d.ts +14 -0
  43. package/dist/graphs/neo4j_graph.js +14 -0
  44. package/dist/llms/googlepalm.cjs +3 -0
  45. package/dist/llms/googlepalm.js +3 -0
  46. package/dist/load/import_constants.cjs +2 -0
  47. package/dist/load/import_constants.js +2 -0
  48. package/dist/load/import_map.cjs +3 -2
  49. package/dist/load/import_map.d.ts +1 -0
  50. package/dist/load/import_map.js +1 -0
  51. package/dist/memory/index.d.ts +1 -1
  52. package/dist/memory/index.js +1 -1
  53. package/dist/retrievers/parent_document.cjs +22 -2
  54. package/dist/retrievers/parent_document.d.ts +8 -1
  55. package/dist/retrievers/parent_document.js +22 -2
  56. package/dist/retrievers/time_weighted.cjs +1 -1
  57. package/dist/retrievers/time_weighted.d.ts +1 -1
  58. package/dist/retrievers/time_weighted.js +1 -1
  59. package/dist/schema/runnable/base.cjs +4 -1
  60. package/dist/schema/runnable/base.d.ts +1 -0
  61. package/dist/schema/runnable/base.js +4 -1
  62. package/dist/schema/runnable/passthrough.cjs +35 -1
  63. package/dist/schema/runnable/passthrough.d.ts +11 -1
  64. package/dist/schema/runnable/passthrough.js +34 -1
  65. package/dist/sql_db.cjs +14 -0
  66. package/dist/sql_db.d.ts +14 -0
  67. package/dist/sql_db.js +14 -0
  68. package/dist/storage/ioredis.cjs +2 -1
  69. package/dist/storage/ioredis.js +2 -1
  70. package/dist/storage/upstash_redis.cjs +155 -0
  71. package/dist/storage/upstash_redis.d.ts +59 -0
  72. package/dist/storage/upstash_redis.js +151 -0
  73. package/dist/storage/vercel_kv.cjs +2 -1
  74. package/dist/storage/vercel_kv.js +2 -1
  75. package/dist/types/assemblyai-types.cjs +0 -150
  76. package/dist/types/assemblyai-types.d.ts +4 -670
  77. package/dist/types/assemblyai-types.js +1 -149
  78. package/dist/util/stream.cjs +3 -0
  79. package/dist/util/stream.js +3 -0
  80. package/dist/vectorstores/cassandra.cjs +25 -4
  81. package/dist/vectorstores/cassandra.d.ts +11 -1
  82. package/dist/vectorstores/cassandra.js +25 -4
  83. package/dist/vectorstores/momento_vector_index.cjs +3 -15
  84. package/dist/vectorstores/momento_vector_index.d.ts +0 -8
  85. package/dist/vectorstores/momento_vector_index.js +3 -15
  86. package/dist/vectorstores/neo4j_vector.cjs +14 -0
  87. package/dist/vectorstores/neo4j_vector.d.ts +14 -0
  88. package/dist/vectorstores/neo4j_vector.js +14 -0
  89. package/dist/vectorstores/pgvector.cjs +1 -1
  90. package/dist/vectorstores/pgvector.js +1 -1
  91. package/package.json +37 -8
  92. package/storage/upstash_redis.cjs +1 -0
  93. package/storage/upstash_redis.d.ts +1 -0
  94. package/storage/upstash_redis.js +1 -0
  95. package/dist/util/assemblyai-client.cjs +0 -173
  96. package/dist/util/assemblyai-client.d.ts +0 -63
  97. package/dist/util/assemblyai-client.js +0 -170
@@ -1,149 +1 @@
1
- /**
2
- * The list of PII Redaction policies to enable.
3
- * See [PII redaction]{@link https://www.assemblyai.com/docs/Models/pii_redaction} for more details.
4
- */
5
- export const PiiPolicy = {
6
- /**
7
- * Medical process, including treatments, procedures, and tests (e.g., heart surgery, CT scan)
8
- */
9
- MedicalProcess: "medical_process",
10
- /**
11
- * Name of a medical condition, disease, syndrome, deficit, or disorder (e.g., chronic fatigue syndrome, arrhythmia, depression)
12
- */
13
- MedicalCondition: "medical_condition",
14
- /**
15
- * Blood type (e.g., O-, AB positive)
16
- */
17
- BloodType: "blood_type",
18
- /**
19
- * Medications, vitamins, or supplements (e.g., Advil, Acetaminophen, Panadol)
20
- */
21
- Drug: "drug",
22
- /**
23
- * Bodily injury (e.g., I broke my arm, I have a sprained wrist)
24
- */
25
- Injury: "injury",
26
- /**
27
- * A "lazy" rule that will redact any sequence of numbers equal to or greater than 2
28
- */
29
- NumberSequence: "number_sequence",
30
- /**
31
- * Email address (e.g., support@assemblyai.com)
32
- */
33
- EmailAddress: "email_address",
34
- /**
35
- * Date of Birth (e.g., Date of Birth: March 7,1961)
36
- */
37
- DateOfBirth: "date_of_birth",
38
- /**
39
- * Telephone or fax number
40
- */
41
- PhoneNumber: "phone_number",
42
- /**
43
- * Social Security Number or equivalent
44
- */
45
- UsSocialSecurityNumber: "us_social_security_number",
46
- /**
47
- * Credit card number
48
- */
49
- CreditCardNumber: "credit_card_number",
50
- /**
51
- * Expiration date of a credit card
52
- */
53
- CreditCardExpiration: "credit_card_expiration",
54
- /**
55
- * Credit card verification code (e.g., CVV: 080)
56
- */
57
- CreditCardCvv: "credit_card_cvv",
58
- /**
59
- * Specific calendar date (e.g., December 18)
60
- */
61
- Date: "date",
62
- /**
63
- * Terms indicating nationality, ethnicity, or race (e.g., American, Asian, Caucasian)
64
- */
65
- Nationality: "nationality",
66
- /**
67
- * Name of an event or holiday (e.g., Olympics, Yom Kippur)
68
- */
69
- Event: "event",
70
- /**
71
- * Name of a natural language (e.g., Spanish, French)
72
- */
73
- Language: "language",
74
- /**
75
- * Any Location reference including mailing address, postal code, city, state, province, or country
76
- */
77
- Location: "location",
78
- /**
79
- * Name and/or amount of currency (e.g., 15 pesos, $94.50)
80
- */
81
- MoneyAmount: "money_amount",
82
- /**
83
- * Name of a person (e.g., Bob, Doug Jones)
84
- */
85
- PersonName: "person_name",
86
- /**
87
- * Number associated with an age (e.g., 27, 75)
88
- */
89
- PersonAge: "person_age",
90
- /**
91
- * Name of an organization (e.g., CNN, McDonalds, University of Alaska)
92
- */
93
- Organization: "organization",
94
- /**
95
- * Terms referring to a political party, movement, or ideology (e.g., Republican, Liberal)
96
- */
97
- PoliticalAffiliation: "political_affiliation",
98
- /**
99
- * Job title or profession (e.g., professor, actors, engineer, CPA)
100
- */
101
- Occupation: "occupation",
102
- /**
103
- * Terms indicating religious affiliation (e.g., Hindu, Catholic)
104
- */
105
- Religion: "religion",
106
- /**
107
- * Driver’s license number (e.g., DL# 356933-540)
108
- */
109
- DriversLicense: "drivers_license",
110
- /**
111
- * Banking information, including account and routing numbers
112
- */
113
- BankingInformation: "banking_information",
114
- };
115
- export const EntityType = {
116
- BloodType: "Blood type (e.g., O-, AB positive)",
117
- CreditCardCvv: "Credit card verification code (e.g., CVV: 080)",
118
- CreditCardExpiration: "Expiration date of a credit card",
119
- CreditCardNumber: "Credit card number",
120
- Date: "Specific calendar date (e.g., December 18)",
121
- DateOfBirth: "Date of Birth (e.g., Date of Birth: March 7, 1961)",
122
- Drug: "Medications, vitamins, or supplements (e.g., Advil, Acetaminophen, Panadol)",
123
- Event: "Name of an event or holiday (e.g., Olympics, Yom Kippur)",
124
- EmailAddress: "Email address (e.g., support@assemblyai.com)",
125
- Injury: "Bodily injury (e.g., I broke my arm, I have a sprained wrist)",
126
- Language: "Name of a natural language (e.g., Spanish, French)",
127
- Location: "Any location reference including mailing address, postal code, city, state, province, or country",
128
- MedicalCondition: "Name of a medical condition, disease, syndrome, deficit, or disorder (e.g., chronic fatigue syndrome, arrhythmia, depression)",
129
- MedicalProcess: "Medical process, including treatments, procedures, and tests (e.g., heart surgery, CT scan)",
130
- MoneyAmount: "Name and/or amount of currency (e.g., 15 pesos, $94.50)",
131
- Nationality: "Terms indicating nationality, ethnicity, or race (e.g., American, Asian, Caucasian)",
132
- Occupation: "Job title or profession (e.g., professor, actors, engineer, CPA)",
133
- Organization: "Name of an organization (e.g., CNN, McDonalds, University of Alaska)",
134
- PersonAge: "Number associated with an age (e.g., 27, 75)",
135
- PersonName: "Name of a person (e.g., Bob, Doug Jones)",
136
- PhoneNumber: "Telephone or fax number",
137
- PoliticalAffiliation: "Terms referring to a political party, movement, or ideology (e.g., Republican, Liberal)",
138
- Religion: "Terms indicating religious affiliation (e.g., Hindu, Catholic)",
139
- UsSocialSecurityNumber: "Social Security Number or equivalent",
140
- DriversLicense: "Driver's license number (e.g., DL #356933-540)",
141
- BankingInformation: "Banking information, including account and routing numbers",
142
- };
143
- /**
144
- * The format of the subtitles.
145
- */
146
- export const SubtitleFormat = {
147
- Srt: "srt",
148
- Vtt: "vtt",
149
- };
1
+ export {};
@@ -62,6 +62,9 @@ class IterableReadableStream extends ReadableStream {
62
62
  });
63
63
  }
64
64
  },
65
+ cancel() {
66
+ reader.releaseLock();
67
+ },
65
68
  });
66
69
  }
67
70
  static fromAsyncGenerator(generator) {
@@ -59,6 +59,9 @@ export class IterableReadableStream extends ReadableStream {
59
59
  });
60
60
  }
61
61
  },
62
+ cancel() {
63
+ reader.releaseLock();
64
+ },
62
65
  });
63
66
  }
64
67
  static fromAsyncGenerator(generator) {
@@ -53,6 +53,12 @@ class CassandraStore extends base_js_1.VectorStore {
53
53
  writable: true,
54
54
  value: void 0
55
55
  });
56
+ Object.defineProperty(this, "indices", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: void 0
61
+ });
56
62
  Object.defineProperty(this, "isInitialized", {
57
63
  enumerable: true,
58
64
  configurable: true,
@@ -65,6 +71,7 @@ class CassandraStore extends base_js_1.VectorStore {
65
71
  this.table = args.table;
66
72
  this.primaryKey = args.primaryKey;
67
73
  this.metadataColumns = args.metadataColumns;
74
+ this.indices = args.indices;
68
75
  }
69
76
  /**
70
77
  * Method to save vectors to the Cassandra database.
@@ -94,13 +101,14 @@ class CassandraStore extends base_js_1.VectorStore {
94
101
  * Method to search for vectors that are similar to a given query vector.
95
102
  * @param query The query vector.
96
103
  * @param k The number of similar vectors to return.
104
+ * @param filter
97
105
  * @returns Promise that resolves with an array of tuples, each containing a Document and a score.
98
106
  */
99
- async similaritySearchVectorWithScore(query, k) {
107
+ async similaritySearchVectorWithScore(query, k, filter) {
100
108
  if (!this.isInitialized) {
101
109
  await this.initialize();
102
110
  }
103
- const queryStr = this.buildSearchQuery(query, k);
111
+ const queryStr = this.buildSearchQuery(query, k, filter);
104
112
  const queryResultSet = await this.client.execute(queryStr);
105
113
  return queryResultSet?.rows.map((row, index) => {
106
114
  const textContent = row.text;
@@ -173,6 +181,11 @@ class CassandraStore extends base_js_1.VectorStore {
173
181
  await this.client
174
182
  .execute(`CREATE CUSTOM INDEX IF NOT EXISTS idx_vector_${this.table}
175
183
  ON ${this.keyspace}.${this.table}(vector) USING 'StorageAttachedIndex';`);
184
+ for await (const { name, value } of this.indices) {
185
+ await this.client
186
+ .execute(`CREATE CUSTOM INDEX IF NOT EXISTS idx_${this.table}_${name}
187
+ ON ${this.keyspace}.${this.table} ${value} USING 'StorageAttachedIndex';`);
188
+ }
176
189
  this.isInitialized = true;
177
190
  }
178
191
  /**
@@ -200,15 +213,23 @@ class CassandraStore extends base_js_1.VectorStore {
200
213
  }
201
214
  return queries;
202
215
  }
216
+ buildWhereClause(filter) {
217
+ const whereClause = Object.entries(filter)
218
+ .map(([key, value]) => `${key} = '${value}'`)
219
+ .join(" AND ");
220
+ return `WHERE ${whereClause}`;
221
+ }
203
222
  /**
204
223
  * Method to build an CQL query for searching for similar vectors in the
205
224
  * Cassandra database.
206
225
  * @param query The query vector.
207
226
  * @param k The number of similar vectors to return.
227
+ * @param filter
208
228
  * @returns The CQL query string.
209
229
  */
210
- buildSearchQuery(query, k) {
211
- return `SELECT * FROM ${this.keyspace}.${this.table} ORDER BY vector ANN OF [${query}] LIMIT ${k || 1};`;
230
+ buildSearchQuery(query, k = 1, filter = undefined) {
231
+ const whereClause = filter ? this.buildWhereClause(filter) : "";
232
+ return `SELECT * FROM ${this.keyspace}.${this.table} ${whereClause} ORDER BY vector ANN OF [${query}] LIMIT ${k}`;
212
233
  }
213
234
  }
214
235
  exports.CassandraStore = CassandraStore;
@@ -6,12 +6,17 @@ export interface Column {
6
6
  type: string;
7
7
  name: string;
8
8
  }
9
+ export interface Index {
10
+ name: string;
11
+ value: string;
12
+ }
9
13
  export interface CassandraLibArgs extends DseClientOptions {
10
14
  table: string;
11
15
  keyspace: string;
12
16
  dimensions: number;
13
17
  primaryKey: Column;
14
18
  metadataColumns: Column[];
19
+ indices: Index[];
15
20
  }
16
21
  /**
17
22
  * Class for interacting with the Cassandra database. It extends the
@@ -20,12 +25,14 @@ export interface CassandraLibArgs extends DseClientOptions {
20
25
  * texts or documents.
21
26
  */
22
27
  export declare class CassandraStore extends VectorStore {
28
+ FilterType: Record<string, any>;
23
29
  private client;
24
30
  private readonly dimensions;
25
31
  private readonly keyspace;
26
32
  private primaryKey;
27
33
  private metadataColumns;
28
34
  private readonly table;
35
+ private indices;
29
36
  private isInitialized;
30
37
  _vectorstoreType(): string;
31
38
  constructor(embeddings: Embeddings, args: CassandraLibArgs);
@@ -46,9 +53,10 @@ export declare class CassandraStore extends VectorStore {
46
53
  * Method to search for vectors that are similar to a given query vector.
47
54
  * @param query The query vector.
48
55
  * @param k The number of similar vectors to return.
56
+ * @param filter
49
57
  * @returns Promise that resolves with an array of tuples, each containing a Document and a score.
50
58
  */
51
- similaritySearchVectorWithScore(query: number[], k: number): Promise<[Document, number][]>;
59
+ similaritySearchVectorWithScore(query: number[], k: number, filter?: this["FilterType"]): Promise<[Document, number][]>;
52
60
  /**
53
61
  * Static method to create an instance of CassandraStore from texts.
54
62
  * @param texts The texts to use.
@@ -87,11 +95,13 @@ export declare class CassandraStore extends VectorStore {
87
95
  * @returns The CQL query string.
88
96
  */
89
97
  private buildInsertQuery;
98
+ private buildWhereClause;
90
99
  /**
91
100
  * Method to build an CQL query for searching for similar vectors in the
92
101
  * Cassandra database.
93
102
  * @param query The query vector.
94
103
  * @param k The number of similar vectors to return.
104
+ * @param filter
95
105
  * @returns The CQL query string.
96
106
  */
97
107
  private buildSearchQuery;
@@ -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";
@@ -193,7 +193,7 @@ class PGVectorStore extends base_js_1.VectorStore {
193
193
  const queryString = `
194
194
  SELECT *, ${this.vectorColumnName} <=> $1 as "_distance"
195
195
  FROM ${this.tableName}
196
- WHERE ${this.metadataColumnName} @> $2
196
+ WHERE ${this.metadataColumnName}::jsonb @> $2
197
197
  ORDER BY "_distance" ASC
198
198
  LIMIT $3;`;
199
199
  const documents = (await this.pool.query(queryString, [embeddingString, _filter, k])).rows;
@@ -187,7 +187,7 @@ export class PGVectorStore extends VectorStore {
187
187
  const queryString = `
188
188
  SELECT *, ${this.vectorColumnName} <=> $1 as "_distance"
189
189
  FROM ${this.tableName}
190
- WHERE ${this.metadataColumnName} @> $2
190
+ WHERE ${this.metadataColumnName}::jsonb @> $2
191
191
  ORDER BY "_distance" ASC
192
192
  LIMIT $3;`;
193
193
  const documents = (await this.pool.query(queryString, [embeddingString, _filter, k])).rows;