@mastra/chroma 0.2.15 → 0.2.16-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +14 -0
- package/dist/_tsup-dts-rollup.d.cts +15 -7
- package/dist/_tsup-dts-rollup.d.ts +15 -7
- package/dist/index.cjs +22 -7
- package/dist/index.js +22 -7
- package/package.json +2 -2
- package/src/vector/index.test.ts +28 -26
- package/src/vector/index.ts +28 -11
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/chroma@0.2.
|
|
2
|
+
> @mastra/chroma@0.2.16-alpha.0 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 8644ms
|
|
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 7313ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m14.59 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 707ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m14.64 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 707ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @mastra/chroma
|
|
2
2
|
|
|
3
|
+
## 0.2.16-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
|
|
8
|
+
- Updated dependencies [f53a6ac]
|
|
9
|
+
- Updated dependencies [eabdcd9]
|
|
10
|
+
- Updated dependencies [90be034]
|
|
11
|
+
- Updated dependencies [99f050a]
|
|
12
|
+
- Updated dependencies [d0ee3c6]
|
|
13
|
+
- Updated dependencies [23f258c]
|
|
14
|
+
- Updated dependencies [2672a05]
|
|
15
|
+
- @mastra/core@0.9.5-alpha.0
|
|
16
|
+
|
|
3
17
|
## 0.2.15
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
2
|
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
3
|
+
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
4
|
+
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
5
|
+
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
3
6
|
import type { IndexStats } from '@mastra/core/vector';
|
|
4
7
|
import { MastraVector } from '@mastra/core/vector';
|
|
5
8
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
@@ -7,6 +10,7 @@ import type { ParamsToArgs } from '@mastra/core/vector';
|
|
|
7
10
|
import type { QueryResult } from '@mastra/core/vector';
|
|
8
11
|
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
9
12
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
13
|
+
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
10
14
|
import type { UpsertVectorArgs } from '@mastra/core/vector';
|
|
11
15
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
12
16
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
@@ -61,8 +65,15 @@ declare class ChromaVector extends MastraVector {
|
|
|
61
65
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
62
66
|
query(...args: ParamsToArgs<ChromaQueryVectorParams> | ChromaQueryArgs): Promise<QueryResult[]>;
|
|
63
67
|
listIndexes(): Promise<string[]>;
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves statistics about a vector index.
|
|
70
|
+
*
|
|
71
|
+
* @param params - The parameters for describing an index
|
|
72
|
+
* @param params.indexName - The name of the index to describe
|
|
73
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
74
|
+
*/
|
|
75
|
+
describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
|
|
76
|
+
deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
|
|
66
77
|
/**
|
|
67
78
|
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
68
79
|
*
|
|
@@ -89,10 +100,7 @@ declare class ChromaVector extends MastraVector {
|
|
|
89
100
|
* @returns A promise that resolves when the update is complete.
|
|
90
101
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
91
102
|
*/
|
|
92
|
-
updateVector(
|
|
93
|
-
vector?: number[];
|
|
94
|
-
metadata?: Record<string, any>;
|
|
95
|
-
}): Promise<void>;
|
|
103
|
+
updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
|
|
96
104
|
/**
|
|
97
105
|
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
98
106
|
*
|
|
@@ -110,7 +118,7 @@ declare class ChromaVector extends MastraVector {
|
|
|
110
118
|
* @returns A promise that resolves when the deletion is complete.
|
|
111
119
|
* @throws Will throw an error if the deletion operation fails.
|
|
112
120
|
*/
|
|
113
|
-
deleteVector(
|
|
121
|
+
deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
|
|
114
122
|
}
|
|
115
123
|
export { ChromaVector }
|
|
116
124
|
export { ChromaVector as ChromaVector_alias_1 }
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
2
|
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
3
|
+
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
4
|
+
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
5
|
+
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
3
6
|
import type { IndexStats } from '@mastra/core/vector';
|
|
4
7
|
import { MastraVector } from '@mastra/core/vector';
|
|
5
8
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
@@ -7,6 +10,7 @@ import type { ParamsToArgs } from '@mastra/core/vector';
|
|
|
7
10
|
import type { QueryResult } from '@mastra/core/vector';
|
|
8
11
|
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
9
12
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
13
|
+
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
10
14
|
import type { UpsertVectorArgs } from '@mastra/core/vector';
|
|
11
15
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
12
16
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
@@ -61,8 +65,15 @@ declare class ChromaVector extends MastraVector {
|
|
|
61
65
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
62
66
|
query(...args: ParamsToArgs<ChromaQueryVectorParams> | ChromaQueryArgs): Promise<QueryResult[]>;
|
|
63
67
|
listIndexes(): Promise<string[]>;
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves statistics about a vector index.
|
|
70
|
+
*
|
|
71
|
+
* @param params - The parameters for describing an index
|
|
72
|
+
* @param params.indexName - The name of the index to describe
|
|
73
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
74
|
+
*/
|
|
75
|
+
describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
|
|
76
|
+
deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
|
|
66
77
|
/**
|
|
67
78
|
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
68
79
|
*
|
|
@@ -89,10 +100,7 @@ declare class ChromaVector extends MastraVector {
|
|
|
89
100
|
* @returns A promise that resolves when the update is complete.
|
|
90
101
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
91
102
|
*/
|
|
92
|
-
updateVector(
|
|
93
|
-
vector?: number[];
|
|
94
|
-
metadata?: Record<string, any>;
|
|
95
|
-
}): Promise<void>;
|
|
103
|
+
updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
|
|
96
104
|
/**
|
|
97
105
|
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
98
106
|
*
|
|
@@ -110,7 +118,7 @@ declare class ChromaVector extends MastraVector {
|
|
|
110
118
|
* @returns A promise that resolves when the deletion is complete.
|
|
111
119
|
* @throws Will throw an error if the deletion operation fails.
|
|
112
120
|
*/
|
|
113
|
-
deleteVector(
|
|
121
|
+
deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
|
|
114
122
|
}
|
|
115
123
|
export { ChromaVector }
|
|
116
124
|
export { ChromaVector as ChromaVector_alias_1 }
|
package/dist/index.cjs
CHANGED
|
@@ -128,7 +128,7 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
128
128
|
const params = this.normalizeArgs("upsert", args, ["documents"]);
|
|
129
129
|
const { indexName, vectors, metadata, ids, documents } = params;
|
|
130
130
|
const collection = await this.getCollection(indexName);
|
|
131
|
-
const stats = await this.describeIndex(indexName);
|
|
131
|
+
const stats = await this.describeIndex({ indexName });
|
|
132
132
|
this.validateVectorDimensions(vectors, stats.dimension);
|
|
133
133
|
const generatedIds = ids || vectors.map(() => crypto.randomUUID());
|
|
134
134
|
const normalizedMetadata = metadata || vectors.map(() => ({}));
|
|
@@ -203,7 +203,16 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
203
203
|
const collections = await this.client.listCollections();
|
|
204
204
|
return collections.map((collection) => collection);
|
|
205
205
|
}
|
|
206
|
-
|
|
206
|
+
/**
|
|
207
|
+
* Retrieves statistics about a vector index.
|
|
208
|
+
*
|
|
209
|
+
* @param params - The parameters for describing an index
|
|
210
|
+
* @param params.indexName - The name of the index to describe
|
|
211
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
212
|
+
*/
|
|
213
|
+
async describeIndex(...args) {
|
|
214
|
+
const params = this.normalizeArgs("describeIndex", args);
|
|
215
|
+
const { indexName } = params;
|
|
207
216
|
const collection = await this.getCollection(indexName);
|
|
208
217
|
const count = await collection.count();
|
|
209
218
|
const metadata = collection.metadata;
|
|
@@ -214,7 +223,9 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
214
223
|
metric: this.HnswSpaceMap[hnswSpace]
|
|
215
224
|
};
|
|
216
225
|
}
|
|
217
|
-
async deleteIndex(
|
|
226
|
+
async deleteIndex(...args) {
|
|
227
|
+
const params = this.normalizeArgs("deleteIndex", args);
|
|
228
|
+
const { indexName } = params;
|
|
218
229
|
await this.client.deleteCollection({ name: indexName });
|
|
219
230
|
this.collections.delete(indexName);
|
|
220
231
|
}
|
|
@@ -236,7 +247,7 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
236
247
|
Please use updateVector() instead.
|
|
237
248
|
updateIndexById() will be removed on May 20th, 2025.`
|
|
238
249
|
);
|
|
239
|
-
await this.updateVector(indexName, id, update);
|
|
250
|
+
await this.updateVector({ indexName, id, update });
|
|
240
251
|
}
|
|
241
252
|
/**
|
|
242
253
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
@@ -248,7 +259,9 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
248
259
|
* @returns A promise that resolves when the update is complete.
|
|
249
260
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
250
261
|
*/
|
|
251
|
-
async updateVector(
|
|
262
|
+
async updateVector(...args) {
|
|
263
|
+
const params = this.normalizeArgs("updateVector", args);
|
|
264
|
+
const { indexName, id, update } = params;
|
|
252
265
|
try {
|
|
253
266
|
if (!update.vector && !update.metadata) {
|
|
254
267
|
throw new Error("No updates provided");
|
|
@@ -256,7 +269,7 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
256
269
|
const collection = await this.getCollection(indexName, true);
|
|
257
270
|
const updateOptions = { ids: [id] };
|
|
258
271
|
if (update?.vector) {
|
|
259
|
-
const stats = await this.describeIndex(indexName);
|
|
272
|
+
const stats = await this.describeIndex({ indexName });
|
|
260
273
|
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
261
274
|
updateOptions.embeddings = [update.vector];
|
|
262
275
|
}
|
|
@@ -290,7 +303,9 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
290
303
|
* @returns A promise that resolves when the deletion is complete.
|
|
291
304
|
* @throws Will throw an error if the deletion operation fails.
|
|
292
305
|
*/
|
|
293
|
-
async deleteVector(
|
|
306
|
+
async deleteVector(...args) {
|
|
307
|
+
const params = this.normalizeArgs("deleteVector", args);
|
|
308
|
+
const { indexName, id } = params;
|
|
294
309
|
try {
|
|
295
310
|
const collection = await this.getCollection(indexName, true);
|
|
296
311
|
await collection.delete({ ids: [id] });
|
package/dist/index.js
CHANGED
|
@@ -126,7 +126,7 @@ var ChromaVector = class extends MastraVector {
|
|
|
126
126
|
const params = this.normalizeArgs("upsert", args, ["documents"]);
|
|
127
127
|
const { indexName, vectors, metadata, ids, documents } = params;
|
|
128
128
|
const collection = await this.getCollection(indexName);
|
|
129
|
-
const stats = await this.describeIndex(indexName);
|
|
129
|
+
const stats = await this.describeIndex({ indexName });
|
|
130
130
|
this.validateVectorDimensions(vectors, stats.dimension);
|
|
131
131
|
const generatedIds = ids || vectors.map(() => crypto.randomUUID());
|
|
132
132
|
const normalizedMetadata = metadata || vectors.map(() => ({}));
|
|
@@ -201,7 +201,16 @@ var ChromaVector = class extends MastraVector {
|
|
|
201
201
|
const collections = await this.client.listCollections();
|
|
202
202
|
return collections.map((collection) => collection);
|
|
203
203
|
}
|
|
204
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Retrieves statistics about a vector index.
|
|
206
|
+
*
|
|
207
|
+
* @param params - The parameters for describing an index
|
|
208
|
+
* @param params.indexName - The name of the index to describe
|
|
209
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
210
|
+
*/
|
|
211
|
+
async describeIndex(...args) {
|
|
212
|
+
const params = this.normalizeArgs("describeIndex", args);
|
|
213
|
+
const { indexName } = params;
|
|
205
214
|
const collection = await this.getCollection(indexName);
|
|
206
215
|
const count = await collection.count();
|
|
207
216
|
const metadata = collection.metadata;
|
|
@@ -212,7 +221,9 @@ var ChromaVector = class extends MastraVector {
|
|
|
212
221
|
metric: this.HnswSpaceMap[hnswSpace]
|
|
213
222
|
};
|
|
214
223
|
}
|
|
215
|
-
async deleteIndex(
|
|
224
|
+
async deleteIndex(...args) {
|
|
225
|
+
const params = this.normalizeArgs("deleteIndex", args);
|
|
226
|
+
const { indexName } = params;
|
|
216
227
|
await this.client.deleteCollection({ name: indexName });
|
|
217
228
|
this.collections.delete(indexName);
|
|
218
229
|
}
|
|
@@ -234,7 +245,7 @@ var ChromaVector = class extends MastraVector {
|
|
|
234
245
|
Please use updateVector() instead.
|
|
235
246
|
updateIndexById() will be removed on May 20th, 2025.`
|
|
236
247
|
);
|
|
237
|
-
await this.updateVector(indexName, id, update);
|
|
248
|
+
await this.updateVector({ indexName, id, update });
|
|
238
249
|
}
|
|
239
250
|
/**
|
|
240
251
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
@@ -246,7 +257,9 @@ var ChromaVector = class extends MastraVector {
|
|
|
246
257
|
* @returns A promise that resolves when the update is complete.
|
|
247
258
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
248
259
|
*/
|
|
249
|
-
async updateVector(
|
|
260
|
+
async updateVector(...args) {
|
|
261
|
+
const params = this.normalizeArgs("updateVector", args);
|
|
262
|
+
const { indexName, id, update } = params;
|
|
250
263
|
try {
|
|
251
264
|
if (!update.vector && !update.metadata) {
|
|
252
265
|
throw new Error("No updates provided");
|
|
@@ -254,7 +267,7 @@ var ChromaVector = class extends MastraVector {
|
|
|
254
267
|
const collection = await this.getCollection(indexName, true);
|
|
255
268
|
const updateOptions = { ids: [id] };
|
|
256
269
|
if (update?.vector) {
|
|
257
|
-
const stats = await this.describeIndex(indexName);
|
|
270
|
+
const stats = await this.describeIndex({ indexName });
|
|
258
271
|
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
259
272
|
updateOptions.embeddings = [update.vector];
|
|
260
273
|
}
|
|
@@ -288,7 +301,9 @@ var ChromaVector = class extends MastraVector {
|
|
|
288
301
|
* @returns A promise that resolves when the deletion is complete.
|
|
289
302
|
* @throws Will throw an error if the deletion operation fails.
|
|
290
303
|
*/
|
|
291
|
-
async deleteVector(
|
|
304
|
+
async deleteVector(...args) {
|
|
305
|
+
const params = this.normalizeArgs("deleteVector", args);
|
|
306
|
+
const { indexName, id } = params;
|
|
292
307
|
try {
|
|
293
308
|
const collection = await this.getCollection(indexName, true);
|
|
294
309
|
await collection.delete({ ids: [id] });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/chroma",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16-alpha.0",
|
|
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.
|
|
24
|
+
"@mastra/core": "^0.9.5-alpha.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@microsoft/api-extractor": "^7.52.5",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -16,7 +16,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
16
16
|
beforeEach(async () => {
|
|
17
17
|
// Clean up any existing test index
|
|
18
18
|
try {
|
|
19
|
-
await vectorDB.deleteIndex(testIndexName);
|
|
19
|
+
await vectorDB.deleteIndex({ indexName: testIndexName });
|
|
20
20
|
} catch {
|
|
21
21
|
// Ignore errors if index doesn't exist
|
|
22
22
|
}
|
|
@@ -26,7 +26,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
26
26
|
afterEach(async () => {
|
|
27
27
|
// Cleanup after tests
|
|
28
28
|
try {
|
|
29
|
-
await vectorDB.deleteIndex(testIndexName);
|
|
29
|
+
await vectorDB.deleteIndex({ indexName: testIndexName });
|
|
30
30
|
} catch {
|
|
31
31
|
// Ignore cleanup errors
|
|
32
32
|
}
|
|
@@ -39,14 +39,14 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
it('should describe index correctly', async () => {
|
|
42
|
-
const stats: IndexStats = await vectorDB.describeIndex(testIndexName);
|
|
42
|
+
const stats: IndexStats = await vectorDB.describeIndex({ indexName: testIndexName });
|
|
43
43
|
expect(stats.dimension).toBe(dimension);
|
|
44
44
|
expect(stats.count).toBe(0);
|
|
45
45
|
expect(stats.metric).toBe('cosine');
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
it('should delete index', async () => {
|
|
49
|
-
await vectorDB.deleteIndex(testIndexName);
|
|
49
|
+
await vectorDB.deleteIndex({ indexName: testIndexName });
|
|
50
50
|
const indexes = await vectorDB.listIndexes();
|
|
51
51
|
expect(indexes).not.toContain(testIndexName);
|
|
52
52
|
});
|
|
@@ -58,10 +58,10 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
58
58
|
const testIndex = `test-index-${metric}`;
|
|
59
59
|
await vectorDB.createIndex({ indexName: testIndex, dimension, metric });
|
|
60
60
|
|
|
61
|
-
const stats = await vectorDB.describeIndex(testIndex);
|
|
61
|
+
const stats = await vectorDB.describeIndex({ indexName: testIndex });
|
|
62
62
|
expect(stats.metric).toBe(metric);
|
|
63
63
|
|
|
64
|
-
await vectorDB.deleteIndex(testIndex);
|
|
64
|
+
await vectorDB.deleteIndex({ indexName: testIndex });
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
});
|
|
@@ -80,14 +80,14 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
80
80
|
expect(ids).toHaveLength(testVectors.length);
|
|
81
81
|
ids.forEach(id => expect(typeof id).toBe('string'));
|
|
82
82
|
|
|
83
|
-
const stats = await vectorDB.describeIndex(testIndexName);
|
|
83
|
+
const stats = await vectorDB.describeIndex({ indexName: testIndexName });
|
|
84
84
|
expect(stats.count).toBe(testVectors.length);
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
it('should upsert vectors with provided ids and metadata', async () => {
|
|
88
88
|
await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors, metadata: testMetadata, ids: testIds });
|
|
89
89
|
|
|
90
|
-
const stats = await vectorDB.describeIndex(testIndexName);
|
|
90
|
+
const stats = await vectorDB.describeIndex({ indexName: testIndexName });
|
|
91
91
|
expect(stats.count).toBe(testVectors.length);
|
|
92
92
|
|
|
93
93
|
// Query each vector to verify metadata
|
|
@@ -133,7 +133,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
133
133
|
metadata: newMetaData,
|
|
134
134
|
};
|
|
135
135
|
|
|
136
|
-
await vectorDB.updateVector(testIndexName, idToBeUpdated, update);
|
|
136
|
+
await vectorDB.updateVector({ indexName: testIndexName, id: 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.updateVector(testIndexName, idToBeUpdated, update);
|
|
162
|
+
await vectorDB.updateVector({ indexName: testIndexName, id: 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.updateVector(testIndexName, idToBeUpdated, update);
|
|
186
|
+
await vectorDB.updateVector({ indexName: testIndexName, id: idToBeUpdated, update });
|
|
187
187
|
|
|
188
188
|
const results: QueryResult[] = await vectorDB.query({
|
|
189
189
|
indexName: testIndexName,
|
|
@@ -196,7 +196,9 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
196
196
|
});
|
|
197
197
|
|
|
198
198
|
it('should throw exception when no updates are given', async () => {
|
|
199
|
-
await expect(vectorDB.updateVector(testIndexName, 'id', {})).rejects.toThrow(
|
|
199
|
+
await expect(vectorDB.updateVector({ indexName: testIndexName, id: 'id', update: {} })).rejects.toThrow(
|
|
200
|
+
'No updates provided',
|
|
201
|
+
);
|
|
200
202
|
});
|
|
201
203
|
|
|
202
204
|
it('should delete the vector by id', async () => {
|
|
@@ -204,7 +206,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
204
206
|
expect(ids).toHaveLength(3);
|
|
205
207
|
const idToBeDeleted = ids[0];
|
|
206
208
|
|
|
207
|
-
await vectorDB.deleteVector(testIndexName, idToBeDeleted);
|
|
209
|
+
await vectorDB.deleteVector({ indexName: testIndexName, id: idToBeDeleted });
|
|
208
210
|
|
|
209
211
|
const results: QueryResult[] = await vectorDB.query({
|
|
210
212
|
indexName: testIndexName,
|
|
@@ -279,7 +281,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
279
281
|
});
|
|
280
282
|
|
|
281
283
|
afterAll(async () => {
|
|
282
|
-
await vectorDB.deleteIndex(testIndexName);
|
|
284
|
+
await vectorDB.deleteIndex({ indexName: testIndexName });
|
|
283
285
|
});
|
|
284
286
|
|
|
285
287
|
it('should handle non-existent index queries', async () => {
|
|
@@ -342,7 +344,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
342
344
|
infoSpy.mockRestore();
|
|
343
345
|
warnSpy.mockRestore();
|
|
344
346
|
// Cleanup
|
|
345
|
-
await vectorDB.deleteIndex(duplicateIndexName);
|
|
347
|
+
await vectorDB.deleteIndex({ indexName: duplicateIndexName });
|
|
346
348
|
}
|
|
347
349
|
});
|
|
348
350
|
});
|
|
@@ -519,7 +521,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
519
521
|
// Set up test vectors and metadata
|
|
520
522
|
beforeAll(async () => {
|
|
521
523
|
try {
|
|
522
|
-
await vectorDB.deleteIndex(testIndexName2);
|
|
524
|
+
await vectorDB.deleteIndex({ indexName: testIndexName2 });
|
|
523
525
|
} catch {
|
|
524
526
|
// Ignore errors if index doesn't exist
|
|
525
527
|
}
|
|
@@ -567,7 +569,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
567
569
|
afterAll(async () => {
|
|
568
570
|
// Cleanup after tests
|
|
569
571
|
try {
|
|
570
|
-
await vectorDB.deleteIndex(testIndexName2);
|
|
572
|
+
await vectorDB.deleteIndex({ indexName: testIndexName2 });
|
|
571
573
|
} catch {
|
|
572
574
|
// Ignore cleanup errors
|
|
573
575
|
}
|
|
@@ -1238,7 +1240,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
1238
1240
|
|
|
1239
1241
|
beforeAll(async () => {
|
|
1240
1242
|
try {
|
|
1241
|
-
await vectorDB.deleteIndex(testIndexName3);
|
|
1243
|
+
await vectorDB.deleteIndex({ indexName: testIndexName3 });
|
|
1242
1244
|
} catch {
|
|
1243
1245
|
// Ignore errors if index doesn't exist
|
|
1244
1246
|
}
|
|
@@ -1272,7 +1274,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
1272
1274
|
afterAll(async () => {
|
|
1273
1275
|
// Cleanup after tests
|
|
1274
1276
|
try {
|
|
1275
|
-
await vectorDB.deleteIndex(testIndexName3);
|
|
1277
|
+
await vectorDB.deleteIndex({ indexName: testIndexName3 });
|
|
1276
1278
|
} catch {
|
|
1277
1279
|
// Ignore cleanup errors
|
|
1278
1280
|
}
|
|
@@ -1468,17 +1470,17 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
1468
1470
|
let warnSpy;
|
|
1469
1471
|
|
|
1470
1472
|
beforeAll(async () => {
|
|
1471
|
-
await vectorDB.createIndex({ indexName
|
|
1473
|
+
await vectorDB.createIndex({ indexName, dimension: 3 });
|
|
1472
1474
|
});
|
|
1473
1475
|
|
|
1474
1476
|
afterAll(async () => {
|
|
1475
1477
|
try {
|
|
1476
|
-
await vectorDB.deleteIndex(indexName);
|
|
1478
|
+
await vectorDB.deleteIndex({ indexName });
|
|
1477
1479
|
} catch {
|
|
1478
1480
|
// Ignore errors if index doesn't exist
|
|
1479
1481
|
}
|
|
1480
1482
|
try {
|
|
1481
|
-
await vectorDB.deleteIndex(indexName2);
|
|
1483
|
+
await vectorDB.deleteIndex({ indexName: indexName2 });
|
|
1482
1484
|
} catch {
|
|
1483
1485
|
// Ignore errors if index doesn't exist
|
|
1484
1486
|
}
|
|
@@ -1491,7 +1493,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
1491
1493
|
afterEach(async () => {
|
|
1492
1494
|
warnSpy.mockRestore();
|
|
1493
1495
|
try {
|
|
1494
|
-
await vectorDB.deleteIndex(indexName2);
|
|
1496
|
+
await vectorDB.deleteIndex({ indexName: indexName2 });
|
|
1495
1497
|
} catch {
|
|
1496
1498
|
// Ignore errors if index doesn't exist
|
|
1497
1499
|
}
|
|
@@ -1575,7 +1577,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
1575
1577
|
|
|
1576
1578
|
beforeEach(async () => {
|
|
1577
1579
|
try {
|
|
1578
|
-
await vectorDB.deleteIndex(perfTestIndex);
|
|
1580
|
+
await vectorDB.deleteIndex({ indexName: perfTestIndex });
|
|
1579
1581
|
} catch {
|
|
1580
1582
|
// Ignore errors if index doesn't exist
|
|
1581
1583
|
}
|
|
@@ -1584,7 +1586,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
1584
1586
|
|
|
1585
1587
|
afterEach(async () => {
|
|
1586
1588
|
try {
|
|
1587
|
-
await vectorDB.deleteIndex(perfTestIndex);
|
|
1589
|
+
await vectorDB.deleteIndex({ indexName: perfTestIndex });
|
|
1588
1590
|
} catch {
|
|
1589
1591
|
// Ignore cleanup errors
|
|
1590
1592
|
}
|
|
@@ -1627,7 +1629,7 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
1627
1629
|
});
|
|
1628
1630
|
|
|
1629
1631
|
// Verify all vectors were inserted
|
|
1630
|
-
const stats = await vectorDB.describeIndex(perfTestIndex);
|
|
1632
|
+
const stats = await vectorDB.describeIndex({ indexName: perfTestIndex });
|
|
1631
1633
|
expect(stats.count).toBe(batchSize);
|
|
1632
1634
|
|
|
1633
1635
|
const results = await vectorDB.query({
|
package/src/vector/index.ts
CHANGED
|
@@ -8,6 +8,10 @@ import type {
|
|
|
8
8
|
ParamsToArgs,
|
|
9
9
|
QueryVectorArgs,
|
|
10
10
|
UpsertVectorArgs,
|
|
11
|
+
DescribeIndexParams,
|
|
12
|
+
DeleteIndexParams,
|
|
13
|
+
DeleteVectorParams,
|
|
14
|
+
UpdateVectorParams,
|
|
11
15
|
} from '@mastra/core/vector';
|
|
12
16
|
|
|
13
17
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
@@ -80,7 +84,7 @@ export class ChromaVector extends MastraVector {
|
|
|
80
84
|
const collection = await this.getCollection(indexName);
|
|
81
85
|
|
|
82
86
|
// Get index stats to check dimension
|
|
83
|
-
const stats = await this.describeIndex(indexName);
|
|
87
|
+
const stats = await this.describeIndex({ indexName });
|
|
84
88
|
|
|
85
89
|
// Validate vector dimensions
|
|
86
90
|
this.validateVectorDimensions(vectors, stats.dimension);
|
|
@@ -177,7 +181,17 @@ export class ChromaVector extends MastraVector {
|
|
|
177
181
|
return collections.map(collection => collection);
|
|
178
182
|
}
|
|
179
183
|
|
|
180
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Retrieves statistics about a vector index.
|
|
186
|
+
*
|
|
187
|
+
* @param params - The parameters for describing an index
|
|
188
|
+
* @param params.indexName - The name of the index to describe
|
|
189
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
190
|
+
*/
|
|
191
|
+
async describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats> {
|
|
192
|
+
const params = this.normalizeArgs<DescribeIndexParams>('describeIndex', args);
|
|
193
|
+
const { indexName } = params;
|
|
194
|
+
|
|
181
195
|
const collection = await this.getCollection(indexName);
|
|
182
196
|
const count = await collection.count();
|
|
183
197
|
const metadata = collection.metadata;
|
|
@@ -191,7 +205,9 @@ export class ChromaVector extends MastraVector {
|
|
|
191
205
|
};
|
|
192
206
|
}
|
|
193
207
|
|
|
194
|
-
async deleteIndex(
|
|
208
|
+
async deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void> {
|
|
209
|
+
const params = this.normalizeArgs<DeleteIndexParams>('deleteIndex', args);
|
|
210
|
+
const { indexName } = params;
|
|
195
211
|
await this.client.deleteCollection({ name: indexName });
|
|
196
212
|
this.collections.delete(indexName);
|
|
197
213
|
}
|
|
@@ -218,7 +234,7 @@ export class ChromaVector extends MastraVector {
|
|
|
218
234
|
Please use updateVector() instead.
|
|
219
235
|
updateIndexById() will be removed on May 20th, 2025.`,
|
|
220
236
|
);
|
|
221
|
-
await this.updateVector(indexName, id, update);
|
|
237
|
+
await this.updateVector({ indexName, id, update });
|
|
222
238
|
}
|
|
223
239
|
|
|
224
240
|
/**
|
|
@@ -231,11 +247,9 @@ export class ChromaVector extends MastraVector {
|
|
|
231
247
|
* @returns A promise that resolves when the update is complete.
|
|
232
248
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
233
249
|
*/
|
|
234
|
-
async updateVector(
|
|
235
|
-
|
|
236
|
-
id
|
|
237
|
-
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
238
|
-
): Promise<void> {
|
|
250
|
+
async updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void> {
|
|
251
|
+
const params = this.normalizeArgs<UpdateVectorParams>('updateVector', args);
|
|
252
|
+
const { indexName, id, update } = params;
|
|
239
253
|
try {
|
|
240
254
|
if (!update.vector && !update.metadata) {
|
|
241
255
|
throw new Error('No updates provided');
|
|
@@ -246,7 +260,7 @@ export class ChromaVector extends MastraVector {
|
|
|
246
260
|
const updateOptions: UpdateRecordsParams = { ids: [id] };
|
|
247
261
|
|
|
248
262
|
if (update?.vector) {
|
|
249
|
-
const stats = await this.describeIndex(indexName);
|
|
263
|
+
const stats = await this.describeIndex({ indexName });
|
|
250
264
|
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
251
265
|
updateOptions.embeddings = [update.vector];
|
|
252
266
|
}
|
|
@@ -284,7 +298,10 @@ export class ChromaVector extends MastraVector {
|
|
|
284
298
|
* @returns A promise that resolves when the deletion is complete.
|
|
285
299
|
* @throws Will throw an error if the deletion operation fails.
|
|
286
300
|
*/
|
|
287
|
-
async deleteVector(
|
|
301
|
+
async deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void> {
|
|
302
|
+
const params = this.normalizeArgs<DeleteVectorParams>('deleteVector', args);
|
|
303
|
+
|
|
304
|
+
const { indexName, id } = params;
|
|
288
305
|
try {
|
|
289
306
|
const collection: Collection = await this.getCollection(indexName, true);
|
|
290
307
|
await collection.delete({ ids: [id] });
|