@mastra/pinecone 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016

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/dist/index.cjs CHANGED
@@ -1,372 +1,442 @@
1
- 'use strict';
2
-
3
- var error = require('@mastra/core/error');
4
- var vector = require('@mastra/core/vector');
5
- var pinecone = require('@pinecone-database/pinecone');
6
- var filter = require('@mastra/core/vector/filter');
7
-
8
- // src/vector/index.ts
9
- var PineconeFilterTranslator = class extends filter.BaseFilterTranslator {
10
- getSupportedOperators() {
11
- return {
12
- ...filter.BaseFilterTranslator.DEFAULT_OPERATORS,
13
- logical: ["$and", "$or"],
14
- array: ["$in", "$all", "$nin"],
15
- element: ["$exists"],
16
- regex: [],
17
- custom: []
18
- };
19
- }
20
- translate(filter) {
21
- if (this.isEmpty(filter)) return filter;
22
- this.validateFilter(filter);
23
- return this.translateNode(filter);
24
- }
25
- translateNode(node, currentPath = "") {
26
- if (this.isRegex(node)) {
27
- throw new Error("Regex is not supported in Pinecone");
28
- }
29
- if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);
30
- if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };
31
- const entries = Object.entries(node);
32
- const firstEntry = entries[0];
33
- if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {
34
- const [operator, value] = firstEntry;
35
- const translated = this.translateOperator(operator, value, currentPath);
36
- return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;
37
- }
38
- const result = {};
39
- for (const [key, value] of entries) {
40
- const newPath = currentPath ? `${currentPath}.${key}` : key;
41
- if (this.isOperator(key)) {
42
- result[key] = this.translateOperator(key, value, currentPath);
43
- continue;
44
- }
45
- if (typeof value === "object" && value !== null && !Array.isArray(value)) {
46
- if (Object.keys(value).length === 1 && "$all" in value) {
47
- const translated = this.translateNode(value, key);
48
- if (translated.$and) {
49
- return translated;
50
- }
51
- }
52
- if (Object.keys(value).length === 0) {
53
- result[newPath] = this.translateNode(value);
54
- } else {
55
- const hasOperators = Object.keys(value).some((k) => this.isOperator(k));
56
- if (hasOperators) {
57
- const normalizedValue = {};
58
- for (const [op, opValue] of Object.entries(value)) {
59
- normalizedValue[op] = this.isOperator(op) ? this.translateOperator(op, opValue) : opValue;
60
- }
61
- result[newPath] = normalizedValue;
62
- } else {
63
- Object.assign(result, this.translateNode(value, newPath));
64
- }
65
- }
66
- } else {
67
- result[newPath] = this.translateNode(value);
68
- }
69
- }
70
- return result;
71
- }
72
- translateOperator(operator, value, currentPath = "") {
73
- if (operator === "$all") {
74
- if (!Array.isArray(value) || value.length === 0) {
75
- throw new Error("A non-empty array is required for the $all operator");
76
- }
77
- return this.simulateAllOperator(currentPath, value);
78
- }
79
- if (this.isLogicalOperator(operator)) {
80
- return Array.isArray(value) ? value.map((item) => this.translateNode(item)) : this.translateNode(value);
81
- }
82
- return this.normalizeComparisonValue(value);
83
- }
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _mastra_core_error = require("@mastra/core/error");
3
+ let _mastra_core_storage = require("@mastra/core/storage");
4
+ let _mastra_core_vector = require("@mastra/core/vector");
5
+ let _pinecone_database_pinecone = require("@pinecone-database/pinecone");
6
+ let _mastra_core_vector_filter = require("@mastra/core/vector/filter");
7
+ //#region src/vector/filter.ts
8
+ var PineconeFilterTranslator = class extends _mastra_core_vector_filter.BaseFilterTranslator {
9
+ getSupportedOperators() {
10
+ return {
11
+ ..._mastra_core_vector_filter.BaseFilterTranslator.DEFAULT_OPERATORS,
12
+ logical: ["$and", "$or"],
13
+ array: [
14
+ "$in",
15
+ "$all",
16
+ "$nin"
17
+ ],
18
+ element: ["$exists"],
19
+ regex: [],
20
+ custom: []
21
+ };
22
+ }
23
+ translate(filter) {
24
+ if (this.isEmpty(filter)) return filter;
25
+ this.validateFilter(filter);
26
+ return this.translateNode(filter);
27
+ }
28
+ translateNode(node, currentPath = "") {
29
+ if (this.isRegex(node)) throw new Error("Regex is not supported in Pinecone");
30
+ if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);
31
+ if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };
32
+ const entries = Object.entries(node);
33
+ const firstEntry = entries[0];
34
+ if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {
35
+ const [operator, value] = firstEntry;
36
+ const translated = this.translateOperator(operator, value, currentPath);
37
+ return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;
38
+ }
39
+ const result = {};
40
+ for (const [key, value] of entries) {
41
+ const newPath = currentPath ? `${currentPath}.${key}` : key;
42
+ if (this.isOperator(key)) {
43
+ result[key] = this.translateOperator(key, value, currentPath);
44
+ continue;
45
+ }
46
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
47
+ if (Object.keys(value).length === 1 && "$all" in value) {
48
+ const translated = this.translateNode(value, key);
49
+ if (translated.$and) return translated;
50
+ }
51
+ if (Object.keys(value).length === 0) result[newPath] = this.translateNode(value);
52
+ else if (Object.keys(value).some((k) => this.isOperator(k))) {
53
+ const normalizedValue = {};
54
+ for (const [op, opValue] of Object.entries(value)) normalizedValue[op] = this.isOperator(op) ? this.translateOperator(op, opValue) : opValue;
55
+ result[newPath] = normalizedValue;
56
+ } else Object.assign(result, this.translateNode(value, newPath));
57
+ } else result[newPath] = this.translateNode(value);
58
+ }
59
+ return result;
60
+ }
61
+ translateOperator(operator, value, currentPath = "") {
62
+ if (operator === "$all") {
63
+ if (!Array.isArray(value) || value.length === 0) throw new Error("A non-empty array is required for the $all operator");
64
+ return this.simulateAllOperator(currentPath, value);
65
+ }
66
+ if (this.isLogicalOperator(operator)) return Array.isArray(value) ? value.map((item) => this.translateNode(item)) : this.translateNode(value);
67
+ return this.normalizeComparisonValue(value);
68
+ }
84
69
  };
85
-
86
- // src/vector/index.ts
87
- var PineconeVector = class extends vector.MastraVector {
88
- client;
89
- /**
90
- * Creates a new PineconeVector client.
91
- * @param apiKey - The API key for Pinecone.
92
- * @param environment - The environment for Pinecone.
93
- */
94
- constructor({ apiKey, environment }) {
95
- super();
96
- const opts = { apiKey };
97
- if (environment) {
98
- opts["controllerHostUrl"] = environment;
99
- }
100
- const baseClient = new pinecone.Pinecone(opts);
101
- const telemetry = this.__getTelemetry();
102
- this.client = telemetry?.traceClass(baseClient, {
103
- spanNamePrefix: "pinecone-vector",
104
- attributes: {
105
- "vector.type": "pinecone"
106
- }
107
- }) ?? baseClient;
108
- }
109
- get indexSeparator() {
110
- return "-";
111
- }
112
- async createIndex({ indexName, dimension, metric = "cosine" }) {
113
- try {
114
- if (!Number.isInteger(dimension) || dimension <= 0) {
115
- throw new Error("Dimension must be a positive integer");
116
- }
117
- if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
118
- throw new Error("Metric must be one of: cosine, euclidean, dotproduct");
119
- }
120
- } catch (validationError) {
121
- throw new error.MastraError(
122
- {
123
- id: "STORAGE_PINECONE_VECTOR_CREATE_INDEX_INVALID_ARGS",
124
- domain: error.ErrorDomain.STORAGE,
125
- category: error.ErrorCategory.USER,
126
- details: { indexName, dimension, metric }
127
- },
128
- validationError
129
- );
130
- }
131
- try {
132
- await this.client.createIndex({
133
- name: indexName,
134
- dimension,
135
- metric,
136
- spec: {
137
- serverless: {
138
- cloud: "aws",
139
- region: "us-east-1"
140
- }
141
- }
142
- });
143
- } catch (error$1) {
144
- const message = error$1?.errors?.[0]?.message || error$1?.message;
145
- if (error$1.status === 409 || typeof message === "string" && (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("duplicate"))) {
146
- await this.validateExistingIndex(indexName, dimension, metric);
147
- return;
148
- }
149
- throw new error.MastraError(
150
- {
151
- id: "STORAGE_PINECONE_VECTOR_CREATE_INDEX_FAILED",
152
- domain: error.ErrorDomain.STORAGE,
153
- category: error.ErrorCategory.THIRD_PARTY,
154
- details: { indexName, dimension, metric }
155
- },
156
- error$1
157
- );
158
- }
159
- }
160
- async upsert({
161
- indexName,
162
- vectors,
163
- metadata,
164
- ids,
165
- namespace,
166
- sparseVectors
167
- }) {
168
- const index = this.client.Index(indexName).namespace(namespace || "");
169
- const vectorIds = ids || vectors.map(() => crypto.randomUUID());
170
- const records = vectors.map((vector, i) => ({
171
- id: vectorIds[i],
172
- values: vector,
173
- ...sparseVectors?.[i] && { sparseValues: sparseVectors?.[i] },
174
- metadata: metadata?.[i] || {}
175
- }));
176
- const batchSize = 100;
177
- try {
178
- for (let i = 0; i < records.length; i += batchSize) {
179
- const batch = records.slice(i, i + batchSize);
180
- await index.upsert(batch);
181
- }
182
- return vectorIds;
183
- } catch (error$1) {
184
- throw new error.MastraError(
185
- {
186
- id: "STORAGE_PINECONE_VECTOR_UPSERT_FAILED",
187
- domain: error.ErrorDomain.STORAGE,
188
- category: error.ErrorCategory.THIRD_PARTY,
189
- details: { indexName, vectorCount: vectors.length }
190
- },
191
- error$1
192
- );
193
- }
194
- }
195
- transformFilter(filter) {
196
- const translator = new PineconeFilterTranslator();
197
- return translator.translate(filter);
198
- }
199
- async query({
200
- indexName,
201
- queryVector,
202
- topK = 10,
203
- filter,
204
- includeVector = false,
205
- namespace,
206
- sparseVector
207
- }) {
208
- const index = this.client.Index(indexName).namespace(namespace || "");
209
- const translatedFilter = this.transformFilter(filter) ?? void 0;
210
- const queryParams = {
211
- vector: queryVector,
212
- topK,
213
- includeMetadata: true,
214
- includeValues: includeVector,
215
- filter: translatedFilter
216
- };
217
- if (sparseVector) {
218
- queryParams.sparseVector = sparseVector;
219
- }
220
- try {
221
- const results = await index.query(queryParams);
222
- return results.matches.map((match) => ({
223
- id: match.id,
224
- score: match.score || 0,
225
- metadata: match.metadata,
226
- ...includeVector && { vector: match.values || [] }
227
- }));
228
- } catch (error$1) {
229
- throw new error.MastraError(
230
- {
231
- id: "STORAGE_PINECONE_VECTOR_QUERY_FAILED",
232
- domain: error.ErrorDomain.STORAGE,
233
- category: error.ErrorCategory.THIRD_PARTY,
234
- details: { indexName, topK }
235
- },
236
- error$1
237
- );
238
- }
239
- }
240
- async listIndexes() {
241
- try {
242
- const indexesResult = await this.client.listIndexes();
243
- return indexesResult?.indexes?.map((index) => index.name) || [];
244
- } catch (error$1) {
245
- throw new error.MastraError(
246
- {
247
- id: "STORAGE_PINECONE_VECTOR_LIST_INDEXES_FAILED",
248
- domain: error.ErrorDomain.STORAGE,
249
- category: error.ErrorCategory.THIRD_PARTY
250
- },
251
- error$1
252
- );
253
- }
254
- }
255
- /**
256
- * Retrieves statistics about a vector index.
257
- *
258
- * @param {string} indexName - The name of the index to describe
259
- * @returns A promise that resolves to the index statistics including dimension, count and metric
260
- */
261
- async describeIndex({ indexName }) {
262
- try {
263
- const index = this.client.Index(indexName);
264
- const stats = await index.describeIndexStats();
265
- const description = await this.client.describeIndex(indexName);
266
- return {
267
- dimension: description.dimension,
268
- count: stats.totalRecordCount || 0,
269
- metric: description.metric,
270
- namespaces: stats.namespaces
271
- };
272
- } catch (error$1) {
273
- throw new error.MastraError(
274
- {
275
- id: "STORAGE_PINECONE_VECTOR_DESCRIBE_INDEX_FAILED",
276
- domain: error.ErrorDomain.STORAGE,
277
- category: error.ErrorCategory.THIRD_PARTY,
278
- details: { indexName }
279
- },
280
- error$1
281
- );
282
- }
283
- }
284
- async deleteIndex({ indexName }) {
285
- try {
286
- await this.client.deleteIndex(indexName);
287
- } catch (error$1) {
288
- throw new error.MastraError(
289
- {
290
- id: "STORAGE_PINECONE_VECTOR_DELETE_INDEX_FAILED",
291
- domain: error.ErrorDomain.STORAGE,
292
- category: error.ErrorCategory.THIRD_PARTY,
293
- details: { indexName }
294
- },
295
- error$1
296
- );
297
- }
298
- }
299
- /**
300
- * Updates a vector by its ID with the provided vector and/or metadata.
301
- * @param indexName - The name of the index containing the vector.
302
- * @param id - The ID of the vector to update.
303
- * @param update - An object containing the vector and/or metadata to update.
304
- * @param update.vector - An optional array of numbers representing the new vector.
305
- * @param update.metadata - An optional record containing the new metadata.
306
- * @param namespace - The namespace of the index (optional).
307
- * @returns A promise that resolves when the update is complete.
308
- * @throws Will throw an error if no updates are provided or if the update operation fails.
309
- */
310
- async updateVector({ indexName, id, update, namespace }) {
311
- if (!update.vector && !update.metadata) {
312
- throw new error.MastraError({
313
- id: "STORAGE_PINECONE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
314
- domain: error.ErrorDomain.STORAGE,
315
- category: error.ErrorCategory.USER,
316
- text: "No updates provided",
317
- details: { indexName, id }
318
- });
319
- }
320
- try {
321
- const index = this.client.Index(indexName).namespace(namespace || "");
322
- const updateObj = { id };
323
- if (update.vector) {
324
- updateObj.values = update.vector;
325
- }
326
- if (update.metadata) {
327
- updateObj.metadata = update.metadata;
328
- }
329
- await index.update(updateObj);
330
- } catch (error$1) {
331
- throw new error.MastraError(
332
- {
333
- id: "STORAGE_PINECONE_VECTOR_UPDATE_VECTOR_FAILED",
334
- domain: error.ErrorDomain.STORAGE,
335
- category: error.ErrorCategory.THIRD_PARTY,
336
- details: { indexName, id }
337
- },
338
- error$1
339
- );
340
- }
341
- }
342
- /**
343
- * Deletes a vector by its ID.
344
- * @param indexName - The name of the index containing the vector.
345
- * @param id - The ID of the vector to delete.
346
- * @param namespace - The namespace of the index (optional).
347
- * @returns A promise that resolves when the deletion is complete.
348
- * @throws Will throw an error if the deletion operation fails.
349
- */
350
- async deleteVector({ indexName, id, namespace }) {
351
- try {
352
- const index = this.client.Index(indexName).namespace(namespace || "");
353
- await index.deleteOne(id);
354
- } catch (error$1) {
355
- throw new error.MastraError(
356
- {
357
- id: "STORAGE_PINECONE_VECTOR_DELETE_VECTOR_FAILED",
358
- domain: error.ErrorDomain.STORAGE,
359
- category: error.ErrorCategory.THIRD_PARTY,
360
- details: { indexName, id }
361
- },
362
- error$1
363
- );
364
- }
365
- }
70
+ //#endregion
71
+ //#region src/vector/index.ts
72
+ var PineconeVector = class extends _mastra_core_vector.MastraVector {
73
+ client;
74
+ cloud;
75
+ region;
76
+ /**
77
+ * Creates a new PineconeVector client.
78
+ *
79
+ * @param config - Configuration options for the Pinecone client.
80
+ * @see {@link PineconeVectorConfig} for all available options.
81
+ */
82
+ constructor({ id, cloud, region, ...pineconeConfig }) {
83
+ super({ id });
84
+ this.client = new _pinecone_database_pinecone.Pinecone(pineconeConfig);
85
+ this.cloud = cloud || "aws";
86
+ this.region = region || "us-east-1";
87
+ }
88
+ get indexSeparator() {
89
+ return "-";
90
+ }
91
+ async createIndex({ indexName, dimension, metric = "cosine" }) {
92
+ try {
93
+ if (!Number.isInteger(dimension) || dimension <= 0) throw new Error("Dimension must be a positive integer");
94
+ if (metric && ![
95
+ "cosine",
96
+ "euclidean",
97
+ "dotproduct"
98
+ ].includes(metric)) throw new Error("Metric must be one of: cosine, euclidean, dotproduct");
99
+ } catch (validationError) {
100
+ throw new _mastra_core_error.MastraError({
101
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "CREATE_INDEX", "INVALID_ARGS"),
102
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
103
+ category: _mastra_core_error.ErrorCategory.USER,
104
+ details: {
105
+ indexName,
106
+ dimension,
107
+ metric
108
+ }
109
+ }, validationError);
110
+ }
111
+ try {
112
+ await this.client.createIndex({
113
+ name: indexName,
114
+ dimension,
115
+ metric,
116
+ spec: { serverless: {
117
+ cloud: this.cloud,
118
+ region: this.region
119
+ } }
120
+ });
121
+ } catch (error) {
122
+ const message = error?.errors?.[0]?.message || error?.message;
123
+ if (error.status === 409 || typeof message === "string" && (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("duplicate"))) {
124
+ await this.validateExistingIndex(indexName, dimension, metric);
125
+ return;
126
+ }
127
+ throw new _mastra_core_error.MastraError({
128
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "CREATE_INDEX", "FAILED"),
129
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
130
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
131
+ details: {
132
+ indexName,
133
+ dimension,
134
+ metric
135
+ }
136
+ }, error);
137
+ }
138
+ }
139
+ async upsert({ indexName, vectors, metadata, ids, namespace, sparseVectors }) {
140
+ const index = this.client.Index(indexName).namespace(namespace || "");
141
+ const vectorIds = ids || vectors.map(() => crypto.randomUUID());
142
+ const records = vectors.map((vector, i) => ({
143
+ id: vectorIds[i],
144
+ values: vector,
145
+ ...sparseVectors?.[i] && { sparseValues: sparseVectors?.[i] },
146
+ metadata: metadata?.[i] || {}
147
+ }));
148
+ const batchSize = 100;
149
+ try {
150
+ for (let i = 0; i < records.length; i += batchSize) {
151
+ const batch = records.slice(i, i + batchSize);
152
+ await index.upsert(batch);
153
+ }
154
+ return vectorIds;
155
+ } catch (error) {
156
+ throw new _mastra_core_error.MastraError({
157
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "UPSERT", "FAILED"),
158
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
159
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
160
+ details: {
161
+ indexName,
162
+ vectorCount: vectors.length
163
+ }
164
+ }, error);
165
+ }
166
+ }
167
+ transformFilter(filter) {
168
+ return new PineconeFilterTranslator().translate(filter);
169
+ }
170
+ async query({ indexName, queryVector, topK = 10, filter, includeVector = false, namespace, sparseVector }) {
171
+ if (!queryVector) throw new _mastra_core_error.MastraError({
172
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "QUERY", "MISSING_VECTOR"),
173
+ text: "queryVector is required for Pinecone queries. Metadata-only queries are not supported by this vector store.",
174
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
175
+ category: _mastra_core_error.ErrorCategory.USER,
176
+ details: { indexName }
177
+ });
178
+ const index = this.client.Index(indexName).namespace(namespace || "");
179
+ const queryParams = {
180
+ vector: queryVector,
181
+ topK,
182
+ includeMetadata: true,
183
+ includeValues: includeVector,
184
+ filter: this.transformFilter(filter) ?? void 0
185
+ };
186
+ if (sparseVector) queryParams.sparseVector = sparseVector;
187
+ try {
188
+ return (await index.query(queryParams)).matches.map((match) => ({
189
+ id: match.id,
190
+ score: match.score || 0,
191
+ metadata: match.metadata,
192
+ ...includeVector && { vector: match.values || [] }
193
+ }));
194
+ } catch (error) {
195
+ throw new _mastra_core_error.MastraError({
196
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "QUERY", "FAILED"),
197
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
198
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
199
+ details: {
200
+ indexName,
201
+ topK
202
+ }
203
+ }, error);
204
+ }
205
+ }
206
+ async listIndexes() {
207
+ try {
208
+ return (await this.client.listIndexes())?.indexes?.map((index) => index.name) || [];
209
+ } catch (error) {
210
+ throw new _mastra_core_error.MastraError({
211
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "LIST_INDEXES", "FAILED"),
212
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
213
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY
214
+ }, error);
215
+ }
216
+ }
217
+ /**
218
+ * Retrieves statistics about a vector index.
219
+ *
220
+ * @param {string} indexName - The name of the index to describe
221
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
222
+ */
223
+ async describeIndex({ indexName }) {
224
+ try {
225
+ const stats = await this.client.Index(indexName).describeIndexStats();
226
+ const description = await this.client.describeIndex(indexName);
227
+ return {
228
+ dimension: description.dimension,
229
+ count: stats.totalRecordCount || 0,
230
+ metric: description.metric,
231
+ namespaces: stats.namespaces
232
+ };
233
+ } catch (error) {
234
+ throw new _mastra_core_error.MastraError({
235
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "DESCRIBE_INDEX", "FAILED"),
236
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
237
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
238
+ details: { indexName }
239
+ }, error);
240
+ }
241
+ }
242
+ async deleteIndex({ indexName }) {
243
+ try {
244
+ await this.client.deleteIndex(indexName);
245
+ } catch (error) {
246
+ throw new _mastra_core_error.MastraError({
247
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "DELETE_INDEX", "FAILED"),
248
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
249
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
250
+ details: { indexName }
251
+ }, error);
252
+ }
253
+ }
254
+ /**
255
+ * Updates a vector by its ID with the provided vector and/or metadata.
256
+ * Note: Pinecone only supports update by ID, not by filter.
257
+ * @param params - Parameters containing the id for targeting the vector to update
258
+ * @param params.indexName - The name of the index containing the vector.
259
+ * @param params.id - The ID of the vector to update.
260
+ * @param params.update - An object containing the vector and/or metadata to update.
261
+ * @param namespace - The namespace of the index (optional, Pinecone-specific).
262
+ * @returns A promise that resolves when the update is complete.
263
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
264
+ */
265
+ async updateVector(params) {
266
+ const { indexName, update } = params;
267
+ if ("id" in params && params.id && "filter" in params && params.filter) throw new _mastra_core_error.MastraError({
268
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
269
+ text: "Cannot specify both id and filter - they are mutually exclusive",
270
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
271
+ category: _mastra_core_error.ErrorCategory.USER,
272
+ details: { indexName }
273
+ });
274
+ if (!("id" in params && params.id) && !("filter" in params && params.filter)) throw new _mastra_core_error.MastraError({
275
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "UPDATE_VECTOR", "NO_TARGET"),
276
+ text: "Either id or filter must be provided",
277
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
278
+ category: _mastra_core_error.ErrorCategory.USER,
279
+ details: { indexName }
280
+ });
281
+ if (!update.vector && !update.metadata) throw new _mastra_core_error.MastraError({
282
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "UPDATE_VECTOR", "NO_PAYLOAD"),
283
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
284
+ category: _mastra_core_error.ErrorCategory.USER,
285
+ text: "No updates provided",
286
+ details: { indexName }
287
+ });
288
+ const namespace = params.namespace;
289
+ try {
290
+ const index = this.client.Index(indexName).namespace(namespace || "");
291
+ if ("id" in params && params.id) {
292
+ const updateObj = { id: params.id };
293
+ if (update.vector) updateObj.values = update.vector;
294
+ if (update.metadata) updateObj.metadata = update.metadata;
295
+ await index.update(updateObj);
296
+ } else if ("filter" in params && params.filter) {
297
+ if (Object.keys(params.filter).length === 0) throw new _mastra_core_error.MastraError({
298
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "UPDATE_VECTOR", "EMPTY_FILTER"),
299
+ text: "Filter cannot be an empty filter object",
300
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
301
+ category: _mastra_core_error.ErrorCategory.USER,
302
+ details: { indexName }
303
+ });
304
+ const translatedFilter = this.transformFilter(params.filter);
305
+ if (translatedFilter) {
306
+ const stats = await this.describeIndex({ indexName });
307
+ const dummyVector = new Array(stats.dimension).fill(1 / Math.sqrt(stats.dimension));
308
+ const idsToUpdate = (await index.query({
309
+ vector: dummyVector,
310
+ topK: 1e4,
311
+ filter: translatedFilter,
312
+ includeMetadata: false,
313
+ includeValues: false
314
+ })).matches.map((m) => m.id);
315
+ for (const id of idsToUpdate) {
316
+ const updateObj = { id };
317
+ if (update.vector) updateObj.values = update.vector;
318
+ if (update.metadata) updateObj.metadata = update.metadata;
319
+ await index.update(updateObj);
320
+ }
321
+ }
322
+ }
323
+ } catch (error) {
324
+ if (error instanceof _mastra_core_error.MastraError) throw error;
325
+ throw new _mastra_core_error.MastraError({
326
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "UPDATE_VECTOR", "FAILED"),
327
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
328
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
329
+ details: {
330
+ indexName,
331
+ ..."id" in params && params.id && { id: params.id },
332
+ ..."filter" in params && params.filter && { filter: JSON.stringify(params.filter) }
333
+ }
334
+ }, error);
335
+ }
336
+ }
337
+ /**
338
+ * Deletes a vector by its ID.
339
+ * @param indexName - The name of the index containing the vector.
340
+ * @param id - The ID of the vector to delete.
341
+ * @param namespace - The namespace of the index (optional).
342
+ * @returns A promise that resolves when the deletion is complete.
343
+ * @throws Will throw an error if the deletion operation fails.
344
+ */
345
+ async deleteVector({ indexName, id, namespace }) {
346
+ try {
347
+ await this.client.Index(indexName).namespace(namespace || "").deleteOne(id);
348
+ } catch (error) {
349
+ throw new _mastra_core_error.MastraError({
350
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "DELETE_VECTOR", "FAILED"),
351
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
352
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
353
+ details: {
354
+ indexName,
355
+ ...id && { id }
356
+ }
357
+ }, error);
358
+ }
359
+ }
360
+ /**
361
+ * Deletes multiple vectors by IDs or filter.
362
+ * @param indexName - The name of the index containing the vectors.
363
+ * @param ids - Array of vector IDs to delete (mutually exclusive with filter).
364
+ * @param filter - Filter to match vectors to delete (mutually exclusive with ids).
365
+ * @param namespace - The namespace of the index (optional, Pinecone-specific).
366
+ * @returns A promise that resolves when the deletion is complete.
367
+ * @throws Will throw an error if both ids and filter are provided, or if neither is provided.
368
+ */
369
+ async deleteVectors(params) {
370
+ const { indexName, filter, ids } = params;
371
+ const namespace = params.namespace;
372
+ if (ids && filter) throw new _mastra_core_error.MastraError({
373
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
374
+ text: "Cannot specify both ids and filter - they are mutually exclusive",
375
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
376
+ category: _mastra_core_error.ErrorCategory.USER,
377
+ details: { indexName }
378
+ });
379
+ if (!ids && !filter) throw new _mastra_core_error.MastraError({
380
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "DELETE_VECTORS", "NO_TARGET"),
381
+ text: "Either filter or ids must be provided",
382
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
383
+ category: _mastra_core_error.ErrorCategory.USER,
384
+ details: { indexName }
385
+ });
386
+ if (ids && ids.length === 0) throw new _mastra_core_error.MastraError({
387
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "DELETE_VECTORS", "EMPTY_IDS"),
388
+ text: "Cannot delete with empty ids array",
389
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
390
+ category: _mastra_core_error.ErrorCategory.USER,
391
+ details: { indexName }
392
+ });
393
+ if (filter && Object.keys(filter).length === 0) throw new _mastra_core_error.MastraError({
394
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "DELETE_VECTORS", "EMPTY_FILTER"),
395
+ text: "Cannot delete with empty filter object",
396
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
397
+ category: _mastra_core_error.ErrorCategory.USER,
398
+ details: { indexName }
399
+ });
400
+ try {
401
+ const index = this.client.Index(indexName).namespace(namespace || "");
402
+ if (ids) await index.deleteMany(ids);
403
+ else if (filter) {
404
+ const translatedFilter = this.transformFilter(filter);
405
+ if (translatedFilter) {
406
+ const stats = await this.describeIndex({ indexName });
407
+ const dummyVector = new Array(stats.dimension).fill(1 / Math.sqrt(stats.dimension));
408
+ const idsToDelete = (await index.query({
409
+ vector: dummyVector,
410
+ topK: 1e4,
411
+ filter: translatedFilter,
412
+ includeMetadata: false,
413
+ includeValues: false
414
+ })).matches.map((m) => m.id);
415
+ if (idsToDelete.length > 0) await index.deleteMany(idsToDelete);
416
+ }
417
+ }
418
+ } catch (error) {
419
+ if (error instanceof _mastra_core_error.MastraError) throw error;
420
+ throw new _mastra_core_error.MastraError({
421
+ id: (0, _mastra_core_storage.createVectorErrorId)("PINECONE", "DELETE_VECTORS", "FAILED"),
422
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
423
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
424
+ details: {
425
+ indexName,
426
+ ...filter && { filter: JSON.stringify(filter) },
427
+ ...ids && { idsCount: ids.length }
428
+ }
429
+ }, error);
430
+ }
431
+ }
366
432
  };
367
-
368
- // src/vector/prompt.ts
369
- var PINECONE_PROMPT = `When querying Pinecone, you can ONLY use the operators listed below. Any other operators will be rejected.
433
+ //#endregion
434
+ //#region src/vector/prompt.ts
435
+ /**
436
+ * Vector store specific prompt that details supported operators and examples.
437
+ * This prompt helps users construct valid filters for Pinecone Vector.
438
+ */
439
+ const PINECONE_PROMPT = `When querying Pinecone, you can ONLY use the operators listed below. Any other operators will be rejected.
370
440
  Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
371
441
  If a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.
372
442
 
@@ -443,8 +513,8 @@ Example Complex Query:
443
513
  ]}
444
514
  ]
445
515
  }`;
446
-
516
+ //#endregion
447
517
  exports.PINECONE_PROMPT = PINECONE_PROMPT;
448
518
  exports.PineconeVector = PineconeVector;
449
- //# sourceMappingURL=index.cjs.map
519
+
450
520
  //# sourceMappingURL=index.cjs.map