@mastra/pinecone 0.10.2-alpha.0 → 0.10.3-alpha.0

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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/pinecone@0.10.2-alpha.0 build /home/runner/work/mastra/mastra/stores/pinecone
2
+ > @mastra/pinecone@0.10.3-alpha.0 build /home/runner/work/mastra/mastra/stores/pinecone
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.5.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 5970ms
9
+ TSC ⚡️ Build success in 6576ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/pinecone/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/pinecone/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 9417ms
16
+ DTS ⚡️ Build success in 9619ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- CJS dist/index.cjs 12.45 KB
21
- CJS ⚡️ Build success in 599ms
22
- ESM dist/index.js 12.38 KB
23
- ESM ⚡️ Build success in 599ms
20
+ ESM dist/index.js 14.87 KB
21
+ ESM ⚡️ Build success in 922ms
22
+ CJS dist/index.cjs 15.11 KB
23
+ CJS ⚡️ Build success in 923ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @mastra/pinecone
2
2
 
3
+ ## 0.10.3-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 0e17048: Throw mastra errors in storage packages
8
+ - Updated dependencies [d1baedb]
9
+ - Updated dependencies [4d21bf2]
10
+ - Updated dependencies [2097952]
11
+ - Updated dependencies [4fb0cc2]
12
+ - Updated dependencies [d2a7a31]
13
+ - Updated dependencies [0e17048]
14
+ - @mastra/core@0.10.7-alpha.1
15
+
16
+ ## 0.10.2
17
+
18
+ ### Patch Changes
19
+
20
+ - 66f4424: Update peerdeps
21
+ - Updated dependencies [d1ed912]
22
+ - Updated dependencies [f6fd25f]
23
+ - Updated dependencies [dffb67b]
24
+ - Updated dependencies [f1f1f1b]
25
+ - Updated dependencies [925ab94]
26
+ - Updated dependencies [f9816ae]
27
+ - Updated dependencies [82090c1]
28
+ - Updated dependencies [1b443fd]
29
+ - Updated dependencies [ce97900]
30
+ - Updated dependencies [f1309d3]
31
+ - Updated dependencies [14a2566]
32
+ - Updated dependencies [f7f8293]
33
+ - Updated dependencies [48eddb9]
34
+ - @mastra/core@0.10.4
35
+
3
36
  ## 0.10.2-alpha.0
4
37
 
5
38
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var error = require('@mastra/core/error');
3
4
  var vector = require('@mastra/core/vector');
4
5
  var pinecone = require('@pinecone-database/pinecone');
5
6
  var filter = require('@mastra/core/vector/filter');
@@ -109,11 +110,23 @@ var PineconeVector = class extends vector.MastraVector {
109
110
  return "-";
110
111
  }
111
112
  async createIndex({ indexName, dimension, metric = "cosine" }) {
112
- if (!Number.isInteger(dimension) || dimension <= 0) {
113
- throw new Error("Dimension must be a positive integer");
114
- }
115
- if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
116
- throw new Error("Metric must be one of: cosine, euclidean, dotproduct");
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
+ );
117
130
  }
118
131
  try {
119
132
  await this.client.createIndex({
@@ -127,13 +140,21 @@ var PineconeVector = class extends vector.MastraVector {
127
140
  }
128
141
  }
129
142
  });
130
- } catch (error) {
131
- const message = error?.errors?.[0]?.message || error?.message;
132
- if (error.status === 409 || typeof message === "string" && (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("duplicate"))) {
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"))) {
133
146
  await this.validateExistingIndex(indexName, dimension, metric);
134
147
  return;
135
148
  }
136
- throw error;
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
+ );
137
158
  }
138
159
  }
139
160
  async upsert({
@@ -153,11 +174,23 @@ var PineconeVector = class extends vector.MastraVector {
153
174
  metadata: metadata?.[i] || {}
154
175
  }));
155
176
  const batchSize = 100;
156
- for (let i = 0; i < records.length; i += batchSize) {
157
- const batch = records.slice(i, i + batchSize);
158
- await index.upsert(batch);
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
+ );
159
193
  }
160
- return vectorIds;
161
194
  }
162
195
  transformFilter(filter) {
163
196
  const translator = new PineconeFilterTranslator();
@@ -184,17 +217,40 @@ var PineconeVector = class extends vector.MastraVector {
184
217
  if (sparseVector) {
185
218
  queryParams.sparseVector = sparseVector;
186
219
  }
187
- const results = await index.query(queryParams);
188
- return results.matches.map((match) => ({
189
- id: match.id,
190
- score: match.score || 0,
191
- metadata: match.metadata,
192
- ...includeVector && { vector: match.values || [] }
193
- }));
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
+ }
194
239
  }
195
240
  async listIndexes() {
196
- const indexesResult = await this.client.listIndexes();
197
- return indexesResult?.indexes?.map((index) => index.name) || [];
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
+ }
198
254
  }
199
255
  /**
200
256
  * Retrieves statistics about a vector index.
@@ -203,21 +259,41 @@ var PineconeVector = class extends vector.MastraVector {
203
259
  * @returns A promise that resolves to the index statistics including dimension, count and metric
204
260
  */
205
261
  async describeIndex({ indexName }) {
206
- const index = this.client.Index(indexName);
207
- const stats = await index.describeIndexStats();
208
- const description = await this.client.describeIndex(indexName);
209
- return {
210
- dimension: description.dimension,
211
- count: stats.totalRecordCount || 0,
212
- metric: description.metric,
213
- namespaces: stats.namespaces
214
- };
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
+ }
215
283
  }
216
284
  async deleteIndex({ indexName }) {
217
285
  try {
218
286
  await this.client.deleteIndex(indexName);
219
- } catch (error) {
220
- throw new Error(`Failed to delete Pinecone index: ${error.message}`);
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
+ );
221
297
  }
222
298
  }
223
299
  /**
@@ -232,10 +308,16 @@ var PineconeVector = class extends vector.MastraVector {
232
308
  * @throws Will throw an error if no updates are provided or if the update operation fails.
233
309
  */
234
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
+ }
235
320
  try {
236
- if (!update.vector && !update.metadata) {
237
- throw new Error("No updates provided");
238
- }
239
321
  const index = this.client.Index(indexName).namespace(namespace || "");
240
322
  const updateObj = { id };
241
323
  if (update.vector) {
@@ -245,8 +327,16 @@ var PineconeVector = class extends vector.MastraVector {
245
327
  updateObj.metadata = update.metadata;
246
328
  }
247
329
  await index.update(updateObj);
248
- } catch (error) {
249
- throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
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
+ );
250
340
  }
251
341
  }
252
342
  /**
@@ -261,8 +351,16 @@ var PineconeVector = class extends vector.MastraVector {
261
351
  try {
262
352
  const index = this.client.Index(indexName).namespace(namespace || "");
263
353
  await index.deleteOne(id);
264
- } catch (error) {
265
- throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
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
+ );
266
364
  }
267
365
  }
268
366
  };
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
1
2
  import { MastraVector } from '@mastra/core/vector';
2
3
  import { Pinecone } from '@pinecone-database/pinecone';
3
4
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
@@ -107,11 +108,23 @@ var PineconeVector = class extends MastraVector {
107
108
  return "-";
108
109
  }
109
110
  async createIndex({ indexName, dimension, metric = "cosine" }) {
110
- if (!Number.isInteger(dimension) || dimension <= 0) {
111
- throw new Error("Dimension must be a positive integer");
112
- }
113
- if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
114
- throw new Error("Metric must be one of: cosine, euclidean, dotproduct");
111
+ try {
112
+ if (!Number.isInteger(dimension) || dimension <= 0) {
113
+ throw new Error("Dimension must be a positive integer");
114
+ }
115
+ if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
116
+ throw new Error("Metric must be one of: cosine, euclidean, dotproduct");
117
+ }
118
+ } catch (validationError) {
119
+ throw new MastraError(
120
+ {
121
+ id: "STORAGE_PINECONE_VECTOR_CREATE_INDEX_INVALID_ARGS",
122
+ domain: ErrorDomain.STORAGE,
123
+ category: ErrorCategory.USER,
124
+ details: { indexName, dimension, metric }
125
+ },
126
+ validationError
127
+ );
115
128
  }
116
129
  try {
117
130
  await this.client.createIndex({
@@ -131,7 +144,15 @@ var PineconeVector = class extends MastraVector {
131
144
  await this.validateExistingIndex(indexName, dimension, metric);
132
145
  return;
133
146
  }
134
- throw error;
147
+ throw new MastraError(
148
+ {
149
+ id: "STORAGE_PINECONE_VECTOR_CREATE_INDEX_FAILED",
150
+ domain: ErrorDomain.STORAGE,
151
+ category: ErrorCategory.THIRD_PARTY,
152
+ details: { indexName, dimension, metric }
153
+ },
154
+ error
155
+ );
135
156
  }
136
157
  }
137
158
  async upsert({
@@ -151,11 +172,23 @@ var PineconeVector = class extends MastraVector {
151
172
  metadata: metadata?.[i] || {}
152
173
  }));
153
174
  const batchSize = 100;
154
- for (let i = 0; i < records.length; i += batchSize) {
155
- const batch = records.slice(i, i + batchSize);
156
- await index.upsert(batch);
175
+ try {
176
+ for (let i = 0; i < records.length; i += batchSize) {
177
+ const batch = records.slice(i, i + batchSize);
178
+ await index.upsert(batch);
179
+ }
180
+ return vectorIds;
181
+ } catch (error) {
182
+ throw new MastraError(
183
+ {
184
+ id: "STORAGE_PINECONE_VECTOR_UPSERT_FAILED",
185
+ domain: ErrorDomain.STORAGE,
186
+ category: ErrorCategory.THIRD_PARTY,
187
+ details: { indexName, vectorCount: vectors.length }
188
+ },
189
+ error
190
+ );
157
191
  }
158
- return vectorIds;
159
192
  }
160
193
  transformFilter(filter) {
161
194
  const translator = new PineconeFilterTranslator();
@@ -182,17 +215,40 @@ var PineconeVector = class extends MastraVector {
182
215
  if (sparseVector) {
183
216
  queryParams.sparseVector = sparseVector;
184
217
  }
185
- const results = await index.query(queryParams);
186
- return results.matches.map((match) => ({
187
- id: match.id,
188
- score: match.score || 0,
189
- metadata: match.metadata,
190
- ...includeVector && { vector: match.values || [] }
191
- }));
218
+ try {
219
+ const results = await index.query(queryParams);
220
+ return results.matches.map((match) => ({
221
+ id: match.id,
222
+ score: match.score || 0,
223
+ metadata: match.metadata,
224
+ ...includeVector && { vector: match.values || [] }
225
+ }));
226
+ } catch (error) {
227
+ throw new MastraError(
228
+ {
229
+ id: "STORAGE_PINECONE_VECTOR_QUERY_FAILED",
230
+ domain: ErrorDomain.STORAGE,
231
+ category: ErrorCategory.THIRD_PARTY,
232
+ details: { indexName, topK }
233
+ },
234
+ error
235
+ );
236
+ }
192
237
  }
193
238
  async listIndexes() {
194
- const indexesResult = await this.client.listIndexes();
195
- return indexesResult?.indexes?.map((index) => index.name) || [];
239
+ try {
240
+ const indexesResult = await this.client.listIndexes();
241
+ return indexesResult?.indexes?.map((index) => index.name) || [];
242
+ } catch (error) {
243
+ throw new MastraError(
244
+ {
245
+ id: "STORAGE_PINECONE_VECTOR_LIST_INDEXES_FAILED",
246
+ domain: ErrorDomain.STORAGE,
247
+ category: ErrorCategory.THIRD_PARTY
248
+ },
249
+ error
250
+ );
251
+ }
196
252
  }
197
253
  /**
198
254
  * Retrieves statistics about a vector index.
@@ -201,21 +257,41 @@ var PineconeVector = class extends MastraVector {
201
257
  * @returns A promise that resolves to the index statistics including dimension, count and metric
202
258
  */
203
259
  async describeIndex({ indexName }) {
204
- const index = this.client.Index(indexName);
205
- const stats = await index.describeIndexStats();
206
- const description = await this.client.describeIndex(indexName);
207
- return {
208
- dimension: description.dimension,
209
- count: stats.totalRecordCount || 0,
210
- metric: description.metric,
211
- namespaces: stats.namespaces
212
- };
260
+ try {
261
+ const index = this.client.Index(indexName);
262
+ const stats = await index.describeIndexStats();
263
+ const description = await this.client.describeIndex(indexName);
264
+ return {
265
+ dimension: description.dimension,
266
+ count: stats.totalRecordCount || 0,
267
+ metric: description.metric,
268
+ namespaces: stats.namespaces
269
+ };
270
+ } catch (error) {
271
+ throw new MastraError(
272
+ {
273
+ id: "STORAGE_PINECONE_VECTOR_DESCRIBE_INDEX_FAILED",
274
+ domain: ErrorDomain.STORAGE,
275
+ category: ErrorCategory.THIRD_PARTY,
276
+ details: { indexName }
277
+ },
278
+ error
279
+ );
280
+ }
213
281
  }
214
282
  async deleteIndex({ indexName }) {
215
283
  try {
216
284
  await this.client.deleteIndex(indexName);
217
285
  } catch (error) {
218
- throw new Error(`Failed to delete Pinecone index: ${error.message}`);
286
+ throw new MastraError(
287
+ {
288
+ id: "STORAGE_PINECONE_VECTOR_DELETE_INDEX_FAILED",
289
+ domain: ErrorDomain.STORAGE,
290
+ category: ErrorCategory.THIRD_PARTY,
291
+ details: { indexName }
292
+ },
293
+ error
294
+ );
219
295
  }
220
296
  }
221
297
  /**
@@ -230,10 +306,16 @@ var PineconeVector = class extends MastraVector {
230
306
  * @throws Will throw an error if no updates are provided or if the update operation fails.
231
307
  */
232
308
  async updateVector({ indexName, id, update, namespace }) {
309
+ if (!update.vector && !update.metadata) {
310
+ throw new MastraError({
311
+ id: "STORAGE_PINECONE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
312
+ domain: ErrorDomain.STORAGE,
313
+ category: ErrorCategory.USER,
314
+ text: "No updates provided",
315
+ details: { indexName, id }
316
+ });
317
+ }
233
318
  try {
234
- if (!update.vector && !update.metadata) {
235
- throw new Error("No updates provided");
236
- }
237
319
  const index = this.client.Index(indexName).namespace(namespace || "");
238
320
  const updateObj = { id };
239
321
  if (update.vector) {
@@ -244,7 +326,15 @@ var PineconeVector = class extends MastraVector {
244
326
  }
245
327
  await index.update(updateObj);
246
328
  } catch (error) {
247
- throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
329
+ throw new MastraError(
330
+ {
331
+ id: "STORAGE_PINECONE_VECTOR_UPDATE_VECTOR_FAILED",
332
+ domain: ErrorDomain.STORAGE,
333
+ category: ErrorCategory.THIRD_PARTY,
334
+ details: { indexName, id }
335
+ },
336
+ error
337
+ );
248
338
  }
249
339
  }
250
340
  /**
@@ -260,7 +350,15 @@ var PineconeVector = class extends MastraVector {
260
350
  const index = this.client.Index(indexName).namespace(namespace || "");
261
351
  await index.deleteOne(id);
262
352
  } catch (error) {
263
- throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
353
+ throw new MastraError(
354
+ {
355
+ id: "STORAGE_PINECONE_VECTOR_DELETE_VECTOR_FAILED",
356
+ domain: ErrorDomain.STORAGE,
357
+ category: ErrorCategory.THIRD_PARTY,
358
+ details: { indexName, id }
359
+ },
360
+ error
361
+ );
264
362
  }
265
363
  }
266
364
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/pinecone",
3
- "version": "0.10.2-alpha.0",
3
+ "version": "0.10.3-alpha.0",
4
4
  "description": "Pinecone vector store provider for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,14 +24,14 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@microsoft/api-extractor": "^7.52.8",
27
- "@types/node": "^20.17.57",
27
+ "@types/node": "^20.19.0",
28
28
  "dotenv": "^16.5.0",
29
29
  "eslint": "^9.28.0",
30
30
  "tsup": "^8.5.0",
31
- "typescript": "^5.8.2",
32
- "vitest": "^3.2.2",
33
- "@internal/lint": "0.0.10",
34
- "@mastra/core": "0.10.4-alpha.3"
31
+ "typescript": "^5.8.3",
32
+ "vitest": "^3.2.3",
33
+ "@internal/lint": "0.0.13",
34
+ "@mastra/core": "0.10.7-alpha.1"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@mastra/core": ">=0.10.4-0 <0.11.0"
@@ -1,3 +1,4 @@
1
+ import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';
1
2
  import { MastraVector } from '@mastra/core/vector';
2
3
  import type {
3
4
  QueryResult,
@@ -73,12 +74,25 @@ export class PineconeVector extends MastraVector {
73
74
  }
74
75
 
75
76
  async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {
76
- if (!Number.isInteger(dimension) || dimension <= 0) {
77
- throw new Error('Dimension must be a positive integer');
78
- }
79
- if (metric && !['cosine', 'euclidean', 'dotproduct'].includes(metric)) {
80
- throw new Error('Metric must be one of: cosine, euclidean, dotproduct');
77
+ try {
78
+ if (!Number.isInteger(dimension) || dimension <= 0) {
79
+ throw new Error('Dimension must be a positive integer');
80
+ }
81
+ if (metric && !['cosine', 'euclidean', 'dotproduct'].includes(metric)) {
82
+ throw new Error('Metric must be one of: cosine, euclidean, dotproduct');
83
+ }
84
+ } catch (validationError) {
85
+ throw new MastraError(
86
+ {
87
+ id: 'STORAGE_PINECONE_VECTOR_CREATE_INDEX_INVALID_ARGS',
88
+ domain: ErrorDomain.STORAGE,
89
+ category: ErrorCategory.USER,
90
+ details: { indexName, dimension, metric },
91
+ },
92
+ validationError,
93
+ );
81
94
  }
95
+
82
96
  try {
83
97
  await this.client.createIndex({
84
98
  name: indexName,
@@ -103,8 +117,16 @@ export class PineconeVector extends MastraVector {
103
117
  await this.validateExistingIndex(indexName, dimension, metric);
104
118
  return;
105
119
  }
106
- // For any other errors, propagate
107
- throw error;
120
+ // For any other errors, wrap in MastraError
121
+ throw new MastraError(
122
+ {
123
+ id: 'STORAGE_PINECONE_VECTOR_CREATE_INDEX_FAILED',
124
+ domain: ErrorDomain.STORAGE,
125
+ category: ErrorCategory.THIRD_PARTY,
126
+ details: { indexName, dimension, metric },
127
+ },
128
+ error,
129
+ );
108
130
  }
109
131
  }
110
132
 
@@ -130,12 +152,24 @@ export class PineconeVector extends MastraVector {
130
152
 
131
153
  // Pinecone has a limit of 100 vectors per upsert request
132
154
  const batchSize = 100;
133
- for (let i = 0; i < records.length; i += batchSize) {
134
- const batch = records.slice(i, i + batchSize);
135
- await index.upsert(batch);
136
- }
155
+ try {
156
+ for (let i = 0; i < records.length; i += batchSize) {
157
+ const batch = records.slice(i, i + batchSize);
158
+ await index.upsert(batch);
159
+ }
137
160
 
138
- return vectorIds;
161
+ return vectorIds;
162
+ } catch (error) {
163
+ throw new MastraError(
164
+ {
165
+ id: 'STORAGE_PINECONE_VECTOR_UPSERT_FAILED',
166
+ domain: ErrorDomain.STORAGE,
167
+ category: ErrorCategory.THIRD_PARTY,
168
+ details: { indexName, vectorCount: vectors.length },
169
+ },
170
+ error,
171
+ );
172
+ }
139
173
  }
140
174
 
141
175
  transformFilter(filter?: VectorFilter) {
@@ -169,19 +203,42 @@ export class PineconeVector extends MastraVector {
169
203
  queryParams.sparseVector = sparseVector;
170
204
  }
171
205
 
172
- const results = await index.query(queryParams);
173
-
174
- return results.matches.map(match => ({
175
- id: match.id,
176
- score: match.score || 0,
177
- metadata: match.metadata as Record<string, any>,
178
- ...(includeVector && { vector: match.values || [] }),
179
- }));
206
+ try {
207
+ const results = await index.query(queryParams);
208
+
209
+ return results.matches.map(match => ({
210
+ id: match.id,
211
+ score: match.score || 0,
212
+ metadata: match.metadata as Record<string, any>,
213
+ ...(includeVector && { vector: match.values || [] }),
214
+ }));
215
+ } catch (error) {
216
+ throw new MastraError(
217
+ {
218
+ id: 'STORAGE_PINECONE_VECTOR_QUERY_FAILED',
219
+ domain: ErrorDomain.STORAGE,
220
+ category: ErrorCategory.THIRD_PARTY,
221
+ details: { indexName, topK },
222
+ },
223
+ error,
224
+ );
225
+ }
180
226
  }
181
227
 
182
228
  async listIndexes(): Promise<string[]> {
183
- const indexesResult = await this.client.listIndexes();
184
- return indexesResult?.indexes?.map(index => index.name) || [];
229
+ try {
230
+ const indexesResult = await this.client.listIndexes();
231
+ return indexesResult?.indexes?.map(index => index.name) || [];
232
+ } catch (error) {
233
+ throw new MastraError(
234
+ {
235
+ id: 'STORAGE_PINECONE_VECTOR_LIST_INDEXES_FAILED',
236
+ domain: ErrorDomain.STORAGE,
237
+ category: ErrorCategory.THIRD_PARTY,
238
+ },
239
+ error,
240
+ );
241
+ }
185
242
  }
186
243
 
187
244
  /**
@@ -191,23 +248,43 @@ export class PineconeVector extends MastraVector {
191
248
  * @returns A promise that resolves to the index statistics including dimension, count and metric
192
249
  */
193
250
  async describeIndex({ indexName }: DescribeIndexParams): Promise<PineconeIndexStats> {
194
- const index = this.client.Index(indexName);
195
- const stats = await index.describeIndexStats();
196
- const description = await this.client.describeIndex(indexName);
197
-
198
- return {
199
- dimension: description.dimension,
200
- count: stats.totalRecordCount || 0,
201
- metric: description.metric as 'cosine' | 'euclidean' | 'dotproduct',
202
- namespaces: stats.namespaces,
203
- };
251
+ try {
252
+ const index = this.client.Index(indexName);
253
+ const stats = await index.describeIndexStats();
254
+ const description = await this.client.describeIndex(indexName);
255
+
256
+ return {
257
+ dimension: description.dimension,
258
+ count: stats.totalRecordCount || 0,
259
+ metric: description.metric as 'cosine' | 'euclidean' | 'dotproduct',
260
+ namespaces: stats.namespaces,
261
+ };
262
+ } catch (error) {
263
+ throw new MastraError(
264
+ {
265
+ id: 'STORAGE_PINECONE_VECTOR_DESCRIBE_INDEX_FAILED',
266
+ domain: ErrorDomain.STORAGE,
267
+ category: ErrorCategory.THIRD_PARTY,
268
+ details: { indexName },
269
+ },
270
+ error,
271
+ );
272
+ }
204
273
  }
205
274
 
206
275
  async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {
207
276
  try {
208
277
  await this.client.deleteIndex(indexName);
209
- } catch (error: any) {
210
- throw new Error(`Failed to delete Pinecone index: ${error.message}`);
278
+ } catch (error) {
279
+ throw new MastraError(
280
+ {
281
+ id: 'STORAGE_PINECONE_VECTOR_DELETE_INDEX_FAILED',
282
+ domain: ErrorDomain.STORAGE,
283
+ category: ErrorCategory.THIRD_PARTY,
284
+ details: { indexName },
285
+ },
286
+ error,
287
+ );
211
288
  }
212
289
  }
213
290
 
@@ -223,11 +300,17 @@ export class PineconeVector extends MastraVector {
223
300
  * @throws Will throw an error if no updates are provided or if the update operation fails.
224
301
  */
225
302
  async updateVector({ indexName, id, update, namespace }: PineconeUpdateVectorParams): Promise<void> {
226
- try {
227
- if (!update.vector && !update.metadata) {
228
- throw new Error('No updates provided');
229
- }
303
+ if (!update.vector && !update.metadata) {
304
+ throw new MastraError({
305
+ id: 'STORAGE_PINECONE_VECTOR_UPDATE_VECTOR_INVALID_ARGS',
306
+ domain: ErrorDomain.STORAGE,
307
+ category: ErrorCategory.USER,
308
+ text: 'No updates provided',
309
+ details: { indexName, id },
310
+ });
311
+ }
230
312
 
313
+ try {
231
314
  const index = this.client.Index(indexName).namespace(namespace || '');
232
315
 
233
316
  const updateObj: UpdateOptions = { id };
@@ -241,8 +324,16 @@ export class PineconeVector extends MastraVector {
241
324
  }
242
325
 
243
326
  await index.update(updateObj);
244
- } catch (error: any) {
245
- throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
327
+ } catch (error) {
328
+ throw new MastraError(
329
+ {
330
+ id: 'STORAGE_PINECONE_VECTOR_UPDATE_VECTOR_FAILED',
331
+ domain: ErrorDomain.STORAGE,
332
+ category: ErrorCategory.THIRD_PARTY,
333
+ details: { indexName, id },
334
+ },
335
+ error,
336
+ );
246
337
  }
247
338
  }
248
339
 
@@ -258,8 +349,16 @@ export class PineconeVector extends MastraVector {
258
349
  try {
259
350
  const index = this.client.Index(indexName).namespace(namespace || '');
260
351
  await index.deleteOne(id);
261
- } catch (error: any) {
262
- throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
352
+ } catch (error) {
353
+ throw new MastraError(
354
+ {
355
+ id: 'STORAGE_PINECONE_VECTOR_DELETE_VECTOR_FAILED',
356
+ domain: ErrorDomain.STORAGE,
357
+ category: ErrorCategory.THIRD_PARTY,
358
+ details: { indexName, id },
359
+ },
360
+ error,
361
+ );
263
362
  }
264
363
  }
265
364
  }