@mastra/pinecone 0.10.2 → 0.11.0-alpha.1

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.11.0-alpha.1 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 5926ms
9
+ TSC ⚡️ Build success in 7566ms
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 8809ms
16
+ DTS ⚡️ Build success in 9021ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 12.38 KB
21
- ESM ⚡️ Build success in 495ms
22
- CJS dist/index.cjs 12.45 KB
23
- CJS ⚡️ Build success in 631ms
20
+ ESM dist/index.js 14.87 KB
21
+ ESM ⚡️ Build success in 712ms
22
+ CJS dist/index.cjs 15.11 KB
23
+ CJS ⚡️ Build success in 712ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @mastra/pinecone
2
2
 
3
+ ## 0.11.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 8a3bfd2: Update peerdeps to latest core
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [792c4c0]
12
+ - Updated dependencies [502fe05]
13
+ - Updated dependencies [4efcfa0]
14
+ - @mastra/core@0.10.7-alpha.3
15
+
16
+ ## 0.10.3-alpha.0
17
+
18
+ ### Patch Changes
19
+
20
+ - 0e17048: Throw mastra errors in storage packages
21
+ - Updated dependencies [d1baedb]
22
+ - Updated dependencies [4d21bf2]
23
+ - Updated dependencies [2097952]
24
+ - Updated dependencies [4fb0cc2]
25
+ - Updated dependencies [d2a7a31]
26
+ - Updated dependencies [0e17048]
27
+ - @mastra/core@0.10.7-alpha.1
28
+
3
29
  ## 0.10.2
4
30
 
5
31
  ### Patch Changes
@@ -1,12 +1,17 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
+ import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
2
3
  import type { CreateIndexParams } from '@mastra/core/vector';
3
4
  import type { DeleteIndexParams } from '@mastra/core/vector';
4
5
  import type { DeleteVectorParams } from '@mastra/core/vector';
5
6
  import type { DescribeIndexParams } from '@mastra/core/vector';
7
+ import type { FilterValue } from '@mastra/core/vector/filter';
6
8
  import type { IndexStats } from '@mastra/core/vector';
7
9
  import type { IndexStatsDescription } from '@pinecone-database/pinecone';
10
+ import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
8
11
  import { MastraVector } from '@mastra/core/vector';
12
+ import type { OperatorCondition } from '@mastra/core/vector/filter';
9
13
  import type { OperatorSupport } from '@mastra/core/vector/filter';
14
+ import type { OperatorValueMap } from '@mastra/core/vector/filter';
10
15
  import type { QueryResult } from '@mastra/core/vector';
11
16
  import type { QueryVectorParams } from '@mastra/core/vector';
12
17
  import type { RecordSparseValues } from '@pinecone-database/pinecone';
@@ -14,6 +19,14 @@ import type { UpdateVectorParams } from '@mastra/core/vector';
14
19
  import type { UpsertVectorParams } from '@mastra/core/vector';
15
20
  import type { VectorFilter } from '@mastra/core/vector/filter';
16
21
 
22
+ declare type InitialOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$elemMatch' | '$all'> & {
23
+ $contains: string;
24
+ $gt: number | Date;
25
+ $gte: number | Date;
26
+ $lt: number | Date;
27
+ $lte: number | Date;
28
+ };
29
+
17
30
  /**
18
31
  * Vector store specific prompt that details supported operators and examples.
19
32
  * This prompt helps users construct valid filters for Pinecone Vector.
@@ -22,13 +35,15 @@ declare const PINECONE_PROMPT = "When querying Pinecone, you can ONLY use the op
22
35
  export { PINECONE_PROMPT }
23
36
  export { PINECONE_PROMPT as PINECONE_PROMPT_alias_1 }
24
37
 
38
+ declare type PineconeBlacklisted = BlacklistedRootOperators | '$not' | '$nor';
39
+
25
40
  declare interface PineconeDeleteVectorParams extends DeleteVectorParams {
26
41
  namespace?: string;
27
42
  }
28
43
 
29
- export declare class PineconeFilterTranslator extends BaseFilterTranslator {
44
+ export declare class PineconeFilterTranslator extends BaseFilterTranslator<PineconeVectorFilter> {
30
45
  protected getSupportedOperators(): OperatorSupport;
31
- translate(filter?: VectorFilter): VectorFilter;
46
+ translate(filter?: PineconeVectorFilter): PineconeVectorFilter;
32
47
  private translateNode;
33
48
  private translateOperator;
34
49
  }
@@ -37,7 +52,13 @@ declare interface PineconeIndexStats extends IndexStats {
37
52
  namespaces?: IndexStatsDescription['namespaces'];
38
53
  }
39
54
 
40
- declare interface PineconeQueryVectorParams extends QueryVectorParams {
55
+ declare type PineconeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$not' | '$nor'>;
56
+
57
+ declare type PineconeOperatorValueMap = InitialOperatorValueMap & {
58
+ $all: OperatorCondition<keyof InitialOperatorValueMap, InitialOperatorValueMap>[] | FilterValue[];
59
+ };
60
+
61
+ declare interface PineconeQueryVectorParams extends QueryVectorParams<PineconeVectorFilter> {
41
62
  namespace?: string;
42
63
  sparseVector?: RecordSparseValues;
43
64
  }
@@ -51,7 +72,7 @@ declare interface PineconeUpsertVectorParams extends UpsertVectorParams {
51
72
  sparseVectors?: RecordSparseValues[];
52
73
  }
53
74
 
54
- declare class PineconeVector extends MastraVector {
75
+ declare class PineconeVector extends MastraVector<PineconeVectorFilter> {
55
76
  private client;
56
77
  /**
57
78
  * Creates a new PineconeVector client.
@@ -65,7 +86,7 @@ declare class PineconeVector extends MastraVector {
65
86
  get indexSeparator(): string;
66
87
  createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
67
88
  upsert({ indexName, vectors, metadata, ids, namespace, sparseVectors, }: PineconeUpsertVectorParams): Promise<string[]>;
68
- transformFilter(filter?: VectorFilter): VectorFilter;
89
+ transformFilter(filter?: PineconeVectorFilter): PineconeVectorFilter;
69
90
  query({ indexName, queryVector, topK, filter, includeVector, namespace, sparseVector, }: PineconeQueryVectorParams): Promise<QueryResult[]>;
70
91
  listIndexes(): Promise<string[]>;
71
92
  /**
@@ -101,4 +122,6 @@ declare class PineconeVector extends MastraVector {
101
122
  export { PineconeVector }
102
123
  export { PineconeVector as PineconeVector_alias_1 }
103
124
 
125
+ export declare type PineconeVectorFilter = VectorFilter<keyof PineconeOperatorValueMap, PineconeOperatorValueMap, PineconeLogicalOperatorValueMap, PineconeBlacklisted>;
126
+
104
127
  export { }
@@ -1,12 +1,17 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
+ import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
2
3
  import type { CreateIndexParams } from '@mastra/core/vector';
3
4
  import type { DeleteIndexParams } from '@mastra/core/vector';
4
5
  import type { DeleteVectorParams } from '@mastra/core/vector';
5
6
  import type { DescribeIndexParams } from '@mastra/core/vector';
7
+ import type { FilterValue } from '@mastra/core/vector/filter';
6
8
  import type { IndexStats } from '@mastra/core/vector';
7
9
  import type { IndexStatsDescription } from '@pinecone-database/pinecone';
10
+ import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
8
11
  import { MastraVector } from '@mastra/core/vector';
12
+ import type { OperatorCondition } from '@mastra/core/vector/filter';
9
13
  import type { OperatorSupport } from '@mastra/core/vector/filter';
14
+ import type { OperatorValueMap } from '@mastra/core/vector/filter';
10
15
  import type { QueryResult } from '@mastra/core/vector';
11
16
  import type { QueryVectorParams } from '@mastra/core/vector';
12
17
  import type { RecordSparseValues } from '@pinecone-database/pinecone';
@@ -14,6 +19,14 @@ import type { UpdateVectorParams } from '@mastra/core/vector';
14
19
  import type { UpsertVectorParams } from '@mastra/core/vector';
15
20
  import type { VectorFilter } from '@mastra/core/vector/filter';
16
21
 
22
+ declare type InitialOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$elemMatch' | '$all'> & {
23
+ $contains: string;
24
+ $gt: number | Date;
25
+ $gte: number | Date;
26
+ $lt: number | Date;
27
+ $lte: number | Date;
28
+ };
29
+
17
30
  /**
18
31
  * Vector store specific prompt that details supported operators and examples.
19
32
  * This prompt helps users construct valid filters for Pinecone Vector.
@@ -22,13 +35,15 @@ declare const PINECONE_PROMPT = "When querying Pinecone, you can ONLY use the op
22
35
  export { PINECONE_PROMPT }
23
36
  export { PINECONE_PROMPT as PINECONE_PROMPT_alias_1 }
24
37
 
38
+ declare type PineconeBlacklisted = BlacklistedRootOperators | '$not' | '$nor';
39
+
25
40
  declare interface PineconeDeleteVectorParams extends DeleteVectorParams {
26
41
  namespace?: string;
27
42
  }
28
43
 
29
- export declare class PineconeFilterTranslator extends BaseFilterTranslator {
44
+ export declare class PineconeFilterTranslator extends BaseFilterTranslator<PineconeVectorFilter> {
30
45
  protected getSupportedOperators(): OperatorSupport;
31
- translate(filter?: VectorFilter): VectorFilter;
46
+ translate(filter?: PineconeVectorFilter): PineconeVectorFilter;
32
47
  private translateNode;
33
48
  private translateOperator;
34
49
  }
@@ -37,7 +52,13 @@ declare interface PineconeIndexStats extends IndexStats {
37
52
  namespaces?: IndexStatsDescription['namespaces'];
38
53
  }
39
54
 
40
- declare interface PineconeQueryVectorParams extends QueryVectorParams {
55
+ declare type PineconeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$not' | '$nor'>;
56
+
57
+ declare type PineconeOperatorValueMap = InitialOperatorValueMap & {
58
+ $all: OperatorCondition<keyof InitialOperatorValueMap, InitialOperatorValueMap>[] | FilterValue[];
59
+ };
60
+
61
+ declare interface PineconeQueryVectorParams extends QueryVectorParams<PineconeVectorFilter> {
41
62
  namespace?: string;
42
63
  sparseVector?: RecordSparseValues;
43
64
  }
@@ -51,7 +72,7 @@ declare interface PineconeUpsertVectorParams extends UpsertVectorParams {
51
72
  sparseVectors?: RecordSparseValues[];
52
73
  }
53
74
 
54
- declare class PineconeVector extends MastraVector {
75
+ declare class PineconeVector extends MastraVector<PineconeVectorFilter> {
55
76
  private client;
56
77
  /**
57
78
  * Creates a new PineconeVector client.
@@ -65,7 +86,7 @@ declare class PineconeVector extends MastraVector {
65
86
  get indexSeparator(): string;
66
87
  createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
67
88
  upsert({ indexName, vectors, metadata, ids, namespace, sparseVectors, }: PineconeUpsertVectorParams): Promise<string[]>;
68
- transformFilter(filter?: VectorFilter): VectorFilter;
89
+ transformFilter(filter?: PineconeVectorFilter): PineconeVectorFilter;
69
90
  query({ indexName, queryVector, topK, filter, includeVector, namespace, sparseVector, }: PineconeQueryVectorParams): Promise<QueryResult[]>;
70
91
  listIndexes(): Promise<string[]>;
71
92
  /**
@@ -101,4 +122,6 @@ declare class PineconeVector extends MastraVector {
101
122
  export { PineconeVector }
102
123
  export { PineconeVector as PineconeVector_alias_1 }
103
124
 
125
+ export declare type PineconeVectorFilter = VectorFilter<keyof PineconeOperatorValueMap, PineconeOperatorValueMap, PineconeLogicalOperatorValueMap, PineconeBlacklisted>;
126
+
104
127
  export { }
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",
3
+ "version": "0.11.0-alpha.1",
4
4
  "description": "Pinecone vector store provider for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,17 +24,17 @@
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
- "eslint": "^9.28.0",
29
+ "eslint": "^9.29.0",
30
30
  "tsup": "^8.5.0",
31
- "typescript": "^5.8.2",
32
- "vitest": "^3.2.2",
33
- "@internal/lint": "0.0.11",
34
- "@mastra/core": "0.10.4"
31
+ "typescript": "^5.8.3",
32
+ "vitest": "^3.2.3",
33
+ "@internal/lint": "0.0.13",
34
+ "@mastra/core": "0.10.7-alpha.3"
35
35
  },
36
36
  "peerDependencies": {
37
- "@mastra/core": ">=0.10.4-0 <0.11.0"
37
+ "@mastra/core": ">=0.10.7-0 <0.11.0-0"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
@@ -1,5 +1,6 @@
1
1
  import { describe, it, expect, beforeEach } from 'vitest';
2
2
 
3
+ import type { PineconeVectorFilter } from './filter';
3
4
  import { PineconeFilterTranslator } from './filter';
4
5
 
5
6
  describe('PineconeFilterTranslator', () => {
@@ -13,17 +14,17 @@ describe('PineconeFilterTranslator', () => {
13
14
  describe('basic operations', () => {
14
15
  it('handles empty filters', () => {
15
16
  expect(translator.translate({})).toEqual({});
16
- expect(translator.translate(null as any)).toEqual(null);
17
- expect(translator.translate(undefined as any)).toEqual(undefined);
17
+ expect(translator.translate(null)).toEqual(null);
18
+ expect(translator.translate(undefined)).toEqual(undefined);
18
19
  });
19
20
 
20
21
  it('allows implicit equality', () => {
21
- const filter = { field: 'value' };
22
+ const filter: PineconeVectorFilter = { field: 'value' };
22
23
  expect(translator.translate(filter)).toEqual({ field: 'value' });
23
24
  });
24
25
 
25
26
  it('allows multiple top-level fields', () => {
26
- const filter = {
27
+ const filter: PineconeVectorFilter = {
27
28
  field1: 'value1',
28
29
  field2: 'value2',
29
30
  };
@@ -34,7 +35,7 @@ describe('PineconeFilterTranslator', () => {
34
35
  });
35
36
 
36
37
  it('handles multiple operators on same field', () => {
37
- const filter = {
38
+ const filter: PineconeVectorFilter = {
38
39
  price: { $gt: 100, $lt: 200 },
39
40
  quantity: { $gte: 10, $lte: 20 },
40
41
  };
@@ -46,12 +47,12 @@ describe('PineconeFilterTranslator', () => {
46
47
 
47
48
  it('normalizes date values', () => {
48
49
  const date = new Date('2024-01-01');
49
- const filter = { timestamp: { $gt: date } };
50
+ const filter: PineconeVectorFilter = { timestamp: { $gt: date } };
50
51
  expect(translator.translate(filter)).toEqual({ timestamp: { $gt: date.toISOString() } });
51
52
  });
52
53
 
53
54
  it('handles $exists operator', () => {
54
- const filter = { field: { $exists: true } };
55
+ const filter: PineconeVectorFilter = { field: { $exists: true } };
55
56
  expect(translator.translate(filter)).toEqual({ field: { $exists: true } });
56
57
  });
57
58
  });
@@ -59,12 +60,12 @@ describe('PineconeFilterTranslator', () => {
59
60
  // Array Operations
60
61
  describe('array operations', () => {
61
62
  it('handles arrays as $in operator', () => {
62
- const filter = { tags: ['tag1', 'tag2'] };
63
+ const filter: PineconeVectorFilter = { tags: ['tag1', 'tag2'] };
63
64
  expect(translator.translate(filter)).toEqual({ tags: { $in: ['tag1', 'tag2'] } });
64
65
  });
65
66
 
66
67
  it('simulates $all using $and + $in', () => {
67
- const filter = { tags: { $all: ['tag1', 'tag2'] } };
68
+ const filter: PineconeVectorFilter = { tags: { $all: ['tag1', 'tag2'] } };
68
69
  expect(translator.translate(filter)).toEqual({
69
70
  $and: [{ tags: { $in: ['tag1'] } }, { tags: { $in: ['tag2'] } }],
70
71
  });
@@ -127,7 +128,7 @@ describe('PineconeFilterTranslator', () => {
127
128
  // Logical Operators
128
129
  describe('logical operators', () => {
129
130
  it('handles logical operators', () => {
130
- const filter = {
131
+ const filter: PineconeVectorFilter = {
131
132
  $or: [{ status: 'active' }, { age: { $gt: 25 } }],
132
133
  };
133
134
  expect(translator.translate(filter)).toEqual({
@@ -136,7 +137,7 @@ describe('PineconeFilterTranslator', () => {
136
137
  });
137
138
 
138
139
  it('handles nested logical operators', () => {
139
- const filter = {
140
+ const filter: PineconeVectorFilter = {
140
141
  $and: [
141
142
  { status: 'active' },
142
143
  {
@@ -170,7 +171,7 @@ describe('PineconeFilterTranslator', () => {
170
171
  });
171
172
 
172
173
  it('handles complex nested conditions', () => {
173
- const filter = {
174
+ const filter: PineconeVectorFilter = {
174
175
  $or: [
175
176
  { age: { $gt: 25 } },
176
177
  {
@@ -205,7 +206,7 @@ describe('PineconeFilterTranslator', () => {
205
206
  });
206
207
 
207
208
  it('preserves empty objects as exact match conditions', () => {
208
- const filter = {
209
+ const filter: PineconeVectorFilter = {
209
210
  metadata: {},
210
211
  'user.profile': {},
211
212
  };
@@ -217,7 +218,7 @@ describe('PineconeFilterTranslator', () => {
217
218
  });
218
219
 
219
220
  it('handles empty objects in logical operators', () => {
220
- const filter = {
221
+ const filter: PineconeVectorFilter = {
221
222
  $or: [{}, { status: 'active' }],
222
223
  };
223
224
 
@@ -241,7 +242,7 @@ describe('PineconeFilterTranslator', () => {
241
242
  });
242
243
 
243
244
  it('handles empty objects in comparison operators', () => {
244
- const filter = {
245
+ const filter: PineconeVectorFilter = {
245
246
  metadata: { $eq: {} },
246
247
  };
247
248
 
@@ -251,7 +252,7 @@ describe('PineconeFilterTranslator', () => {
251
252
  });
252
253
 
253
254
  it('handles empty objects in array operators', () => {
254
- const filter = {
255
+ const filter: PineconeVectorFilter = {
255
256
  tags: { $in: [{}] },
256
257
  };
257
258
 
@@ -367,7 +368,7 @@ describe('PineconeFilterTranslator', () => {
367
368
  });
368
369
 
369
370
  it('throws error for unsupported logical operators', () => {
370
- const invalidFilters = [
371
+ const invalidFilters: any = [
371
372
  {
372
373
  $not: { field: 'value' },
373
374
  },
@@ -389,13 +390,13 @@ describe('PineconeFilterTranslator', () => {
389
390
  });
390
391
 
391
392
  it('ensure all operator filters are supported', () => {
392
- const supportedFilters = [
393
+ const supportedFilters: PineconeVectorFilter[] = [
393
394
  { field: { $eq: 'value' } },
394
395
  { field: { $ne: 'value' } },
395
- { field: { $gt: 'value' } },
396
- { field: { $gte: 'value' } },
397
- { field: { $lt: 'value' } },
398
- { field: { $lte: 'value' } },
396
+ { field: { $gt: 10 } },
397
+ { field: { $gte: 10 } },
398
+ { field: { $lt: 10 } },
399
+ { field: { $lte: 10 } },
399
400
  { field: { $in: ['value'] } },
400
401
  { $and: [{ field: { $eq: 'value' } }] },
401
402
  { $or: [{ field: { $eq: 'value' } }] },
@@ -431,7 +432,7 @@ describe('PineconeFilterTranslator', () => {
431
432
  });
432
433
 
433
434
  it('throws error for invalid operator values', () => {
434
- const filter = { tags: { $all: 'not-an-array' } };
435
+ const filter: any = { tags: { $all: 'not-an-array' } };
435
436
  expect(() => translator.translate(filter)).toThrow();
436
437
  });
437
438
  it('throws error for regex operators', () => {
@@ -439,7 +440,7 @@ describe('PineconeFilterTranslator', () => {
439
440
  expect(() => translator.translate(filter)).toThrow();
440
441
  });
441
442
  it('throws error for non-logical operators at top level', () => {
442
- const invalidFilters = [{ $gt: 100 }, { $in: ['value1', 'value2'] }, { $eq: true }];
443
+ const invalidFilters: any = [{ $gt: 100 }, { $in: ['value1', 'value2'] }, { $eq: true }];
443
444
 
444
445
  invalidFilters.forEach(filter => {
445
446
  expect(() => translator.translate(filter)).toThrow(/Invalid top-level operator/);
@@ -1,7 +1,38 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
- import type { FieldCondition, VectorFilter, OperatorSupport, QueryOperator } from '@mastra/core/vector/filter';
2
+ import type {
3
+ VectorFilter,
4
+ OperatorSupport,
5
+ OperatorValueMap,
6
+ LogicalOperatorValueMap,
7
+ BlacklistedRootOperators,
8
+ QueryOperator,
9
+ FilterValue,
10
+ OperatorCondition,
11
+ } from '@mastra/core/vector/filter';
3
12
 
4
- export class PineconeFilterTranslator extends BaseFilterTranslator {
13
+ type InitialOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$elemMatch' | '$all'> & {
14
+ $contains: string;
15
+ $gt: number | Date;
16
+ $gte: number | Date;
17
+ $lt: number | Date;
18
+ $lte: number | Date;
19
+ };
20
+
21
+ type PineconeOperatorValueMap = InitialOperatorValueMap & {
22
+ $all: OperatorCondition<keyof InitialOperatorValueMap, InitialOperatorValueMap>[] | FilterValue[];
23
+ };
24
+ type PineconeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$not' | '$nor'>;
25
+
26
+ type PineconeBlacklisted = BlacklistedRootOperators | '$not' | '$nor';
27
+
28
+ export type PineconeVectorFilter = VectorFilter<
29
+ keyof PineconeOperatorValueMap,
30
+ PineconeOperatorValueMap,
31
+ PineconeLogicalOperatorValueMap,
32
+ PineconeBlacklisted
33
+ >;
34
+
35
+ export class PineconeFilterTranslator extends BaseFilterTranslator<PineconeVectorFilter> {
5
36
  protected override getSupportedOperators(): OperatorSupport {
6
37
  return {
7
38
  ...BaseFilterTranslator.DEFAULT_OPERATORS,
@@ -13,13 +44,13 @@ export class PineconeFilterTranslator extends BaseFilterTranslator {
13
44
  };
14
45
  }
15
46
 
16
- translate(filter?: VectorFilter): VectorFilter {
47
+ translate(filter?: PineconeVectorFilter): PineconeVectorFilter {
17
48
  if (this.isEmpty(filter)) return filter;
18
49
  this.validateFilter(filter);
19
50
  return this.translateNode(filter);
20
51
  }
21
52
 
22
- private translateNode(node: VectorFilter | FieldCondition, currentPath: string = ''): any {
53
+ private translateNode(node: PineconeVectorFilter, currentPath: string = ''): any {
23
54
  if (this.isRegex(node)) {
24
55
  throw new Error('Regex is not supported in Pinecone');
25
56
  }
@@ -728,7 +728,11 @@ describe.skip('PineconeVector Integration Tests', () => {
728
728
  vectorDB.query({
729
729
  indexName: testIndexName,
730
730
  queryVector: [1, 0, 0],
731
- filter: { field1: { $in: 'not-array' }, field2: { $exists: 'not-boolean' }, field3: { $gt: 'not-number' } },
731
+ filter: {
732
+ field1: { $in: 'not-array' },
733
+ field2: { $exists: 'not-boolean' },
734
+ field3: { $gt: 'not-number' },
735
+ } as any,
732
736
  }),
733
737
  ).rejects.toThrow();
734
738
  });
@@ -754,7 +758,7 @@ describe.skip('PineconeVector Integration Tests', () => {
754
758
  vectorDB.query({
755
759
  indexName: testIndexName,
756
760
  queryVector: [1, 0, 0],
757
- filter: { field: { $all: 'not-an-array' } },
761
+ filter: { field: { $all: 'not-an-array' } } as any,
758
762
  }),
759
763
  ).rejects.toThrow('A non-empty array is required for the $all operator');
760
764
  });
@@ -1164,7 +1168,7 @@ describe.skip('PineconeVector Integration Tests', () => {
1164
1168
  vectorDB.query({
1165
1169
  indexName: testIndexName,
1166
1170
  queryVector: [1, 0, 0],
1167
- filter: { price: { $gt: '500' } }, // string instead of number
1171
+ filter: { price: { $gt: '500' } } as any, // string instead of number
1168
1172
  }),
1169
1173
  ).rejects.toThrow('the $gt operator must be followed by a number');
1170
1174
  });
@@ -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,
@@ -10,7 +11,6 @@ import type {
10
11
  DeleteVectorParams,
11
12
  UpdateVectorParams,
12
13
  } from '@mastra/core/vector';
13
- import type { VectorFilter } from '@mastra/core/vector/filter';
14
14
  import { Pinecone } from '@pinecone-database/pinecone';
15
15
  import type {
16
16
  IndexStatsDescription,
@@ -20,12 +20,13 @@ import type {
20
20
  } from '@pinecone-database/pinecone';
21
21
 
22
22
  import { PineconeFilterTranslator } from './filter';
23
+ import type { PineconeVectorFilter } from './filter';
23
24
 
24
25
  interface PineconeIndexStats extends IndexStats {
25
26
  namespaces?: IndexStatsDescription['namespaces'];
26
27
  }
27
28
 
28
- interface PineconeQueryVectorParams extends QueryVectorParams {
29
+ interface PineconeQueryVectorParams extends QueryVectorParams<PineconeVectorFilter> {
29
30
  namespace?: string;
30
31
  sparseVector?: RecordSparseValues;
31
32
  }
@@ -43,7 +44,7 @@ interface PineconeDeleteVectorParams extends DeleteVectorParams {
43
44
  namespace?: string;
44
45
  }
45
46
 
46
- export class PineconeVector extends MastraVector {
47
+ export class PineconeVector extends MastraVector<PineconeVectorFilter> {
47
48
  private client: Pinecone;
48
49
 
49
50
  /**
@@ -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,15 +152,27 @@ 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
- transformFilter(filter?: VectorFilter) {
175
+ transformFilter(filter?: PineconeVectorFilter) {
142
176
  const translator = new PineconeFilterTranslator();
143
177
  return translator.translate(filter);
144
178
  }
@@ -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
  }