@mastra/chroma 0.0.0-vector-query-sources-20250516172905 → 0.0.0-vector-query-tool-provider-options-20250828222356

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,3 +1,4 @@
1
+ import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';
1
2
  import { MastraVector } from '@mastra/core/vector';
2
3
  import type {
3
4
  QueryResult,
@@ -5,65 +6,83 @@ import type {
5
6
  CreateIndexParams,
6
7
  UpsertVectorParams,
7
8
  QueryVectorParams,
8
- ParamsToArgs,
9
- QueryVectorArgs,
10
- UpsertVectorArgs,
11
9
  DescribeIndexParams,
12
10
  DeleteIndexParams,
13
11
  DeleteVectorParams,
14
12
  UpdateVectorParams,
15
13
  } from '@mastra/core/vector';
16
-
17
- import type { VectorFilter } from '@mastra/core/vector/filter';
18
- import { ChromaClient } from 'chromadb';
19
- import type { UpdateRecordsParams, Collection } from 'chromadb';
14
+ import { ChromaClient, CloudClient } from 'chromadb';
15
+ import type { ChromaClientArgs, RecordSet, Where, WhereDocument, Collection, Metadata } from 'chromadb';
16
+ import type { ChromaVectorFilter } from './filter';
20
17
  import { ChromaFilterTranslator } from './filter';
21
18
 
22
19
  interface ChromaUpsertVectorParams extends UpsertVectorParams {
23
20
  documents?: string[];
24
21
  }
25
22
 
26
- type ChromaUpsertArgs = [...UpsertVectorArgs, string[]?];
23
+ interface ChromaQueryVectorParams extends QueryVectorParams<ChromaVectorFilter> {
24
+ documentFilter?: WhereDocument | null;
25
+ }
27
26
 
28
- interface ChromaQueryVectorParams extends QueryVectorParams {
29
- documentFilter?: VectorFilter;
27
+ interface ChromaGetRecordsParams {
28
+ indexName: string;
29
+ ids?: string[];
30
+ filter?: ChromaVectorFilter;
31
+ documentFilter?: WhereDocument | null;
32
+ includeVector?: boolean;
33
+ limit?: number;
34
+ offset?: number;
30
35
  }
31
36
 
32
- type ChromaQueryArgs = [...QueryVectorArgs, VectorFilter?];
37
+ type MastraMetadata = {
38
+ dimension?: number;
39
+ };
40
+
41
+ type ChromaVectorArgs = ChromaClientArgs & { apiKey?: string };
33
42
 
34
- export class ChromaVector extends MastraVector {
43
+ const spaceMappings = {
44
+ cosine: 'cosine',
45
+ euclidean: 'l2',
46
+ dotproduct: 'ip',
47
+ l2: 'euclidean',
48
+ ip: 'dotproduct',
49
+ };
50
+
51
+ export class ChromaVector extends MastraVector<ChromaVectorFilter> {
35
52
  private client: ChromaClient;
36
- private collections: Map<string, any>;
37
-
38
- constructor({
39
- path,
40
- auth,
41
- }: {
42
- path: string;
43
- auth?: {
44
- provider: string;
45
- credentials: string;
46
- };
47
- }) {
53
+ private collections: Map<string, Collection>;
54
+
55
+ constructor(chromaClientArgs?: ChromaVectorArgs) {
48
56
  super();
49
- this.client = new ChromaClient({
50
- path,
51
- auth,
52
- });
57
+ if (chromaClientArgs?.apiKey) {
58
+ this.client = new CloudClient({
59
+ apiKey: chromaClientArgs.apiKey,
60
+ tenant: chromaClientArgs.tenant,
61
+ database: chromaClientArgs.database,
62
+ });
63
+ } else {
64
+ this.client = new ChromaClient(chromaClientArgs);
65
+ }
53
66
  this.collections = new Map();
54
67
  }
55
68
 
56
- async getCollection(indexName: string, throwIfNotExists: boolean = true) {
57
- try {
58
- const collection = await this.client.getCollection({ name: indexName, embeddingFunction: undefined as any });
59
- this.collections.set(indexName, collection);
60
- } catch {
61
- if (throwIfNotExists) {
62
- throw new Error(`Index ${indexName} does not exist`);
69
+ async getCollection({ indexName, forceUpdate = false }: { indexName: string; forceUpdate?: boolean }) {
70
+ let collection = this.collections.get(indexName);
71
+ if (forceUpdate || !collection) {
72
+ try {
73
+ collection = await this.client.getCollection({ name: indexName });
74
+ this.collections.set(indexName, collection);
75
+ return collection;
76
+ } catch {
77
+ throw new MastraError({
78
+ id: 'CHROMA_COLLECTION_GET_FAILED',
79
+ domain: ErrorDomain.MASTRA_VECTOR,
80
+ category: ErrorCategory.THIRD_PARTY,
81
+ details: { indexName },
82
+ });
63
83
  }
64
- return null;
65
84
  }
66
- return this.collections.get(indexName);
85
+ return collection;
67
86
  }
68
87
 
69
88
  private validateVectorDimensions(vectors: number[][], dimension: number): void {
@@ -76,62 +95,67 @@ export class ChromaVector extends MastraVector {
76
95
  }
77
96
  }
78
97
 
79
- async upsert(...args: ParamsToArgs<ChromaUpsertVectorParams> | ChromaUpsertArgs): Promise<string[]> {
80
- const params = this.normalizeArgs<ChromaUpsertVectorParams, ChromaUpsertArgs>('upsert', args, ['documents']);
81
-
82
- const { indexName, vectors, metadata, ids, documents } = params;
83
-
84
- const collection = await this.getCollection(indexName);
85
-
86
- // Get index stats to check dimension
87
- const stats = await this.describeIndex({ indexName });
88
-
89
- // Validate vector dimensions
90
- this.validateVectorDimensions(vectors, stats.dimension);
91
-
92
- // Generate IDs if not provided
93
- const generatedIds = ids || vectors.map(() => crypto.randomUUID());
98
+ async upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]> {
99
+ try {
100
+ const collection = await this.getCollection({ indexName });
94
101
 
95
- // Ensure metadata exists for each vector
96
- const normalizedMetadata = metadata || vectors.map(() => ({}));
102
+ const stats = await this.describeIndex({ indexName });
103
+ this.validateVectorDimensions(vectors, stats.dimension);
104
+ const generatedIds = ids || vectors.map(() => crypto.randomUUID());
97
105
 
98
- await collection.upsert({
99
- ids: generatedIds,
100
- embeddings: vectors,
101
- metadatas: normalizedMetadata,
102
- documents: documents,
103
- });
106
+ await collection.upsert({
107
+ ids: generatedIds,
108
+ embeddings: vectors,
109
+ metadatas: metadata,
110
+ documents: documents,
111
+ });
104
112
 
105
- return generatedIds;
113
+ return generatedIds;
114
+ } catch (error: any) {
115
+ if (error instanceof MastraError) throw error;
116
+ throw new MastraError(
117
+ {
118
+ id: 'CHROMA_VECTOR_UPSERT_FAILED',
119
+ domain: ErrorDomain.MASTRA_VECTOR,
120
+ category: ErrorCategory.THIRD_PARTY,
121
+ details: { indexName },
122
+ },
123
+ error,
124
+ );
125
+ }
106
126
  }
107
127
 
108
- private HnswSpaceMap = {
109
- cosine: 'cosine',
110
- euclidean: 'l2',
111
- dotproduct: 'ip',
112
- l2: 'euclidean',
113
- ip: 'dotproduct',
114
- };
115
-
116
- async createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void> {
117
- const params = this.normalizeArgs<CreateIndexParams>('createIndex', args);
118
- const { indexName, dimension, metric = 'cosine' } = params;
119
-
128
+ async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {
120
129
  if (!Number.isInteger(dimension) || dimension <= 0) {
121
- throw new Error('Dimension must be a positive integer');
130
+ throw new MastraError({
131
+ id: 'CHROMA_VECTOR_CREATE_INDEX_INVALID_DIMENSION',
132
+ text: 'Dimension must be a positive integer',
133
+ domain: ErrorDomain.MASTRA_VECTOR,
134
+ category: ErrorCategory.USER,
135
+ details: { dimension },
136
+ });
122
137
  }
123
- const hnswSpace = this.HnswSpaceMap[metric];
124
- if (!['cosine', 'l2', 'ip'].includes(hnswSpace)) {
125
- throw new Error(`Invalid metric: "${metric}". Must be one of: cosine, euclidean, dotproduct`);
138
+
139
+ const hnswSpace = spaceMappings[metric] as 'cosine' | 'l2' | 'ip' | undefined;
140
+
141
+ if (!hnswSpace || !['cosine', 'l2', 'ip'].includes(hnswSpace)) {
142
+ throw new MastraError({
143
+ id: 'CHROMA_VECTOR_CREATE_INDEX_INVALID_METRIC',
144
+ text: `Invalid metric: "${metric}". Must be one of: cosine, euclidean, dotproduct`,
145
+ domain: ErrorDomain.MASTRA_VECTOR,
146
+ category: ErrorCategory.USER,
147
+ details: { metric },
148
+ });
126
149
  }
150
+
127
151
  try {
128
- await this.client.createCollection({
152
+ const collection = await this.client.createCollection({
129
153
  name: indexName,
130
- metadata: {
131
- dimension,
132
- 'hnsw:space': hnswSpace,
133
- },
154
+ metadata: { dimension },
155
+ configuration: { hnsw: { space: hnswSpace } },
156
+ embeddingFunction: null,
134
157
  });
158
+ this.collections.set(indexName, collection);
135
159
  } catch (error: any) {
136
160
  // Check for 'already exists' error
137
161
  const message = error?.message || error?.toString();
@@ -140,101 +164,187 @@ export class ChromaVector extends MastraVector {
140
164
  await this.validateExistingIndex(indexName, dimension, metric);
141
165
  return;
142
166
  }
143
- throw error;
167
+ throw new MastraError(
168
+ {
169
+ id: 'CHROMA_VECTOR_CREATE_INDEX_FAILED',
170
+ domain: ErrorDomain.MASTRA_VECTOR,
171
+ category: ErrorCategory.THIRD_PARTY,
172
+ details: { indexName },
173
+ },
174
+ error,
175
+ );
144
176
  }
145
177
  }
146
178
 
147
- transformFilter(filter?: VectorFilter) {
179
+ transformFilter(filter?: ChromaVectorFilter) {
148
180
  const translator = new ChromaFilterTranslator();
149
- return translator.translate(filter);
181
+ const translatedFilter = translator.translate(filter);
182
+ return translatedFilter ? (translatedFilter as Where) : undefined;
150
183
  }
151
- async query(...args: ParamsToArgs<ChromaQueryVectorParams> | ChromaQueryArgs): Promise<QueryResult[]> {
152
- const params = this.normalizeArgs<ChromaQueryVectorParams, ChromaQueryArgs>('query', args, ['documentFilter']);
153
-
154
- const { indexName, queryVector, topK = 10, filter, includeVector = false, documentFilter } = params;
155
-
156
- const collection = await this.getCollection(indexName, true);
157
-
158
- const defaultInclude = ['documents', 'metadatas', 'distances'];
159
-
160
- const translatedFilter = this.transformFilter(filter);
161
- const results = await collection.query({
162
- queryEmbeddings: [queryVector],
163
- nResults: topK,
164
- where: translatedFilter,
165
- whereDocument: documentFilter,
166
- include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,
167
- });
168
-
169
- // Transform ChromaDB results to QueryResult format
170
- return (results.ids[0] || []).map((id: string, index: number) => ({
171
- id,
172
- score: results.distances?.[0]?.[index] || 0,
173
- metadata: results.metadatas?.[0]?.[index] || {},
174
- document: results.documents?.[0]?.[index],
175
- ...(includeVector && { vector: results.embeddings?.[0]?.[index] || [] }),
176
- }));
184
+
185
+ async query<T extends Metadata = Metadata>({
186
+ indexName,
187
+ queryVector,
188
+ topK = 10,
189
+ filter,
190
+ includeVector = false,
191
+ documentFilter,
192
+ }: ChromaQueryVectorParams): Promise<QueryResult[]> {
193
+ try {
194
+ const collection = await this.getCollection({ indexName });
195
+
196
+ const defaultInclude: ['documents', 'metadatas', 'distances'] = ['documents', 'metadatas', 'distances'];
197
+
198
+ const translatedFilter = this.transformFilter(filter);
199
+ const results = await collection.query<T>({
200
+ queryEmbeddings: [queryVector],
201
+ nResults: topK,
202
+ where: translatedFilter ?? undefined,
203
+ whereDocument: documentFilter ?? undefined,
204
+ include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,
205
+ });
206
+
207
+ return (results.ids[0] || []).map((id: string, index: number) => ({
208
+ id,
209
+ score: results.distances?.[0]?.[index] || 0,
210
+ metadata: results.metadatas?.[0]?.[index] || {},
211
+ document: results.documents?.[0]?.[index] ?? undefined,
212
+ ...(includeVector && { vector: results.embeddings?.[0]?.[index] || [] }),
213
+ }));
214
+ } catch (error: any) {
215
+ if (error instanceof MastraError) throw error;
216
+ throw new MastraError(
217
+ {
218
+ id: 'CHROMA_VECTOR_QUERY_FAILED',
219
+ domain: ErrorDomain.MASTRA_VECTOR,
220
+ category: ErrorCategory.THIRD_PARTY,
221
+ details: { indexName },
222
+ },
223
+ error,
224
+ );
225
+ }
226
+ }
227
+
228
+ async get<T extends Metadata = Metadata>({
229
+ indexName,
230
+ ids,
231
+ filter,
232
+ includeVector = false,
233
+ documentFilter,
234
+ offset,
235
+ limit,
236
+ }: ChromaGetRecordsParams) {
237
+ try {
238
+ const collection = await this.getCollection({ indexName });
239
+
240
+ const defaultInclude: ['documents', 'metadatas'] = ['documents', 'metadatas'];
241
+ const translatedFilter = this.transformFilter(filter);
242
+
243
+ const result = await collection.get<T>({
244
+ ids,
245
+ where: translatedFilter ?? undefined,
246
+ whereDocument: documentFilter ?? undefined,
247
+ offset,
248
+ limit,
249
+ include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,
250
+ });
251
+ return result.rows();
252
+ } catch (error: any) {
253
+ if (error instanceof MastraError) throw error;
254
+ throw new MastraError(
255
+ {
256
+ id: 'CHROMA_VECTOR_GET_FAILED',
257
+ domain: ErrorDomain.MASTRA_VECTOR,
258
+ category: ErrorCategory.THIRD_PARTY,
259
+ details: { indexName },
260
+ },
261
+ error,
262
+ );
263
+ }
177
264
  }
178
265
 
179
266
  async listIndexes(): Promise<string[]> {
180
- const collections = await this.client.listCollections();
181
- return collections.map(collection => collection);
267
+ try {
268
+ const collections = await this.client.listCollections();
269
+ return collections.map(collection => collection.name);
270
+ } catch (error: any) {
271
+ throw new MastraError(
272
+ {
273
+ id: 'CHROMA_VECTOR_LIST_INDEXES_FAILED',
274
+ domain: ErrorDomain.MASTRA_VECTOR,
275
+ category: ErrorCategory.THIRD_PARTY,
276
+ },
277
+ error,
278
+ );
279
+ }
182
280
  }
183
281
 
184
282
  /**
185
283
  * Retrieves statistics about a vector index.
186
284
  *
187
- * @param params - The parameters for describing an index
188
- * @param params.indexName - The name of the index to describe
285
+ * @param {string} indexName - The name of the index to describe
189
286
  * @returns A promise that resolves to the index statistics including dimension, count and metric
190
287
  */
191
- async describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats> {
192
- const params = this.normalizeArgs<DescribeIndexParams>('describeIndex', args);
193
- const { indexName } = params;
194
-
195
- const collection = await this.getCollection(indexName);
196
- const count = await collection.count();
197
- const metadata = collection.metadata;
198
-
199
- const hnswSpace = metadata?.['hnsw:space'] as 'cosine' | 'l2' | 'ip';
200
-
201
- return {
202
- dimension: metadata?.dimension || 0,
203
- count,
204
- metric: this.HnswSpaceMap[hnswSpace] as 'cosine' | 'euclidean' | 'dotproduct',
205
- };
288
+ async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {
289
+ try {
290
+ const collection = await this.getCollection({ indexName });
291
+ const count = await collection.count();
292
+ const metadata = collection.metadata as MastraMetadata | undefined;
293
+ const space = collection.configuration.hnsw?.space || collection.configuration.spann?.space || undefined;
294
+
295
+ return {
296
+ dimension: metadata?.dimension || 0,
297
+ count,
298
+ metric: space ? (spaceMappings[space] as 'cosine' | 'euclidean' | 'dotproduct') : undefined,
299
+ };
300
+ } catch (error: any) {
301
+ if (error instanceof MastraError) throw error;
302
+ throw new MastraError(
303
+ {
304
+ id: 'CHROMA_VECTOR_DESCRIBE_INDEX_FAILED',
305
+ domain: ErrorDomain.MASTRA_VECTOR,
306
+ category: ErrorCategory.THIRD_PARTY,
307
+ details: { indexName },
308
+ },
309
+ error,
310
+ );
311
+ }
206
312
  }
207
313
 
208
- async deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void> {
209
- const params = this.normalizeArgs<DeleteIndexParams>('deleteIndex', args);
210
- const { indexName } = params;
211
- await this.client.deleteCollection({ name: indexName });
212
- this.collections.delete(indexName);
314
+ async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {
315
+ try {
316
+ await this.client.deleteCollection({ name: indexName });
317
+ this.collections.delete(indexName);
318
+ } catch (error: any) {
319
+ throw new MastraError(
320
+ {
321
+ id: 'CHROMA_VECTOR_DELETE_INDEX_FAILED',
322
+ domain: ErrorDomain.MASTRA_VECTOR,
323
+ category: ErrorCategory.THIRD_PARTY,
324
+ details: { indexName },
325
+ },
326
+ error,
327
+ );
328
+ }
213
329
  }
214
330
 
215
- /**
216
- * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
217
- *
218
- * Updates a vector by its ID with the provided vector and/or metadata.
219
- * @param indexName - The name of the index containing the vector.
220
- * @param id - The ID of the vector to update.
221
- * @param update - An object containing the vector and/or metadata to update.
222
- * @param update.vector - An optional array of numbers representing the new vector.
223
- * @param update.metadata - An optional record containing the new metadata.
224
- * @returns A promise that resolves when the update is complete.
225
- * @throws Will throw an error if no updates are provided or if the update operation fails.
226
- */
227
- async updateIndexById(
228
- indexName: string,
229
- id: string,
230
- update: { vector?: number[]; metadata?: Record<string, any> },
231
- ): Promise<void> {
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 });
331
+ async forkIndex({ indexName, newIndexName }: { indexName: string; newIndexName: string }): Promise<void> {
332
+ try {
333
+ const collection = await this.getCollection({ indexName, forceUpdate: true });
334
+ const forkedCollection = await collection.fork({ name: newIndexName });
335
+ this.collections.set(newIndexName, forkedCollection);
336
+ } catch (error: any) {
337
+ if (error instanceof MastraError) throw error;
338
+ throw new MastraError(
339
+ {
340
+ id: 'CHROMA_INDEX_FORK_FAILED',
341
+ domain: ErrorDomain.MASTRA_VECTOR,
342
+ category: ErrorCategory.THIRD_PARTY,
343
+ details: { indexName },
344
+ },
345
+ error,
346
+ );
347
+ }
238
348
  }
239
349
 
240
350
  /**
@@ -247,66 +357,62 @@ export class ChromaVector extends MastraVector {
247
357
  * @returns A promise that resolves when the update is complete.
248
358
  * @throws Will throw an error if no updates are provided or if the update operation fails.
249
359
  */
250
- async updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void> {
251
- const params = this.normalizeArgs<UpdateVectorParams>('updateVector', args);
252
- const { indexName, id, update } = params;
253
- try {
254
- if (!update.vector && !update.metadata) {
255
- throw new Error('No updates provided');
256
- }
360
+ async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {
361
+ if (!update.vector && !update.metadata) {
362
+ throw new MastraError({
363
+ id: 'CHROMA_VECTOR_UPDATE_NO_PAYLOAD',
364
+ text: 'No updates provided for vector',
365
+ domain: ErrorDomain.MASTRA_VECTOR,
366
+ category: ErrorCategory.USER,
367
+ details: { indexName, id },
368
+ });
369
+ }
257
370
 
258
- const collection: Collection = await this.getCollection(indexName, true);
371
+ try {
372
+ const collection: Collection = await this.getCollection({ indexName });
259
373
 
260
- const updateOptions: UpdateRecordsParams = { ids: [id] };
374
+ const updateRecordSet: RecordSet = { ids: [id] };
261
375
 
262
376
  if (update?.vector) {
263
377
  const stats = await this.describeIndex({ indexName });
264
378
  this.validateVectorDimensions([update.vector], stats.dimension);
265
- updateOptions.embeddings = [update.vector];
379
+ updateRecordSet.embeddings = [update.vector];
266
380
  }
267
381
 
268
382
  if (update?.metadata) {
269
- updateOptions.metadatas = [update.metadata];
383
+ updateRecordSet.metadatas = [update.metadata];
270
384
  }
271
385
 
272
- return await collection.update(updateOptions);
386
+ return await collection.update(updateRecordSet);
273
387
  } catch (error: any) {
274
- throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
388
+ if (error instanceof MastraError) throw error;
389
+ throw new MastraError(
390
+ {
391
+ id: 'CHROMA_VECTOR_UPDATE_FAILED',
392
+ domain: ErrorDomain.MASTRA_VECTOR,
393
+ category: ErrorCategory.THIRD_PARTY,
394
+ details: { indexName, id },
395
+ },
396
+ error,
397
+ );
275
398
  }
276
399
  }
277
400
 
278
- /**
279
- * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
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 deleteIndexById(indexName: string, id: string): Promise<void> {
288
- this.logger.warn(
289
- `Deprecation Warning: deleteIndexById() is deprecated. Please use deleteVector() instead. deleteIndexById() will be removed on May 20th.`,
290
- );
291
- await this.deleteVector(indexName, id);
292
- }
293
-
294
- /**
295
- * Deletes a vector by its ID.
296
- * @param indexName - The name of the index containing the vector.
297
- * @param id - The ID of the vector to delete.
298
- * @returns A promise that resolves when the deletion is complete.
299
- * @throws Will throw an error if the deletion operation fails.
300
- */
301
- async deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void> {
302
- const params = this.normalizeArgs<DeleteVectorParams>('deleteVector', args);
303
-
304
- const { indexName, id } = params;
401
+ async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {
305
402
  try {
306
- const collection: Collection = await this.getCollection(indexName, true);
403
+ const collection: Collection = await this.getCollection({ indexName });
307
404
  await collection.delete({ ids: [id] });
308
405
  } catch (error: any) {
309
- throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
406
+ if (error instanceof MastraError) throw error;
407
+ throw new MastraError(
408
+ {
409
+ id: 'CHROMA_VECTOR_DELETE_FAILED',
410
+ domain: ErrorDomain.MASTRA_VECTOR,
411
+ category: ErrorCategory.THIRD_PARTY,
412
+ details: { indexName, id },
413
+ },
414
+ error,
415
+ );
310
416
  }
311
417
  }
312
418
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": ["./tsconfig.json", "../../tsconfig.build.json"],
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "**/*.test.ts", "src/**/*.mock.ts"]
9
+ }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*"],
3
+ "include": ["src/**/*", "tsup.config.ts"],
4
4
  "exclude": ["node_modules", "**/*.test.ts"]
5
5
  }
package/tsup.config.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { generateTypes } from '@internal/types-builder';
2
+ import { defineConfig } from 'tsup';
3
+
4
+ export default defineConfig({
5
+ entry: ['src/index.ts'],
6
+ format: ['esm', 'cjs'],
7
+ clean: true,
8
+ dts: false,
9
+ splitting: true,
10
+ treeshake: {
11
+ preset: 'smallest',
12
+ },
13
+ sourcemap: true,
14
+ onSuccess: async () => {
15
+ await generateTypes(process.cwd());
16
+ },
17
+ });