@mastra/pinecone 0.1.10-alpha.0 → 0.2.0-alpha.2
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +25 -0
- package/dist/_tsup-dts-rollup.d.cts +5 -0
- package/dist/_tsup-dts-rollup.d.ts +5 -0
- package/dist/index.cjs +18 -0
- package/dist/index.js +18 -0
- package/package.json +2 -2
- package/src/vector/index.test.ts +148 -0
- package/src/vector/index.ts +33 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pinecone@0.
|
|
2
|
+
> @mastra/pinecone@0.2.0-alpha.2 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
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 6455ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.7.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pinecone/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.7.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pinecone/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 8676ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m6.64 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 464ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m6.61 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 465ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @mastra/pinecone
|
|
2
2
|
|
|
3
|
+
## 0.2.0-alpha.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [fc2f89c]
|
|
8
|
+
- Updated dependencies [dfbb131]
|
|
9
|
+
- Updated dependencies [0850b4c]
|
|
10
|
+
- Updated dependencies [9116d70]
|
|
11
|
+
- @mastra/core@0.6.1-alpha.2
|
|
12
|
+
|
|
13
|
+
## 0.2.0-alpha.1
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- 2ee56ad: Added new operation implementations for MastraVector in pinecone store
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [f4854ee]
|
|
22
|
+
- Updated dependencies [afaf73f]
|
|
23
|
+
- Updated dependencies [44631b1]
|
|
24
|
+
- Updated dependencies [6e559a0]
|
|
25
|
+
- Updated dependencies [5f43505]
|
|
26
|
+
- @mastra/core@0.6.1-alpha.1
|
|
27
|
+
|
|
3
28
|
## 0.1.10-alpha.0
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -26,6 +26,11 @@ declare class PineconeVector extends MastraVector {
|
|
|
26
26
|
listIndexes(): Promise<string[]>;
|
|
27
27
|
describeIndex(indexName: string): Promise<IndexStats>;
|
|
28
28
|
deleteIndex(indexName: string): Promise<void>;
|
|
29
|
+
updateIndexById(indexName: string, id: string, update: {
|
|
30
|
+
vector?: number[];
|
|
31
|
+
metadata?: Record<string, any>;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
29
34
|
}
|
|
30
35
|
export { PineconeVector }
|
|
31
36
|
export { PineconeVector as PineconeVector_alias_1 }
|
|
@@ -26,6 +26,11 @@ declare class PineconeVector extends MastraVector {
|
|
|
26
26
|
listIndexes(): Promise<string[]>;
|
|
27
27
|
describeIndex(indexName: string): Promise<IndexStats>;
|
|
28
28
|
deleteIndex(indexName: string): Promise<void>;
|
|
29
|
+
updateIndexById(indexName: string, id: string, update: {
|
|
30
|
+
vector?: number[];
|
|
31
|
+
metadata?: Record<string, any>;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
29
34
|
}
|
|
30
35
|
export { PineconeVector }
|
|
31
36
|
export { PineconeVector as PineconeVector_alias_1 }
|
package/dist/index.cjs
CHANGED
|
@@ -179,6 +179,24 @@ var PineconeVector = class extends vector.MastraVector {
|
|
|
179
179
|
throw new Error(`Failed to delete Pinecone index: ${error.message}`);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
+
async updateIndexById(indexName, id, update) {
|
|
183
|
+
if (!update.vector && !update.metadata) {
|
|
184
|
+
throw new Error("No updates provided");
|
|
185
|
+
}
|
|
186
|
+
const index = this.client.Index(indexName);
|
|
187
|
+
const updateObj = { id };
|
|
188
|
+
if (update.vector) {
|
|
189
|
+
updateObj.values = update.vector;
|
|
190
|
+
}
|
|
191
|
+
if (update.metadata) {
|
|
192
|
+
updateObj.metadata = update.metadata;
|
|
193
|
+
}
|
|
194
|
+
await index.update(updateObj);
|
|
195
|
+
}
|
|
196
|
+
async deleteIndexById(indexName, id) {
|
|
197
|
+
const index = this.client.Index(indexName);
|
|
198
|
+
await index.deleteOne(id);
|
|
199
|
+
}
|
|
182
200
|
};
|
|
183
201
|
|
|
184
202
|
exports.PineconeVector = PineconeVector;
|
package/dist/index.js
CHANGED
|
@@ -177,6 +177,24 @@ var PineconeVector = class extends MastraVector {
|
|
|
177
177
|
throw new Error(`Failed to delete Pinecone index: ${error.message}`);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
+
async updateIndexById(indexName, id, update) {
|
|
181
|
+
if (!update.vector && !update.metadata) {
|
|
182
|
+
throw new Error("No updates provided");
|
|
183
|
+
}
|
|
184
|
+
const index = this.client.Index(indexName);
|
|
185
|
+
const updateObj = { id };
|
|
186
|
+
if (update.vector) {
|
|
187
|
+
updateObj.values = update.vector;
|
|
188
|
+
}
|
|
189
|
+
if (update.metadata) {
|
|
190
|
+
updateObj.metadata = update.metadata;
|
|
191
|
+
}
|
|
192
|
+
await index.update(updateObj);
|
|
193
|
+
}
|
|
194
|
+
async deleteIndexById(indexName, id) {
|
|
195
|
+
const index = this.client.Index(indexName);
|
|
196
|
+
await index.deleteOne(id);
|
|
197
|
+
}
|
|
180
198
|
};
|
|
181
199
|
|
|
182
200
|
export { PineconeVector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pinecone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-alpha.2",
|
|
4
4
|
"description": "Pinecone vector store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@pinecone-database/pinecone": "^3.0.3",
|
|
23
|
-
"@mastra/core": "^0.6.1-alpha.
|
|
23
|
+
"@mastra/core": "^0.6.1-alpha.2"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@microsoft/api-extractor": "^7.52.1",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -2,6 +2,7 @@ import dotenv from 'dotenv';
|
|
|
2
2
|
import { describe, it, expect, beforeAll, afterAll, beforeEach, vi, afterEach } from 'vitest';
|
|
3
3
|
|
|
4
4
|
import { PineconeVector } from './';
|
|
5
|
+
import type { QueryResult } from '@mastra/core/vector';
|
|
5
6
|
|
|
6
7
|
dotenv.config();
|
|
7
8
|
|
|
@@ -125,6 +126,153 @@ describe.skip('PineconeVector Integration Tests', () => {
|
|
|
125
126
|
expect(results?.[0]?.vector).toBeDefined();
|
|
126
127
|
expect(results?.[0]?.vector).toHaveLength(dimension);
|
|
127
128
|
}, 500000);
|
|
129
|
+
|
|
130
|
+
describe('vector update operations', () => {
|
|
131
|
+
const testVectors = [
|
|
132
|
+
[1, 2, 3],
|
|
133
|
+
[4, 5, 6],
|
|
134
|
+
[7, 8, 9],
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
it('should update the vector by id', async () => {
|
|
138
|
+
const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
|
|
139
|
+
expect(ids).toHaveLength(3);
|
|
140
|
+
|
|
141
|
+
const idToBeUpdated = ids[0];
|
|
142
|
+
const newVector = [1, 2, 4];
|
|
143
|
+
const newMetaData = {
|
|
144
|
+
test: 'updates',
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const update = {
|
|
148
|
+
vector: newVector,
|
|
149
|
+
metadata: newMetaData,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
|
|
153
|
+
|
|
154
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
155
|
+
|
|
156
|
+
const results: QueryResult[] = await vectorDB.query({
|
|
157
|
+
indexName: testIndexName,
|
|
158
|
+
queryVector: newVector,
|
|
159
|
+
topK: 10,
|
|
160
|
+
includeVector: true,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
expect(results[0]?.id).toBe(idToBeUpdated);
|
|
164
|
+
expect(results[0]?.vector).toEqual(newVector);
|
|
165
|
+
expect(results[0]?.metadata).toEqual(newMetaData);
|
|
166
|
+
}, 500000);
|
|
167
|
+
|
|
168
|
+
it('should only update the metadata by id', async () => {
|
|
169
|
+
const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
|
|
170
|
+
expect(ids).toHaveLength(3);
|
|
171
|
+
|
|
172
|
+
const idToBeUpdated = ids[0];
|
|
173
|
+
const newMetaData = {
|
|
174
|
+
test: 'updates',
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const update = {
|
|
178
|
+
metadata: newMetaData,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
|
|
182
|
+
|
|
183
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
184
|
+
|
|
185
|
+
const results: QueryResult[] = await vectorDB.query({
|
|
186
|
+
indexName: testIndexName,
|
|
187
|
+
queryVector: testVectors[0],
|
|
188
|
+
topK: 2,
|
|
189
|
+
includeVector: true,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(results[0]?.id).toBe(idToBeUpdated);
|
|
193
|
+
expect(results[0]?.vector).toEqual(testVectors[0]);
|
|
194
|
+
expect(results[0]?.metadata).toEqual(newMetaData);
|
|
195
|
+
}, 500000);
|
|
196
|
+
|
|
197
|
+
it('should only update vector embeddings by id', async () => {
|
|
198
|
+
const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
|
|
199
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
200
|
+
|
|
201
|
+
expect(ids).toHaveLength(3);
|
|
202
|
+
|
|
203
|
+
const idToBeUpdated = ids[0];
|
|
204
|
+
const newVector = [1, 2, 3];
|
|
205
|
+
|
|
206
|
+
const update = {
|
|
207
|
+
vector: newVector,
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
|
|
211
|
+
|
|
212
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
213
|
+
|
|
214
|
+
const results: QueryResult[] = await vectorDB.query({
|
|
215
|
+
indexName: testIndexName,
|
|
216
|
+
queryVector: newVector,
|
|
217
|
+
topK: 10,
|
|
218
|
+
includeVector: true,
|
|
219
|
+
filter: { ids: [idToBeUpdated] },
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const resultIds = results.map(res => res.id);
|
|
223
|
+
const resultVectors = results.map(res => res.vector);
|
|
224
|
+
expect(resultIds).toContain(idToBeUpdated);
|
|
225
|
+
expect(resultVectors).toContain(newVector);
|
|
226
|
+
}, 500000);
|
|
227
|
+
|
|
228
|
+
it('should throw exception when no updates are given', () => {
|
|
229
|
+
expect(vectorDB.updateIndexById(testIndexName, 'id', {})).rejects.toThrow('No updates provided');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('should throw error for non-existent index', async () => {
|
|
233
|
+
const nonExistentIndex = 'non-existent-index';
|
|
234
|
+
await expect(vectorDB.updateIndexById(nonExistentIndex, 'test-id', { vector: [1, 2, 3] })).rejects.toThrow();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('should throw error for invalid vector dimension', async () => {
|
|
238
|
+
const [id] = await vectorDB.upsert({
|
|
239
|
+
indexName: testIndexName,
|
|
240
|
+
vectors: [[1, 2, 3]],
|
|
241
|
+
metadata: [{ test: 'initial' }],
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
await expect(
|
|
245
|
+
vectorDB.updateIndexById(testIndexName, id, { vector: [1, 2] }), // Wrong dimension
|
|
246
|
+
).rejects.toThrow();
|
|
247
|
+
}, 500000);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe('vector delete operations', () => {
|
|
251
|
+
const testVectors = [
|
|
252
|
+
[1, 2, 3],
|
|
253
|
+
[4, 5, 6],
|
|
254
|
+
[7, 8, 9],
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
it('should delete the vector by id', async () => {
|
|
258
|
+
const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
|
|
259
|
+
expect(ids).toHaveLength(3);
|
|
260
|
+
const idToBeDeleted = ids[0];
|
|
261
|
+
|
|
262
|
+
await vectorDB.deleteIndexById(testIndexName, idToBeDeleted);
|
|
263
|
+
|
|
264
|
+
// Query all vectors similar to the deleted one
|
|
265
|
+
const results: QueryResult[] = await vectorDB.query({
|
|
266
|
+
indexName: testIndexName,
|
|
267
|
+
queryVector: testVectors[0],
|
|
268
|
+
topK: 3,
|
|
269
|
+
includeVector: true,
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
const resultIds = results.map(r => r.id);
|
|
273
|
+
expect(resultIds).not.toContain(idToBeDeleted);
|
|
274
|
+
}, 500000);
|
|
275
|
+
});
|
|
128
276
|
});
|
|
129
277
|
|
|
130
278
|
describe('Error Handling', () => {
|
package/src/vector/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
} from '@mastra/core/vector';
|
|
10
10
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
11
11
|
import { Pinecone } from '@pinecone-database/pinecone';
|
|
12
|
+
import type { UpdateOptions } from '@pinecone-database/pinecone';
|
|
12
13
|
|
|
13
14
|
import { PineconeFilterTranslator } from './filter';
|
|
14
15
|
|
|
@@ -136,4 +137,36 @@ export class PineconeVector extends MastraVector {
|
|
|
136
137
|
throw new Error(`Failed to delete Pinecone index: ${error.message}`);
|
|
137
138
|
}
|
|
138
139
|
}
|
|
140
|
+
|
|
141
|
+
async updateIndexById(
|
|
142
|
+
indexName: string,
|
|
143
|
+
id: string,
|
|
144
|
+
update: {
|
|
145
|
+
vector?: number[];
|
|
146
|
+
metadata?: Record<string, any>;
|
|
147
|
+
},
|
|
148
|
+
): Promise<void> {
|
|
149
|
+
if (!update.vector && !update.metadata) {
|
|
150
|
+
throw new Error('No updates provided');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const index = this.client.Index(indexName);
|
|
154
|
+
|
|
155
|
+
const updateObj: UpdateOptions = { id };
|
|
156
|
+
|
|
157
|
+
if (update.vector) {
|
|
158
|
+
updateObj.values = update.vector;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (update.metadata) {
|
|
162
|
+
updateObj.metadata = update.metadata;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
await index.update(updateObj);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async deleteIndexById(indexName: string, id: string): Promise<void> {
|
|
169
|
+
const index = this.client.Index(indexName);
|
|
170
|
+
await index.deleteOne(id);
|
|
171
|
+
}
|
|
139
172
|
}
|