@mastra/chroma 0.1.8-alpha.4 → 0.2.0-alpha.6

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/chroma@0.1.8-alpha.4 build /home/runner/work/mastra/mastra/stores/chroma
2
+ > @mastra/chroma@0.2.0-alpha.6 build /home/runner/work/mastra/mastra/stores/chroma
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.3.6
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 7924ms
9
+ TSC ⚡️ Build success in 6673ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.7.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/chroma/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.7.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/chroma/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 9330ms
16
+ DTS ⚡️ Build success in 8364ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 7.28 KB
21
- ESM ⚡️ Build success in 592ms
22
- CJS dist/index.cjs 7.31 KB
23
- CJS ⚡️ Build success in 592ms
20
+ ESM dist/index.js 8.05 KB
21
+ ESM ⚡️ Build success in 705ms
22
+ CJS dist/index.cjs 8.08 KB
23
+ CJS ⚡️ Build success in 707ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @mastra/chroma
2
2
 
3
+ ## 0.2.0-alpha.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [f6678e4]
8
+ - @mastra/core@0.5.0-alpha.6
9
+
10
+ ## 0.2.0-alpha.5
11
+
12
+ ### Minor Changes
13
+
14
+ - 8bee68a: Added implementations to support new operations for MastraVector interface for chroma store
15
+
16
+ ### Patch Changes
17
+
18
+ - 9e81f35: Fix query filter for vector search and rerank
19
+ - Updated dependencies [22643eb]
20
+ - Updated dependencies [6feb23f]
21
+ - Updated dependencies [f2d6727]
22
+ - Updated dependencies [301e4ee]
23
+ - Updated dependencies [dfbe4e9]
24
+ - Updated dependencies [9e81f35]
25
+ - Updated dependencies [caefaa2]
26
+ - Updated dependencies [c151ae6]
27
+ - Updated dependencies [52e0418]
28
+ - Updated dependencies [03236ec]
29
+ - Updated dependencies [3764e71]
30
+ - Updated dependencies [df982db]
31
+ - Updated dependencies [0461849]
32
+ - Updated dependencies [2259379]
33
+ - Updated dependencies [358f069]
34
+ - @mastra/core@0.5.0-alpha.5
35
+
3
36
  ## 0.1.8-alpha.4
4
37
 
5
38
  ### Patch Changes
@@ -55,6 +55,11 @@ declare class ChromaVector extends MastraVector {
55
55
  listIndexes(): Promise<string[]>;
56
56
  describeIndex(indexName: string): Promise<IndexStats>;
57
57
  deleteIndex(indexName: string): Promise<void>;
58
+ updateIndexById(indexName: string, id: string, update: {
59
+ vector?: number[];
60
+ metadata?: Record<string, any>;
61
+ }): Promise<void>;
62
+ deleteIndexById(indexName: string, id: string): Promise<void>;
58
63
  }
59
64
  export { ChromaVector }
60
65
  export { ChromaVector as ChromaVector_alias_1 }
@@ -55,6 +55,11 @@ declare class ChromaVector extends MastraVector {
55
55
  listIndexes(): Promise<string[]>;
56
56
  describeIndex(indexName: string): Promise<IndexStats>;
57
57
  deleteIndex(indexName: string): Promise<void>;
58
+ updateIndexById(indexName: string, id: string, update: {
59
+ vector?: number[];
60
+ metadata?: Record<string, any>;
61
+ }): Promise<void>;
62
+ deleteIndexById(indexName: string, id: string): Promise<void>;
58
63
  }
59
64
  export { ChromaVector }
60
65
  export { ChromaVector as ChromaVector_alias_1 }
package/dist/index.cjs CHANGED
@@ -209,6 +209,28 @@ var ChromaVector = class extends vector.MastraVector {
209
209
  await this.client.deleteCollection({ name: indexName });
210
210
  this.collections.delete(indexName);
211
211
  }
212
+ async updateIndexById(indexName, id, update) {
213
+ if (!update.vector && !update.metadata) {
214
+ throw new Error("No updates provided");
215
+ }
216
+ const collection = await this.getCollection(indexName, true);
217
+ const updateOptions = { ids: [id] };
218
+ if (update?.vector) {
219
+ updateOptions.embeddings = [update.vector];
220
+ }
221
+ if (update?.metadata) {
222
+ updateOptions.metadatas = [update.metadata];
223
+ }
224
+ return await collection.update(updateOptions);
225
+ }
226
+ async deleteIndexById(indexName, id) {
227
+ try {
228
+ const collection = await this.getCollection(indexName, true);
229
+ await collection.delete({ ids: [id] });
230
+ } catch (error) {
231
+ throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
232
+ }
233
+ }
212
234
  };
213
235
 
214
236
  exports.ChromaVector = ChromaVector;
package/dist/index.js CHANGED
@@ -207,6 +207,28 @@ var ChromaVector = class extends MastraVector {
207
207
  await this.client.deleteCollection({ name: indexName });
208
208
  this.collections.delete(indexName);
209
209
  }
210
+ async updateIndexById(indexName, id, update) {
211
+ if (!update.vector && !update.metadata) {
212
+ throw new Error("No updates provided");
213
+ }
214
+ const collection = await this.getCollection(indexName, true);
215
+ const updateOptions = { ids: [id] };
216
+ if (update?.vector) {
217
+ updateOptions.embeddings = [update.vector];
218
+ }
219
+ if (update?.metadata) {
220
+ updateOptions.metadatas = [update.metadata];
221
+ }
222
+ return await collection.update(updateOptions);
223
+ }
224
+ async deleteIndexById(indexName, id) {
225
+ try {
226
+ const collection = await this.getCollection(indexName, true);
227
+ await collection.delete({ ids: [id] });
228
+ } catch (error) {
229
+ throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
230
+ }
231
+ }
210
232
  };
211
233
 
212
234
  export { ChromaVector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/chroma",
3
- "version": "0.1.8-alpha.4",
3
+ "version": "0.2.0-alpha.6",
4
4
  "description": "Chroma 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
  "chromadb": "^1.9.4",
23
- "@mastra/core": "^0.5.0-alpha.4"
23
+ "@mastra/core": "^0.5.0-alpha.6"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@microsoft/api-extractor": "^7.49.2",
@@ -2,6 +2,7 @@ import type { QueryResult, IndexStats } from '@mastra/core/vector';
2
2
  import { describe, expect, beforeEach, afterEach, it, beforeAll, afterAll, vi } from 'vitest';
3
3
 
4
4
  import { ChromaVector } from './';
5
+ import { Collection } from 'chromadb';
5
6
 
6
7
  describe('ChromaVector Integration Tests', () => {
7
8
  let vectorDB = new ChromaVector({
@@ -117,6 +118,104 @@ describe('ChromaVector Integration Tests', () => {
117
118
  expect(results?.[0]?.id).toBe(testIds[0]);
118
119
  expect(results?.[0]?.metadata).toEqual(updatedMetadata[0]);
119
120
  });
121
+
122
+ it('should update the vector by id', async () => {
123
+ const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
124
+ expect(ids).toHaveLength(3);
125
+
126
+ const idToBeUpdated = ids[0];
127
+ const newVector = [1, 2, 3];
128
+ const newMetaData = {
129
+ test: 'updates',
130
+ };
131
+
132
+ const update = {
133
+ vector: newVector,
134
+ metadata: newMetaData,
135
+ };
136
+
137
+ await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
138
+
139
+ const results: QueryResult[] = await vectorDB.query({
140
+ indexName: testIndexName,
141
+ queryVector: newVector,
142
+ topK: 2,
143
+ includeVector: true,
144
+ });
145
+ expect(results[0]?.id).toBe(idToBeUpdated);
146
+ expect(results[0]?.vector).toEqual(newVector);
147
+ expect(results[0]?.metadata).toEqual(newMetaData);
148
+ });
149
+
150
+ it('should only update the metadata by id', async () => {
151
+ const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
152
+ expect(ids).toHaveLength(3);
153
+
154
+ const idToBeUpdated = ids[0];
155
+ const newMetaData = {
156
+ test: 'updates',
157
+ };
158
+
159
+ const update = {
160
+ metadata: newMetaData,
161
+ };
162
+
163
+ await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
164
+
165
+ const results: QueryResult[] = await vectorDB.query({
166
+ indexName: testIndexName,
167
+ queryVector: testVectors[0],
168
+ topK: 2,
169
+ includeVector: true,
170
+ });
171
+ expect(results[0]?.id).toBe(idToBeUpdated);
172
+ expect(results[0]?.vector).toEqual(testVectors[0]);
173
+ expect(results[0]?.metadata).toEqual(newMetaData);
174
+ });
175
+
176
+ it('should only update vector embeddings by id', async () => {
177
+ const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
178
+ expect(ids).toHaveLength(3);
179
+
180
+ const idToBeUpdated = ids[0];
181
+ const newVector = [1, 2, 3];
182
+
183
+ const update = {
184
+ vector: newVector,
185
+ };
186
+
187
+ await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
188
+
189
+ const results: QueryResult[] = await vectorDB.query({
190
+ indexName: testIndexName,
191
+ queryVector: newVector,
192
+ topK: 2,
193
+ includeVector: true,
194
+ });
195
+ expect(results[0]?.id).toBe(idToBeUpdated);
196
+ expect(results[0]?.vector).toEqual(newVector);
197
+ });
198
+
199
+ it('should throw exception when no updates are given', () => {
200
+ expect(vectorDB.updateIndexById(testIndexName, 'id', {})).rejects.toThrow('No updates provided');
201
+ });
202
+
203
+ it('should delete the vector by id', async () => {
204
+ const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
205
+ expect(ids).toHaveLength(3);
206
+ const idToBeDeleted = ids[0];
207
+
208
+ await vectorDB.deleteIndexById(testIndexName, idToBeDeleted);
209
+
210
+ const results: QueryResult[] = await vectorDB.query({
211
+ indexName: testIndexName,
212
+ queryVector: [1.0, 0.0, 0.0],
213
+ topK: 2,
214
+ });
215
+
216
+ expect(results).toHaveLength(2);
217
+ expect(results.map(res => res.id)).not.toContain(idToBeDeleted);
218
+ });
120
219
  });
121
220
 
122
221
  describe('Query Operations', () => {
@@ -932,7 +1031,6 @@ describe('ChromaVector Integration Tests', () => {
932
1031
  const results2 = await vectorDB.query({
933
1032
  indexName: testIndexName2,
934
1033
  queryVector: [1, 0, 0],
935
- filter: undefined,
936
1034
  });
937
1035
  expect(results1).toEqual(results2);
938
1036
  expect(results1.length).toBeGreaterThan(0);
@@ -947,7 +1045,6 @@ describe('ChromaVector Integration Tests', () => {
947
1045
  const results2 = await vectorDB.query({
948
1046
  indexName: testIndexName2,
949
1047
  queryVector: [1, 0, 0],
950
- filter: undefined,
951
1048
  });
952
1049
  expect(results).toEqual(results2);
953
1050
  expect(results.length).toBeGreaterThan(0);
@@ -1270,6 +1367,43 @@ describe('ChromaVector Integration Tests', () => {
1270
1367
  }
1271
1368
  });
1272
1369
  });
1370
+ it('should handle undefined document filter', async () => {
1371
+ const results1 = await vectorDB.query({
1372
+ indexName: testIndexName3,
1373
+ queryVector: [1, 0, 0],
1374
+ documentFilter: undefined,
1375
+ });
1376
+ const results2 = await vectorDB.query({
1377
+ indexName: testIndexName3,
1378
+ queryVector: [1, 0, 0],
1379
+ });
1380
+ expect(results1).toEqual(results2);
1381
+ expect(results1.length).toBeGreaterThan(0);
1382
+ });
1383
+
1384
+ it('should handle empty object document filter', async () => {
1385
+ await expect(
1386
+ vectorDB.query({
1387
+ indexName: testIndexName3,
1388
+ queryVector: [1, 0, 0],
1389
+ documentFilter: {},
1390
+ }),
1391
+ ).rejects.toThrow();
1392
+ });
1393
+
1394
+ it('should handle null filter', async () => {
1395
+ const results = await vectorDB.query({
1396
+ indexName: testIndexName3,
1397
+ queryVector: [1, 0, 0],
1398
+ documentFilter: null,
1399
+ });
1400
+ const results2 = await vectorDB.query({
1401
+ indexName: testIndexName3,
1402
+ queryVector: [1, 0, 0],
1403
+ });
1404
+ expect(results).toEqual(results2);
1405
+ expect(results.length).toBeGreaterThan(0);
1406
+ });
1273
1407
  });
1274
1408
  });
1275
1409
  describe('Deprecation Warnings', () => {
@@ -9,11 +9,13 @@ import type {
9
9
  QueryVectorArgs,
10
10
  UpsertVectorArgs,
11
11
  } from '@mastra/core/vector';
12
- import type { VectorFilter } from '@mastra/core/vector/filter';
13
- import { ChromaClient } from 'chromadb';
14
12
 
13
+ import { ChromaClient, Collection } from 'chromadb';
15
14
  import { ChromaFilterTranslator } from './filter';
16
15
 
16
+ import type { UpdateRecordsParams } from 'chromadb';
17
+ import type { VectorFilter } from '@mastra/core/vector/filter';
18
+
17
19
  interface ChromaUpsertVectorParams extends UpsertVectorParams {
18
20
  documents?: string[];
19
21
  }
@@ -184,4 +186,37 @@ export class ChromaVector extends MastraVector {
184
186
  await this.client.deleteCollection({ name: indexName });
185
187
  this.collections.delete(indexName);
186
188
  }
189
+
190
+ async updateIndexById(
191
+ indexName: string,
192
+ id: string,
193
+ update: { vector?: number[]; metadata?: Record<string, any> },
194
+ ): Promise<void> {
195
+ if (!update.vector && !update.metadata) {
196
+ throw new Error('No updates provided');
197
+ }
198
+
199
+ const collection: Collection = await this.getCollection(indexName, true);
200
+
201
+ const updateOptions: UpdateRecordsParams = { ids: [id] };
202
+
203
+ if (update?.vector) {
204
+ updateOptions.embeddings = [update.vector];
205
+ }
206
+
207
+ if (update?.metadata) {
208
+ updateOptions.metadatas = [update.metadata];
209
+ }
210
+
211
+ return await collection.update(updateOptions);
212
+ }
213
+
214
+ async deleteIndexById(indexName: string, id: string): Promise<void> {
215
+ try {
216
+ const collection: Collection = await this.getCollection(indexName, true);
217
+ await collection.delete({ ids: [id] });
218
+ } catch (error: any) {
219
+ throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
220
+ }
221
+ }
187
222
  }