@mastra/pinecone 0.2.11 → 0.2.12-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.2.11-alpha.6 build /home/runner/work/mastra/mastra/stores/pinecone
2
+ > @mastra/pinecone@0.2.12-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.4.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 6549ms
9
+ TSC ⚡️ Build success in 6837ms
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 9935ms
16
+ DTS ⚡️ Build success in 8906ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- CJS dist/index.cjs 10.41 KB
21
- CJS ⚡️ Build success in 636ms
22
- ESM dist/index.js 10.35 KB
23
- ESM ⚡️ Build success in 859ms
20
+ CJS dist/index.cjs 11.02 KB
21
+ CJS ⚡️ Build success in 655ms
22
+ ESM dist/index.js 10.96 KB
23
+ ESM ⚡️ Build success in 655ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @mastra/pinecone
2
2
 
3
+ ## 0.2.12-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 9cd1a46: [MASTRA-3338] update naming scheme for embedding index based on vector store rules and added duplicate index checks
8
+ - Updated dependencies [e450778]
9
+ - Updated dependencies [8902157]
10
+ - Updated dependencies [ca0dc88]
11
+ - Updated dependencies [9cd1a46]
12
+ - Updated dependencies [70dbf51]
13
+ - @mastra/core@0.9.3-alpha.1
14
+
15
+ ## 0.2.12-alpha.0
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [526c570]
20
+ - Updated dependencies [b5d2de0]
21
+ - Updated dependencies [644f8ad]
22
+ - @mastra/core@0.9.3-alpha.0
23
+
3
24
  ## 0.2.11
4
25
 
5
26
  ### Patch Changes
@@ -49,6 +49,7 @@ declare interface PineconeUpsertVectorParams extends UpsertVectorParams {
49
49
  declare class PineconeVector extends MastraVector {
50
50
  private client;
51
51
  constructor(apiKey: string, environment?: string);
52
+ get indexSeparator(): string;
52
53
  createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void>;
53
54
  upsert(...args: ParamsToArgs<PineconeUpsertVectorParams> | PineconeUpsertVectorArgs): Promise<string[]>;
54
55
  transformFilter(filter?: VectorFilter): VectorFilter;
@@ -49,6 +49,7 @@ declare interface PineconeUpsertVectorParams extends UpsertVectorParams {
49
49
  declare class PineconeVector extends MastraVector {
50
50
  private client;
51
51
  constructor(apiKey: string, environment?: string);
52
+ get indexSeparator(): string;
52
53
  createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void>;
53
54
  upsert(...args: ParamsToArgs<PineconeUpsertVectorParams> | PineconeUpsertVectorArgs): Promise<string[]>;
54
55
  transformFilter(filter?: VectorFilter): VectorFilter;
package/dist/index.cjs CHANGED
@@ -100,23 +100,38 @@ var PineconeVector = class extends vector.MastraVector {
100
100
  }
101
101
  }) ?? baseClient;
102
102
  }
103
+ get indexSeparator() {
104
+ return "-";
105
+ }
103
106
  async createIndex(...args) {
104
107
  const params = this.normalizeArgs("createIndex", args);
105
108
  const { indexName, dimension, metric = "cosine" } = params;
106
109
  if (!Number.isInteger(dimension) || dimension <= 0) {
107
110
  throw new Error("Dimension must be a positive integer");
108
111
  }
109
- await this.client.createIndex({
110
- name: indexName,
111
- dimension,
112
- metric,
113
- spec: {
114
- serverless: {
115
- cloud: "aws",
116
- region: "us-east-1"
112
+ if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
113
+ throw new Error("Metric must be one of: cosine, euclidean, dotproduct");
114
+ }
115
+ try {
116
+ await this.client.createIndex({
117
+ name: indexName,
118
+ dimension,
119
+ metric,
120
+ spec: {
121
+ serverless: {
122
+ cloud: "aws",
123
+ region: "us-east-1"
124
+ }
117
125
  }
126
+ });
127
+ } catch (error) {
128
+ const message = error?.errors?.[0]?.message || error?.message;
129
+ if (error.status === 409 || typeof message === "string" && (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("duplicate"))) {
130
+ await this.validateExistingIndex(indexName, dimension, metric);
131
+ return;
118
132
  }
119
- });
133
+ throw error;
134
+ }
120
135
  }
121
136
  async upsert(...args) {
122
137
  const params = this.normalizeArgs("upsert", args, [
package/dist/index.js CHANGED
@@ -98,23 +98,38 @@ var PineconeVector = class extends MastraVector {
98
98
  }
99
99
  }) ?? baseClient;
100
100
  }
101
+ get indexSeparator() {
102
+ return "-";
103
+ }
101
104
  async createIndex(...args) {
102
105
  const params = this.normalizeArgs("createIndex", args);
103
106
  const { indexName, dimension, metric = "cosine" } = params;
104
107
  if (!Number.isInteger(dimension) || dimension <= 0) {
105
108
  throw new Error("Dimension must be a positive integer");
106
109
  }
107
- await this.client.createIndex({
108
- name: indexName,
109
- dimension,
110
- metric,
111
- spec: {
112
- serverless: {
113
- cloud: "aws",
114
- region: "us-east-1"
110
+ if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
111
+ throw new Error("Metric must be one of: cosine, euclidean, dotproduct");
112
+ }
113
+ try {
114
+ await this.client.createIndex({
115
+ name: indexName,
116
+ dimension,
117
+ metric,
118
+ spec: {
119
+ serverless: {
120
+ cloud: "aws",
121
+ region: "us-east-1"
122
+ }
115
123
  }
124
+ });
125
+ } catch (error) {
126
+ const message = error?.errors?.[0]?.message || error?.message;
127
+ if (error.status === 409 || typeof message === "string" && (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("duplicate"))) {
128
+ await this.validateExistingIndex(indexName, dimension, metric);
129
+ return;
116
130
  }
117
- });
131
+ throw error;
132
+ }
118
133
  }
119
134
  async upsert(...args) {
120
135
  const params = this.normalizeArgs("upsert", args, [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/pinecone",
3
- "version": "0.2.11",
3
+ "version": "0.2.12-alpha.1",
4
4
  "description": "Pinecone vector store provider for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,7 +21,7 @@
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
23
  "@pinecone-database/pinecone": "^3.0.3",
24
- "@mastra/core": "^0.9.2"
24
+ "@mastra/core": "^0.9.3-alpha.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@microsoft/api-extractor": "^7.52.5",
@@ -555,6 +555,14 @@ describe.skip('PineconeVector Integration Tests', () => {
555
555
  });
556
556
 
557
557
  describe('Error Handling', () => {
558
+ const testIndexName = 'test-index-error';
559
+ beforeAll(async () => {
560
+ await vectorDB.createIndex({ indexName: testIndexName, dimension: 3 });
561
+ });
562
+
563
+ afterAll(async () => {
564
+ await vectorDB.deleteIndex(testIndexName);
565
+ });
558
566
  it('should handle non-existent index query gracefully', async () => {
559
567
  const nonExistentIndex = 'non-existent-index';
560
568
  await expect(vectorDB.query({ indexName: nonExistentIndex, queryVector: [1, 0, 0] })).rejects.toThrow();
@@ -564,6 +572,60 @@ describe.skip('PineconeVector Integration Tests', () => {
564
572
  const wrongDimVector = [[1, 0]]; // 2D vector for 3D index
565
573
  await expect(vectorDB.upsert({ indexName: testIndexName, vectors: wrongDimVector })).rejects.toThrow();
566
574
  }, 500000);
575
+
576
+ it('should handle duplicate index creation gracefully', async () => {
577
+ const duplicateIndexName = `duplicate-test`;
578
+ const dimension = 768;
579
+ const infoSpy = vi.spyOn(vectorDB['logger'], 'info');
580
+ const warnSpy = vi.spyOn(vectorDB['logger'], 'warn');
581
+
582
+ try {
583
+ // Create index first time
584
+ await vectorDB.createIndex({
585
+ indexName: duplicateIndexName,
586
+ dimension,
587
+ metric: 'cosine',
588
+ });
589
+
590
+ // Try to create with same dimensions - should not throw
591
+ await expect(
592
+ vectorDB.createIndex({
593
+ indexName: duplicateIndexName,
594
+ dimension,
595
+ metric: 'cosine',
596
+ }),
597
+ ).resolves.not.toThrow();
598
+
599
+ expect(infoSpy).toHaveBeenCalledWith(expect.stringContaining('already exists with'));
600
+
601
+ // Try to create with same dimensions and different metric - should not throw
602
+ await expect(
603
+ vectorDB.createIndex({
604
+ indexName: duplicateIndexName,
605
+ dimension,
606
+ metric: 'euclidean',
607
+ }),
608
+ ).resolves.not.toThrow();
609
+
610
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Attempted to create index with metric'));
611
+
612
+ // Try to create with different dimensions - should throw
613
+ await expect(
614
+ vectorDB.createIndex({
615
+ indexName: duplicateIndexName,
616
+ dimension: dimension + 1,
617
+ metric: 'cosine',
618
+ }),
619
+ ).rejects.toThrow(
620
+ `Index "${duplicateIndexName}" already exists with ${dimension} dimensions, but ${dimension + 1} dimensions were requested`,
621
+ );
622
+ } finally {
623
+ infoSpy.mockRestore();
624
+ warnSpy.mockRestore();
625
+ // Cleanup
626
+ await vectorDB.deleteIndex(duplicateIndexName);
627
+ }
628
+ });
567
629
  });
568
630
 
569
631
  describe('Performance Tests', () => {
@@ -61,6 +61,10 @@ export class PineconeVector extends MastraVector {
61
61
  }) ?? baseClient;
62
62
  }
63
63
 
64
+ get indexSeparator(): string {
65
+ return '-';
66
+ }
67
+
64
68
  async createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void> {
65
69
  const params = this.normalizeArgs<CreateIndexParams>('createIndex', args);
66
70
 
@@ -69,17 +73,36 @@ export class PineconeVector extends MastraVector {
69
73
  if (!Number.isInteger(dimension) || dimension <= 0) {
70
74
  throw new Error('Dimension must be a positive integer');
71
75
  }
72
- await this.client.createIndex({
73
- name: indexName,
74
- dimension: dimension,
75
- metric: metric,
76
- spec: {
77
- serverless: {
78
- cloud: 'aws',
79
- region: 'us-east-1',
76
+ if (metric && !['cosine', 'euclidean', 'dotproduct'].includes(metric)) {
77
+ throw new Error('Metric must be one of: cosine, euclidean, dotproduct');
78
+ }
79
+ try {
80
+ await this.client.createIndex({
81
+ name: indexName,
82
+ dimension: dimension,
83
+ metric: metric,
84
+ spec: {
85
+ serverless: {
86
+ cloud: 'aws',
87
+ region: 'us-east-1',
88
+ },
80
89
  },
81
- },
82
- });
90
+ });
91
+ } catch (error: any) {
92
+ // Check for 'already exists' error
93
+ const message = error?.errors?.[0]?.message || error?.message;
94
+ if (
95
+ error.status === 409 ||
96
+ (typeof message === 'string' &&
97
+ (message.toLowerCase().includes('already exists') || message.toLowerCase().includes('duplicate')))
98
+ ) {
99
+ // Fetch index info and check dimensions
100
+ await this.validateExistingIndex(indexName, dimension, metric);
101
+ return;
102
+ }
103
+ // For any other errors, propagate
104
+ throw error;
105
+ }
83
106
  }
84
107
 
85
108
  async upsert(...args: ParamsToArgs<PineconeUpsertVectorParams> | PineconeUpsertVectorArgs): Promise<string[]> {