@mastra/chroma 0.2.15-alpha.1 → 0.2.15-alpha.3
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 +20 -0
- package/dist/_tsup-dts-rollup.d.cts +43 -0
- package/dist/_tsup-dts-rollup.d.ts +43 -0
- package/dist/index.cjs +70 -12
- package/dist/index.js +70 -12
- package/package.json +2 -2
- package/src/vector/index.test.ts +5 -5
- package/src/vector/index.ts +77 -13
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/chroma@0.2.15-alpha.
|
|
2
|
+
> @mastra/chroma@0.2.15-alpha.3 build /home/runner/work/mastra/mastra/stores/chroma
|
|
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 9802ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/chroma/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/chroma/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 9633ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m13.93 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 630ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m13.98 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 636ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/chroma
|
|
2
2
|
|
|
3
|
+
## 0.2.15-alpha.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
|
|
8
|
+
- Updated dependencies [396be50]
|
|
9
|
+
- Updated dependencies [c3bd795]
|
|
10
|
+
- Updated dependencies [da082f8]
|
|
11
|
+
- Updated dependencies [a5810ce]
|
|
12
|
+
- @mastra/core@0.9.4-alpha.3
|
|
13
|
+
|
|
14
|
+
## 0.2.15-alpha.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [3171b5b]
|
|
19
|
+
- Updated dependencies [973e5ac]
|
|
20
|
+
- Updated dependencies [9e1eff5]
|
|
21
|
+
- @mastra/core@0.9.4-alpha.2
|
|
22
|
+
|
|
3
23
|
## 0.2.15-alpha.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -63,11 +63,54 @@ declare class ChromaVector extends MastraVector {
|
|
|
63
63
|
listIndexes(): Promise<string[]>;
|
|
64
64
|
describeIndex(indexName: string): Promise<IndexStats>;
|
|
65
65
|
deleteIndex(indexName: string): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
68
|
+
*
|
|
69
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
70
|
+
* @param indexName - The name of the index containing the vector.
|
|
71
|
+
* @param id - The ID of the vector to update.
|
|
72
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
73
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
74
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
75
|
+
* @returns A promise that resolves when the update is complete.
|
|
76
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
77
|
+
*/
|
|
66
78
|
updateIndexById(indexName: string, id: string, update: {
|
|
67
79
|
vector?: number[];
|
|
68
80
|
metadata?: Record<string, any>;
|
|
69
81
|
}): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
84
|
+
* @param indexName - The name of the index containing the vector.
|
|
85
|
+
* @param id - The ID of the vector to update.
|
|
86
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
87
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
88
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
89
|
+
* @returns A promise that resolves when the update is complete.
|
|
90
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
91
|
+
*/
|
|
92
|
+
updateVector(indexName: string, id: string, update: {
|
|
93
|
+
vector?: number[];
|
|
94
|
+
metadata?: Record<string, any>;
|
|
95
|
+
}): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
98
|
+
*
|
|
99
|
+
* Deletes a vector by its ID.
|
|
100
|
+
* @param indexName - The name of the index containing the vector.
|
|
101
|
+
* @param id - The ID of the vector to delete.
|
|
102
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
103
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
104
|
+
*/
|
|
70
105
|
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Deletes a vector by its ID.
|
|
108
|
+
* @param indexName - The name of the index containing the vector.
|
|
109
|
+
* @param id - The ID of the vector to delete.
|
|
110
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
111
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
112
|
+
*/
|
|
113
|
+
deleteVector(indexName: string, id: string): Promise<void>;
|
|
71
114
|
}
|
|
72
115
|
export { ChromaVector }
|
|
73
116
|
export { ChromaVector as ChromaVector_alias_1 }
|
|
@@ -63,11 +63,54 @@ declare class ChromaVector extends MastraVector {
|
|
|
63
63
|
listIndexes(): Promise<string[]>;
|
|
64
64
|
describeIndex(indexName: string): Promise<IndexStats>;
|
|
65
65
|
deleteIndex(indexName: string): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
68
|
+
*
|
|
69
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
70
|
+
* @param indexName - The name of the index containing the vector.
|
|
71
|
+
* @param id - The ID of the vector to update.
|
|
72
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
73
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
74
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
75
|
+
* @returns A promise that resolves when the update is complete.
|
|
76
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
77
|
+
*/
|
|
66
78
|
updateIndexById(indexName: string, id: string, update: {
|
|
67
79
|
vector?: number[];
|
|
68
80
|
metadata?: Record<string, any>;
|
|
69
81
|
}): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
84
|
+
* @param indexName - The name of the index containing the vector.
|
|
85
|
+
* @param id - The ID of the vector to update.
|
|
86
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
87
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
88
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
89
|
+
* @returns A promise that resolves when the update is complete.
|
|
90
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
91
|
+
*/
|
|
92
|
+
updateVector(indexName: string, id: string, update: {
|
|
93
|
+
vector?: number[];
|
|
94
|
+
metadata?: Record<string, any>;
|
|
95
|
+
}): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
98
|
+
*
|
|
99
|
+
* Deletes a vector by its ID.
|
|
100
|
+
* @param indexName - The name of the index containing the vector.
|
|
101
|
+
* @param id - The ID of the vector to delete.
|
|
102
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
103
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
104
|
+
*/
|
|
70
105
|
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Deletes a vector by its ID.
|
|
108
|
+
* @param indexName - The name of the index containing the vector.
|
|
109
|
+
* @param id - The ID of the vector to delete.
|
|
110
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
111
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
112
|
+
*/
|
|
113
|
+
deleteVector(indexName: string, id: string): Promise<void>;
|
|
71
114
|
}
|
|
72
115
|
export { ChromaVector }
|
|
73
116
|
export { ChromaVector as ChromaVector_alias_1 }
|
package/dist/index.cjs
CHANGED
|
@@ -218,26 +218,84 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
218
218
|
await this.client.deleteCollection({ name: indexName });
|
|
219
219
|
this.collections.delete(indexName);
|
|
220
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
223
|
+
*
|
|
224
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
225
|
+
* @param indexName - The name of the index containing the vector.
|
|
226
|
+
* @param id - The ID of the vector to update.
|
|
227
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
228
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
229
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
230
|
+
* @returns A promise that resolves when the update is complete.
|
|
231
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
232
|
+
*/
|
|
221
233
|
async updateIndexById(indexName, id, update) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
234
|
+
this.logger.warn(
|
|
235
|
+
`Deprecation Warning: updateIndexById() is deprecated.
|
|
236
|
+
Please use updateVector() instead.
|
|
237
|
+
updateIndexById() will be removed on May 20th, 2025.`
|
|
238
|
+
);
|
|
239
|
+
await this.updateVector(indexName, id, update);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
243
|
+
* @param indexName - The name of the index containing the vector.
|
|
244
|
+
* @param id - The ID of the vector to update.
|
|
245
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
246
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
247
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
248
|
+
* @returns A promise that resolves when the update is complete.
|
|
249
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
250
|
+
*/
|
|
251
|
+
async updateVector(indexName, id, update) {
|
|
252
|
+
try {
|
|
253
|
+
if (!update.vector && !update.metadata) {
|
|
254
|
+
throw new Error("No updates provided");
|
|
255
|
+
}
|
|
256
|
+
const collection = await this.getCollection(indexName, true);
|
|
257
|
+
const updateOptions = { ids: [id] };
|
|
258
|
+
if (update?.vector) {
|
|
259
|
+
const stats = await this.describeIndex(indexName);
|
|
260
|
+
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
261
|
+
updateOptions.embeddings = [update.vector];
|
|
262
|
+
}
|
|
263
|
+
if (update?.metadata) {
|
|
264
|
+
updateOptions.metadatas = [update.metadata];
|
|
265
|
+
}
|
|
266
|
+
return await collection.update(updateOptions);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
232
269
|
}
|
|
233
|
-
return await collection.update(updateOptions);
|
|
234
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
273
|
+
*
|
|
274
|
+
* Deletes a vector by its ID.
|
|
275
|
+
* @param indexName - The name of the index containing the vector.
|
|
276
|
+
* @param id - The ID of the vector to delete.
|
|
277
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
278
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
279
|
+
*/
|
|
235
280
|
async deleteIndexById(indexName, id) {
|
|
281
|
+
this.logger.warn(
|
|
282
|
+
`Deprecation Warning: deleteIndexById() is deprecated. Please use deleteVector() instead. deleteIndexById() will be removed on May 20th.`
|
|
283
|
+
);
|
|
284
|
+
await this.deleteVector(indexName, id);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Deletes a vector by its ID.
|
|
288
|
+
* @param indexName - The name of the index containing the vector.
|
|
289
|
+
* @param id - The ID of the vector to delete.
|
|
290
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
291
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
292
|
+
*/
|
|
293
|
+
async deleteVector(indexName, id) {
|
|
236
294
|
try {
|
|
237
295
|
const collection = await this.getCollection(indexName, true);
|
|
238
296
|
await collection.delete({ ids: [id] });
|
|
239
297
|
} catch (error) {
|
|
240
|
-
throw new Error(`Failed to delete
|
|
298
|
+
throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
241
299
|
}
|
|
242
300
|
}
|
|
243
301
|
};
|
package/dist/index.js
CHANGED
|
@@ -216,26 +216,84 @@ var ChromaVector = class extends MastraVector {
|
|
|
216
216
|
await this.client.deleteCollection({ name: indexName });
|
|
217
217
|
this.collections.delete(indexName);
|
|
218
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
221
|
+
*
|
|
222
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
223
|
+
* @param indexName - The name of the index containing the vector.
|
|
224
|
+
* @param id - The ID of the vector to update.
|
|
225
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
226
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
227
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
228
|
+
* @returns A promise that resolves when the update is complete.
|
|
229
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
230
|
+
*/
|
|
219
231
|
async updateIndexById(indexName, id, update) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
232
|
+
this.logger.warn(
|
|
233
|
+
`Deprecation Warning: updateIndexById() is deprecated.
|
|
234
|
+
Please use updateVector() instead.
|
|
235
|
+
updateIndexById() will be removed on May 20th, 2025.`
|
|
236
|
+
);
|
|
237
|
+
await this.updateVector(indexName, id, update);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
241
|
+
* @param indexName - The name of the index containing the vector.
|
|
242
|
+
* @param id - The ID of the vector to update.
|
|
243
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
244
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
245
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
246
|
+
* @returns A promise that resolves when the update is complete.
|
|
247
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
248
|
+
*/
|
|
249
|
+
async updateVector(indexName, id, update) {
|
|
250
|
+
try {
|
|
251
|
+
if (!update.vector && !update.metadata) {
|
|
252
|
+
throw new Error("No updates provided");
|
|
253
|
+
}
|
|
254
|
+
const collection = await this.getCollection(indexName, true);
|
|
255
|
+
const updateOptions = { ids: [id] };
|
|
256
|
+
if (update?.vector) {
|
|
257
|
+
const stats = await this.describeIndex(indexName);
|
|
258
|
+
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
259
|
+
updateOptions.embeddings = [update.vector];
|
|
260
|
+
}
|
|
261
|
+
if (update?.metadata) {
|
|
262
|
+
updateOptions.metadatas = [update.metadata];
|
|
263
|
+
}
|
|
264
|
+
return await collection.update(updateOptions);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
230
267
|
}
|
|
231
|
-
return await collection.update(updateOptions);
|
|
232
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
271
|
+
*
|
|
272
|
+
* Deletes a vector by its ID.
|
|
273
|
+
* @param indexName - The name of the index containing the vector.
|
|
274
|
+
* @param id - The ID of the vector to delete.
|
|
275
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
276
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
277
|
+
*/
|
|
233
278
|
async deleteIndexById(indexName, id) {
|
|
279
|
+
this.logger.warn(
|
|
280
|
+
`Deprecation Warning: deleteIndexById() is deprecated. Please use deleteVector() instead. deleteIndexById() will be removed on May 20th.`
|
|
281
|
+
);
|
|
282
|
+
await this.deleteVector(indexName, id);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Deletes a vector by its ID.
|
|
286
|
+
* @param indexName - The name of the index containing the vector.
|
|
287
|
+
* @param id - The ID of the vector to delete.
|
|
288
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
289
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
290
|
+
*/
|
|
291
|
+
async deleteVector(indexName, id) {
|
|
234
292
|
try {
|
|
235
293
|
const collection = await this.getCollection(indexName, true);
|
|
236
294
|
await collection.delete({ ids: [id] });
|
|
237
295
|
} catch (error) {
|
|
238
|
-
throw new Error(`Failed to delete
|
|
296
|
+
throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
239
297
|
}
|
|
240
298
|
}
|
|
241
299
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/chroma",
|
|
3
|
-
"version": "0.2.15-alpha.
|
|
3
|
+
"version": "0.2.15-alpha.3",
|
|
4
4
|
"description": "Chroma 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
|
"chromadb": "^2.2.0",
|
|
24
|
-
"@mastra/core": "^0.9.4-alpha.
|
|
24
|
+
"@mastra/core": "^0.9.4-alpha.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@microsoft/api-extractor": "^7.52.5",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -133,7 +133,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
133
133
|
metadata: newMetaData,
|
|
134
134
|
};
|
|
135
135
|
|
|
136
|
-
await vectorDB.
|
|
136
|
+
await vectorDB.updateVector(testIndexName, idToBeUpdated, update);
|
|
137
137
|
|
|
138
138
|
const results: QueryResult[] = await vectorDB.query({
|
|
139
139
|
indexName: testIndexName,
|
|
@@ -159,7 +159,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
159
159
|
metadata: newMetaData,
|
|
160
160
|
};
|
|
161
161
|
|
|
162
|
-
await vectorDB.
|
|
162
|
+
await vectorDB.updateVector(testIndexName, idToBeUpdated, update);
|
|
163
163
|
|
|
164
164
|
const results: QueryResult[] = await vectorDB.query({
|
|
165
165
|
indexName: testIndexName,
|
|
@@ -183,7 +183,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
183
183
|
vector: newVector,
|
|
184
184
|
};
|
|
185
185
|
|
|
186
|
-
await vectorDB.
|
|
186
|
+
await vectorDB.updateVector(testIndexName, idToBeUpdated, update);
|
|
187
187
|
|
|
188
188
|
const results: QueryResult[] = await vectorDB.query({
|
|
189
189
|
indexName: testIndexName,
|
|
@@ -196,7 +196,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
196
196
|
});
|
|
197
197
|
|
|
198
198
|
it('should throw exception when no updates are given', async () => {
|
|
199
|
-
await expect(vectorDB.
|
|
199
|
+
await expect(vectorDB.updateVector(testIndexName, 'id', {})).rejects.toThrow('No updates provided');
|
|
200
200
|
});
|
|
201
201
|
|
|
202
202
|
it('should delete the vector by id', async () => {
|
|
@@ -204,7 +204,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
204
204
|
expect(ids).toHaveLength(3);
|
|
205
205
|
const idToBeDeleted = ids[0];
|
|
206
206
|
|
|
207
|
-
await vectorDB.
|
|
207
|
+
await vectorDB.deleteVector(testIndexName, idToBeDeleted);
|
|
208
208
|
|
|
209
209
|
const results: QueryResult[] = await vectorDB.query({
|
|
210
210
|
indexName: testIndexName,
|
package/src/vector/index.ts
CHANGED
|
@@ -196,36 +196,100 @@ export class ChromaVector extends MastraVector {
|
|
|
196
196
|
this.collections.delete(indexName);
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
/**
|
|
200
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
201
|
+
*
|
|
202
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
203
|
+
* @param indexName - The name of the index containing the vector.
|
|
204
|
+
* @param id - The ID of the vector to update.
|
|
205
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
206
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
207
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
208
|
+
* @returns A promise that resolves when the update is complete.
|
|
209
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
210
|
+
*/
|
|
199
211
|
async updateIndexById(
|
|
200
212
|
indexName: string,
|
|
201
213
|
id: string,
|
|
202
214
|
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
203
215
|
): Promise<void> {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
216
|
+
this.logger.warn(
|
|
217
|
+
`Deprecation Warning: updateIndexById() is deprecated.
|
|
218
|
+
Please use updateVector() instead.
|
|
219
|
+
updateIndexById() will be removed on May 20th, 2025.`,
|
|
220
|
+
);
|
|
221
|
+
await this.updateVector(indexName, id, update);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
226
|
+
* @param indexName - The name of the index containing the vector.
|
|
227
|
+
* @param id - The ID of the vector to update.
|
|
228
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
229
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
230
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
231
|
+
* @returns A promise that resolves when the update is complete.
|
|
232
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
233
|
+
*/
|
|
234
|
+
async updateVector(
|
|
235
|
+
indexName: string,
|
|
236
|
+
id: string,
|
|
237
|
+
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
238
|
+
): Promise<void> {
|
|
239
|
+
try {
|
|
240
|
+
if (!update.vector && !update.metadata) {
|
|
241
|
+
throw new Error('No updates provided');
|
|
242
|
+
}
|
|
207
243
|
|
|
208
|
-
|
|
244
|
+
const collection: Collection = await this.getCollection(indexName, true);
|
|
209
245
|
|
|
210
|
-
|
|
246
|
+
const updateOptions: UpdateRecordsParams = { ids: [id] };
|
|
211
247
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
248
|
+
if (update?.vector) {
|
|
249
|
+
const stats = await this.describeIndex(indexName);
|
|
250
|
+
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
251
|
+
updateOptions.embeddings = [update.vector];
|
|
252
|
+
}
|
|
215
253
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
254
|
+
if (update?.metadata) {
|
|
255
|
+
updateOptions.metadatas = [update.metadata];
|
|
256
|
+
}
|
|
219
257
|
|
|
220
|
-
|
|
258
|
+
return await collection.update(updateOptions);
|
|
259
|
+
} catch (error: any) {
|
|
260
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
261
|
+
}
|
|
221
262
|
}
|
|
222
263
|
|
|
264
|
+
/**
|
|
265
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
266
|
+
*
|
|
267
|
+
* Deletes a vector by its ID.
|
|
268
|
+
* @param indexName - The name of the index containing the vector.
|
|
269
|
+
* @param id - The ID of the vector to delete.
|
|
270
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
271
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
272
|
+
*/
|
|
223
273
|
async deleteIndexById(indexName: string, id: string): Promise<void> {
|
|
274
|
+
this.logger.warn(
|
|
275
|
+
`Deprecation Warning: deleteIndexById() is deprecated. Please use deleteVector() instead. deleteIndexById() will be removed on May 20th.`,
|
|
276
|
+
);
|
|
277
|
+
await this.deleteVector(indexName, id);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Deletes a vector by its ID.
|
|
282
|
+
* @param indexName - The name of the index containing the vector.
|
|
283
|
+
* @param id - The ID of the vector to delete.
|
|
284
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
285
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
286
|
+
*/
|
|
287
|
+
async deleteVector(indexName: string, id: string): Promise<void> {
|
|
224
288
|
try {
|
|
225
289
|
const collection: Collection = await this.getCollection(indexName, true);
|
|
226
290
|
await collection.delete({ ids: [id] });
|
|
227
291
|
} catch (error: any) {
|
|
228
|
-
throw new Error(`Failed to delete
|
|
292
|
+
throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
229
293
|
}
|
|
230
294
|
}
|
|
231
295
|
}
|