@mastra/chroma 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-rag-retrieval.md +20 -18
- package/dist/docs/references/docs-rag-vector-databases.md +28 -4
- package/dist/docs/references/reference-vectors-chroma.md +5 -3
- package/dist/index.cjs +512 -630
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +509 -626
- package/dist/index.js.map +1 -1
- package/package.json +17 -16
package/dist/index.js
CHANGED
|
@@ -1,634 +1,517 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createVectorErrorId } from
|
|
3
|
-
import { MastraVector,
|
|
4
|
-
import {
|
|
5
|
-
import { BaseFilterTranslator } from
|
|
6
|
-
|
|
7
|
-
// src/vector/index.ts
|
|
8
|
-
|
|
9
|
-
// src/vector/distance-to-score.ts
|
|
1
|
+
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
2
|
+
import { createVectorErrorId } from "@mastra/core/storage";
|
|
3
|
+
import { MastraVector, validateTopK, validateUpsert } from "@mastra/core/vector";
|
|
4
|
+
import { ChromaClient, CloudClient } from "chromadb";
|
|
5
|
+
import { BaseFilterTranslator } from "@mastra/core/vector/filter";
|
|
6
|
+
//#region src/vector/distance-to-score.ts
|
|
10
7
|
function distanceToScore(distance, metric) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
case "cosine":
|
|
16
|
-
default:
|
|
17
|
-
return 1 - distance;
|
|
18
|
-
}
|
|
8
|
+
switch (metric) {
|
|
9
|
+
case "euclidean": return 1 / (1 + Math.sqrt(distance));
|
|
10
|
+
default: return 1 - distance;
|
|
11
|
+
}
|
|
19
12
|
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/vector/filter.ts
|
|
15
|
+
/**
|
|
16
|
+
* Translator for Chroma filter queries.
|
|
17
|
+
* Maintains MongoDB-compatible syntax while ensuring proper validation
|
|
18
|
+
* and normalization of values.
|
|
19
|
+
*/
|
|
20
20
|
var ChromaFilterTranslator = class extends BaseFilterTranslator {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
result[newPath] = this.translateNode(value);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (multiOperatorConditions.length > 0) {
|
|
89
|
-
const resultConditions = Object.entries(result).map(([key, value]) => ({ [key]: value }));
|
|
90
|
-
const allConditions = [...multiOperatorConditions, ...resultConditions];
|
|
91
|
-
if (allConditions.length === 1) {
|
|
92
|
-
return allConditions[0];
|
|
93
|
-
}
|
|
94
|
-
return { $and: allConditions };
|
|
95
|
-
}
|
|
96
|
-
if (Object.keys(result).length > 1 && !currentPath) {
|
|
97
|
-
return {
|
|
98
|
-
$and: Object.entries(result).map(([key, value]) => ({ [key]: value }))
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
|
-
translateOperator(operator, value) {
|
|
104
|
-
if (this.isLogicalOperator(operator)) {
|
|
105
|
-
return Array.isArray(value) ? value.map((item) => this.translateNode(item)) : this.translateNode(value);
|
|
106
|
-
}
|
|
107
|
-
return this.normalizeComparisonValue(value);
|
|
108
|
-
}
|
|
21
|
+
getSupportedOperators() {
|
|
22
|
+
return {
|
|
23
|
+
...BaseFilterTranslator.DEFAULT_OPERATORS,
|
|
24
|
+
logical: ["$and", "$or"],
|
|
25
|
+
array: ["$in", "$nin"],
|
|
26
|
+
element: [],
|
|
27
|
+
regex: [],
|
|
28
|
+
custom: []
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
translate(filter) {
|
|
32
|
+
if (this.isEmpty(filter)) return filter;
|
|
33
|
+
this.validateFilter(filter);
|
|
34
|
+
return this.translateNode(filter);
|
|
35
|
+
}
|
|
36
|
+
translateNode(node, currentPath = "") {
|
|
37
|
+
if (this.isRegex(node)) throw new Error("Regex is supported in Chroma via the `documentFilter` argument");
|
|
38
|
+
if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);
|
|
39
|
+
if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };
|
|
40
|
+
const entries = Object.entries(node);
|
|
41
|
+
const firstEntry = entries[0];
|
|
42
|
+
if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {
|
|
43
|
+
const [operator, value] = firstEntry;
|
|
44
|
+
const translated = this.translateOperator(operator, value);
|
|
45
|
+
if (this.isLogicalOperator(operator) && Array.isArray(translated) && translated.length === 1) return translated[0];
|
|
46
|
+
return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;
|
|
47
|
+
}
|
|
48
|
+
const result = {};
|
|
49
|
+
const multiOperatorConditions = [];
|
|
50
|
+
for (const [key, value] of entries) {
|
|
51
|
+
const newPath = currentPath ? `${currentPath}.${key}` : key;
|
|
52
|
+
if (this.isOperator(key)) {
|
|
53
|
+
result[key] = this.translateOperator(key, value);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
57
|
+
const valueEntries = Object.entries(value);
|
|
58
|
+
if (valueEntries.every(([op]) => this.isOperator(op)) && valueEntries.length > 1) {
|
|
59
|
+
valueEntries.forEach(([op, opValue]) => {
|
|
60
|
+
multiOperatorConditions.push({ [newPath]: { [op]: this.normalizeComparisonValue(opValue) } });
|
|
61
|
+
});
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (Object.keys(value).length === 0) result[newPath] = this.translateNode(value);
|
|
65
|
+
else if (Object.keys(value).some((k) => this.isOperator(k))) {
|
|
66
|
+
const normalizedValue = {};
|
|
67
|
+
for (const [op, opValue] of Object.entries(value)) normalizedValue[op] = this.isOperator(op) ? this.translateOperator(op, opValue) : opValue;
|
|
68
|
+
result[newPath] = normalizedValue;
|
|
69
|
+
} else Object.assign(result, this.translateNode(value, newPath));
|
|
70
|
+
} else result[newPath] = this.translateNode(value);
|
|
71
|
+
}
|
|
72
|
+
if (multiOperatorConditions.length > 0) {
|
|
73
|
+
const resultConditions = Object.entries(result).map(([key, value]) => ({ [key]: value }));
|
|
74
|
+
const allConditions = [...multiOperatorConditions, ...resultConditions];
|
|
75
|
+
if (allConditions.length === 1) return allConditions[0];
|
|
76
|
+
return { $and: allConditions };
|
|
77
|
+
}
|
|
78
|
+
if (Object.keys(result).length > 1 && !currentPath) return { $and: Object.entries(result).map(([key, value]) => ({ [key]: value })) };
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
translateOperator(operator, value) {
|
|
82
|
+
if (this.isLogicalOperator(operator)) return Array.isArray(value) ? value.map((item) => this.translateNode(item)) : this.translateNode(value);
|
|
83
|
+
return this.normalizeComparisonValue(value);
|
|
84
|
+
}
|
|
109
85
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/vector/index.ts
|
|
88
|
+
const spaceMappings = {
|
|
89
|
+
cosine: "cosine",
|
|
90
|
+
euclidean: "l2",
|
|
91
|
+
dotproduct: "ip",
|
|
92
|
+
l2: "euclidean",
|
|
93
|
+
ip: "dotproduct"
|
|
118
94
|
};
|
|
119
95
|
var ChromaVector = class extends MastraVector {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
},
|
|
532
|
-
error
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
async deleteVector({ indexName, id }) {
|
|
537
|
-
try {
|
|
538
|
-
const collection = await this.getCollection({ indexName });
|
|
539
|
-
await collection.delete({ ids: [id] });
|
|
540
|
-
} catch (error) {
|
|
541
|
-
if (error instanceof MastraError) throw error;
|
|
542
|
-
throw new MastraError(
|
|
543
|
-
{
|
|
544
|
-
id: createVectorErrorId("CHROMA", "DELETE_VECTOR", "FAILED"),
|
|
545
|
-
domain: ErrorDomain.MASTRA_VECTOR,
|
|
546
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
547
|
-
details: {
|
|
548
|
-
indexName,
|
|
549
|
-
...id && { id }
|
|
550
|
-
}
|
|
551
|
-
},
|
|
552
|
-
error
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
/**
|
|
557
|
-
* Deletes multiple vectors by IDs or filter.
|
|
558
|
-
* @param indexName - The name of the index containing the vectors.
|
|
559
|
-
* @param ids - Array of vector IDs to delete (mutually exclusive with filter).
|
|
560
|
-
* @param filter - Filter to match vectors to delete (mutually exclusive with ids).
|
|
561
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
562
|
-
* @throws Will throw an error if both ids and filter are provided, or if neither is provided.
|
|
563
|
-
*/
|
|
564
|
-
async deleteVectors({ indexName, filter, ids }) {
|
|
565
|
-
if (ids && filter) {
|
|
566
|
-
throw new MastraError({
|
|
567
|
-
id: createVectorErrorId("CHROMA", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
|
|
568
|
-
text: "Cannot specify both ids and filter - they are mutually exclusive",
|
|
569
|
-
domain: ErrorDomain.MASTRA_VECTOR,
|
|
570
|
-
category: ErrorCategory.USER,
|
|
571
|
-
details: { indexName }
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
if (!ids && !filter) {
|
|
575
|
-
throw new MastraError({
|
|
576
|
-
id: createVectorErrorId("CHROMA", "DELETE_VECTORS", "NO_TARGET"),
|
|
577
|
-
text: "Either filter or ids must be provided",
|
|
578
|
-
domain: ErrorDomain.MASTRA_VECTOR,
|
|
579
|
-
category: ErrorCategory.USER,
|
|
580
|
-
details: { indexName }
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
if (ids && ids.length === 0) {
|
|
584
|
-
throw new MastraError({
|
|
585
|
-
id: createVectorErrorId("CHROMA", "DELETE_VECTORS", "EMPTY_IDS"),
|
|
586
|
-
text: "Cannot delete with empty ids array",
|
|
587
|
-
domain: ErrorDomain.MASTRA_VECTOR,
|
|
588
|
-
category: ErrorCategory.USER,
|
|
589
|
-
details: { indexName }
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
if (filter && Object.keys(filter).length === 0) {
|
|
593
|
-
throw new MastraError({
|
|
594
|
-
id: createVectorErrorId("CHROMA", "DELETE_VECTORS", "EMPTY_FILTER"),
|
|
595
|
-
text: "Cannot delete with empty filter object",
|
|
596
|
-
domain: ErrorDomain.MASTRA_VECTOR,
|
|
597
|
-
category: ErrorCategory.USER,
|
|
598
|
-
details: { indexName }
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
try {
|
|
602
|
-
const collection = await this.getCollection({ indexName });
|
|
603
|
-
if (ids) {
|
|
604
|
-
await collection.delete({ ids });
|
|
605
|
-
} else if (filter) {
|
|
606
|
-
const translatedFilter = this.transformFilter(filter);
|
|
607
|
-
await collection.delete({
|
|
608
|
-
where: translatedFilter ?? void 0
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
} catch (error) {
|
|
612
|
-
if (error instanceof MastraError) throw error;
|
|
613
|
-
throw new MastraError(
|
|
614
|
-
{
|
|
615
|
-
id: createVectorErrorId("CHROMA", "DELETE_VECTORS", "FAILED"),
|
|
616
|
-
domain: ErrorDomain.MASTRA_VECTOR,
|
|
617
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
618
|
-
details: {
|
|
619
|
-
indexName,
|
|
620
|
-
...filter && { filter: JSON.stringify(filter) },
|
|
621
|
-
...ids && { idsCount: ids.length }
|
|
622
|
-
}
|
|
623
|
-
},
|
|
624
|
-
error
|
|
625
|
-
);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
96
|
+
client;
|
|
97
|
+
collections;
|
|
98
|
+
constructor({ id, ...chromaClientArgs }) {
|
|
99
|
+
super({ id });
|
|
100
|
+
if (chromaClientArgs?.apiKey) this.client = new CloudClient({
|
|
101
|
+
apiKey: chromaClientArgs.apiKey,
|
|
102
|
+
tenant: chromaClientArgs.tenant,
|
|
103
|
+
database: chromaClientArgs.database
|
|
104
|
+
});
|
|
105
|
+
else this.client = new ChromaClient(chromaClientArgs);
|
|
106
|
+
this.collections = /* @__PURE__ */ new Map();
|
|
107
|
+
}
|
|
108
|
+
async getCollection({ indexName, forceUpdate = false }) {
|
|
109
|
+
let collection = this.collections.get(indexName);
|
|
110
|
+
if (forceUpdate || !collection) try {
|
|
111
|
+
collection = await this.client.getCollection({ name: indexName });
|
|
112
|
+
this.collections.set(indexName, collection);
|
|
113
|
+
return collection;
|
|
114
|
+
} catch {
|
|
115
|
+
throw new MastraError({
|
|
116
|
+
id: createVectorErrorId("CHROMA", "GET_COLLECTION", "FAILED"),
|
|
117
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
118
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
119
|
+
details: { indexName }
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return collection;
|
|
123
|
+
}
|
|
124
|
+
validateVectorDimensions(vectors, dimension) {
|
|
125
|
+
for (let i = 0; i < vectors.length; i++) if (vectors?.[i]?.length !== dimension) throw new Error(`Vector at index ${i} has invalid dimension ${vectors?.[i]?.length}. Expected ${dimension} dimensions.`);
|
|
126
|
+
}
|
|
127
|
+
async upsert({ indexName, vectors, metadata, ids, documents }) {
|
|
128
|
+
validateUpsert("CHROMA", vectors, metadata, ids, true);
|
|
129
|
+
try {
|
|
130
|
+
const collection = await this.getCollection({ indexName });
|
|
131
|
+
const stats = await this.describeIndex({ indexName });
|
|
132
|
+
this.validateVectorDimensions(vectors, stats.dimension);
|
|
133
|
+
const generatedIds = ids || vectors.map(() => crypto.randomUUID());
|
|
134
|
+
await collection.upsert({
|
|
135
|
+
ids: generatedIds,
|
|
136
|
+
embeddings: vectors,
|
|
137
|
+
metadatas: metadata,
|
|
138
|
+
documents
|
|
139
|
+
});
|
|
140
|
+
return generatedIds;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (error instanceof MastraError) throw error;
|
|
143
|
+
throw new MastraError({
|
|
144
|
+
id: createVectorErrorId("CHROMA", "UPSERT", "FAILED"),
|
|
145
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
146
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
147
|
+
details: { indexName }
|
|
148
|
+
}, error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async createIndex({ indexName, dimension, metric = "cosine" }) {
|
|
152
|
+
if (!Number.isInteger(dimension) || dimension <= 0) throw new MastraError({
|
|
153
|
+
id: createVectorErrorId("CHROMA", "CREATE_INDEX", "INVALID_DIMENSION"),
|
|
154
|
+
text: "Dimension must be a positive integer",
|
|
155
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
156
|
+
category: ErrorCategory.USER,
|
|
157
|
+
details: { dimension }
|
|
158
|
+
});
|
|
159
|
+
const hnswSpace = spaceMappings[metric];
|
|
160
|
+
if (!hnswSpace || ![
|
|
161
|
+
"cosine",
|
|
162
|
+
"l2",
|
|
163
|
+
"ip"
|
|
164
|
+
].includes(hnswSpace)) throw new MastraError({
|
|
165
|
+
id: createVectorErrorId("CHROMA", "CREATE_INDEX", "INVALID_METRIC"),
|
|
166
|
+
text: `Invalid metric: "${metric}". Must be one of: cosine, euclidean, dotproduct`,
|
|
167
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
168
|
+
category: ErrorCategory.USER,
|
|
169
|
+
details: { metric }
|
|
170
|
+
});
|
|
171
|
+
try {
|
|
172
|
+
const collection = await this.client.createCollection({
|
|
173
|
+
name: indexName,
|
|
174
|
+
metadata: { dimension },
|
|
175
|
+
configuration: { hnsw: { space: hnswSpace } },
|
|
176
|
+
embeddingFunction: null
|
|
177
|
+
});
|
|
178
|
+
this.collections.set(indexName, collection);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
const message = error?.message || error?.toString();
|
|
181
|
+
if (message && message.toLowerCase().includes("already exists")) {
|
|
182
|
+
await this.validateExistingIndex(indexName, dimension, metric);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
throw new MastraError({
|
|
186
|
+
id: createVectorErrorId("CHROMA", "CREATE_INDEX", "FAILED"),
|
|
187
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
188
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
189
|
+
details: { indexName }
|
|
190
|
+
}, error);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
transformFilter(filter) {
|
|
194
|
+
const translatedFilter = new ChromaFilterTranslator().translate(filter);
|
|
195
|
+
return translatedFilter ? translatedFilter : void 0;
|
|
196
|
+
}
|
|
197
|
+
async query({ indexName, queryVector, topK = 10, filter, includeVector = false, documentFilter }) {
|
|
198
|
+
if (!queryVector) throw new MastraError({
|
|
199
|
+
id: createVectorErrorId("CHROMA", "QUERY", "MISSING_VECTOR"),
|
|
200
|
+
text: "queryVector is required for Chroma queries. Metadata-only queries are not supported by this vector store.",
|
|
201
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
202
|
+
category: ErrorCategory.USER,
|
|
203
|
+
details: { indexName }
|
|
204
|
+
});
|
|
205
|
+
validateTopK("CHROMA", topK);
|
|
206
|
+
try {
|
|
207
|
+
const collection = await this.getCollection({ indexName });
|
|
208
|
+
const defaultInclude = [
|
|
209
|
+
"documents",
|
|
210
|
+
"metadatas",
|
|
211
|
+
"distances"
|
|
212
|
+
];
|
|
213
|
+
const translatedFilter = this.transformFilter(filter);
|
|
214
|
+
const results = await collection.query({
|
|
215
|
+
queryEmbeddings: [queryVector],
|
|
216
|
+
nResults: topK,
|
|
217
|
+
where: translatedFilter ?? void 0,
|
|
218
|
+
whereDocument: documentFilter ?? void 0,
|
|
219
|
+
include: includeVector ? [...defaultInclude, "embeddings"] : defaultInclude
|
|
220
|
+
});
|
|
221
|
+
const space = collection.configuration?.hnsw?.space || collection.configuration?.spann?.space || "cosine";
|
|
222
|
+
const metric = spaceMappings[space];
|
|
223
|
+
return (results.ids[0] || []).map((id, index) => {
|
|
224
|
+
const distance = results.distances?.[0]?.[index];
|
|
225
|
+
return {
|
|
226
|
+
id,
|
|
227
|
+
score: distance == null ? 0 : distanceToScore(distance, metric),
|
|
228
|
+
metadata: results.metadatas?.[0]?.[index] || {},
|
|
229
|
+
document: results.documents?.[0]?.[index] ?? void 0,
|
|
230
|
+
...includeVector && { vector: results.embeddings?.[0]?.[index] || [] }
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
} catch (error) {
|
|
234
|
+
if (error instanceof MastraError) throw error;
|
|
235
|
+
throw new MastraError({
|
|
236
|
+
id: createVectorErrorId("CHROMA", "QUERY", "FAILED"),
|
|
237
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
238
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
239
|
+
details: { indexName }
|
|
240
|
+
}, error);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async hybridSearch({ indexName, search }) {
|
|
244
|
+
try {
|
|
245
|
+
return ((await (await this.getCollection({ indexName })).search(search)).rows()[0] ?? []).map((record) => ({
|
|
246
|
+
id: record.id,
|
|
247
|
+
score: record.score ?? 0,
|
|
248
|
+
metadata: record.metadata ?? void 0,
|
|
249
|
+
vector: record.embedding ?? void 0,
|
|
250
|
+
document: record.document ?? void 0
|
|
251
|
+
}));
|
|
252
|
+
} catch (error) {
|
|
253
|
+
if (error instanceof MastraError) throw error;
|
|
254
|
+
throw new MastraError({
|
|
255
|
+
id: createVectorErrorId("CHROMA", "SEARCH_API", "FAILED"),
|
|
256
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
257
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
258
|
+
details: { indexName }
|
|
259
|
+
}, error);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async get({ indexName, ids, filter, includeVector = false, documentFilter, offset, limit }) {
|
|
263
|
+
try {
|
|
264
|
+
const collection = await this.getCollection({ indexName });
|
|
265
|
+
const defaultInclude = ["documents", "metadatas"];
|
|
266
|
+
const translatedFilter = this.transformFilter(filter);
|
|
267
|
+
return (await collection.get({
|
|
268
|
+
ids,
|
|
269
|
+
where: translatedFilter ?? void 0,
|
|
270
|
+
whereDocument: documentFilter ?? void 0,
|
|
271
|
+
offset,
|
|
272
|
+
limit,
|
|
273
|
+
include: includeVector ? [...defaultInclude, "embeddings"] : defaultInclude
|
|
274
|
+
})).rows();
|
|
275
|
+
} catch (error) {
|
|
276
|
+
if (error instanceof MastraError) throw error;
|
|
277
|
+
throw new MastraError({
|
|
278
|
+
id: createVectorErrorId("CHROMA", "GET", "FAILED"),
|
|
279
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
280
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
281
|
+
details: { indexName }
|
|
282
|
+
}, error);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
async listIndexes() {
|
|
286
|
+
try {
|
|
287
|
+
return (await this.client.listCollections()).map((collection) => collection.name);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
throw new MastraError({
|
|
290
|
+
id: createVectorErrorId("CHROMA", "LIST_INDEXES", "FAILED"),
|
|
291
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
292
|
+
category: ErrorCategory.THIRD_PARTY
|
|
293
|
+
}, error);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Retrieves statistics about a vector index.
|
|
298
|
+
*
|
|
299
|
+
* @param {string} indexName - The name of the index to describe
|
|
300
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
301
|
+
*/
|
|
302
|
+
async describeIndex({ indexName }) {
|
|
303
|
+
try {
|
|
304
|
+
const collection = await this.getCollection({ indexName });
|
|
305
|
+
const count = await collection.count();
|
|
306
|
+
const metadata = collection.metadata;
|
|
307
|
+
const space = collection.configuration.hnsw?.space || collection.configuration.spann?.space || void 0;
|
|
308
|
+
return {
|
|
309
|
+
dimension: metadata?.dimension || 0,
|
|
310
|
+
count,
|
|
311
|
+
metric: space ? spaceMappings[space] : void 0
|
|
312
|
+
};
|
|
313
|
+
} catch (error) {
|
|
314
|
+
if (error instanceof MastraError) throw error;
|
|
315
|
+
throw new MastraError({
|
|
316
|
+
id: createVectorErrorId("CHROMA", "DESCRIBE_INDEX", "FAILED"),
|
|
317
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
318
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
319
|
+
details: { indexName }
|
|
320
|
+
}, error);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async deleteIndex({ indexName }) {
|
|
324
|
+
try {
|
|
325
|
+
await this.client.deleteCollection({ name: indexName });
|
|
326
|
+
this.collections.delete(indexName);
|
|
327
|
+
} catch (error) {
|
|
328
|
+
throw new MastraError({
|
|
329
|
+
id: createVectorErrorId("CHROMA", "DELETE_INDEX", "FAILED"),
|
|
330
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
331
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
332
|
+
details: { indexName }
|
|
333
|
+
}, error);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
async forkIndex({ indexName, newIndexName }) {
|
|
337
|
+
try {
|
|
338
|
+
const forkedCollection = await (await this.getCollection({
|
|
339
|
+
indexName,
|
|
340
|
+
forceUpdate: true
|
|
341
|
+
})).fork({ name: newIndexName });
|
|
342
|
+
this.collections.set(newIndexName, forkedCollection);
|
|
343
|
+
} catch (error) {
|
|
344
|
+
if (error instanceof MastraError) throw error;
|
|
345
|
+
throw new MastraError({
|
|
346
|
+
id: createVectorErrorId("CHROMA", "FORK_INDEX", "FAILED"),
|
|
347
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
348
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
349
|
+
details: { indexName }
|
|
350
|
+
}, error);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Updates a vector by its ID or multiple vectors matching a filter.
|
|
355
|
+
* @param indexName - The name of the index containing the vector(s).
|
|
356
|
+
* @param id - The ID of the vector to update (mutually exclusive with filter).
|
|
357
|
+
* @param filter - Filter to match multiple vectors to update (mutually exclusive with id).
|
|
358
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
359
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
360
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
361
|
+
* @returns A promise that resolves when the update is complete.
|
|
362
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
363
|
+
*/
|
|
364
|
+
async updateVector({ indexName, id, filter, update }) {
|
|
365
|
+
if (id && filter) throw new MastraError({
|
|
366
|
+
id: createVectorErrorId("CHROMA", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
|
|
367
|
+
text: "Cannot specify both id and filter - they are mutually exclusive",
|
|
368
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
369
|
+
category: ErrorCategory.USER,
|
|
370
|
+
details: { indexName }
|
|
371
|
+
});
|
|
372
|
+
if (!id && !filter) throw new MastraError({
|
|
373
|
+
id: createVectorErrorId("CHROMA", "UPDATE_VECTOR", "NO_TARGET"),
|
|
374
|
+
text: "Either id or filter must be provided",
|
|
375
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
376
|
+
category: ErrorCategory.USER,
|
|
377
|
+
details: { indexName }
|
|
378
|
+
});
|
|
379
|
+
if (!update.vector && !update.metadata) throw new MastraError({
|
|
380
|
+
id: createVectorErrorId("CHROMA", "UPDATE_VECTOR", "NO_PAYLOAD"),
|
|
381
|
+
text: "No updates provided",
|
|
382
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
383
|
+
category: ErrorCategory.USER,
|
|
384
|
+
details: {
|
|
385
|
+
indexName,
|
|
386
|
+
...id && { id }
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
if (filter && Object.keys(filter).length === 0) throw new MastraError({
|
|
390
|
+
id: createVectorErrorId("CHROMA", "UPDATE_VECTOR", "EMPTY_FILTER"),
|
|
391
|
+
text: "Filter cannot be an empty filter object",
|
|
392
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
393
|
+
category: ErrorCategory.USER,
|
|
394
|
+
details: { indexName }
|
|
395
|
+
});
|
|
396
|
+
try {
|
|
397
|
+
const collection = await this.getCollection({ indexName });
|
|
398
|
+
if (update?.vector) {
|
|
399
|
+
const stats = await this.describeIndex({ indexName });
|
|
400
|
+
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
401
|
+
}
|
|
402
|
+
if (id) {
|
|
403
|
+
const updateRecordSet = { ids: [id] };
|
|
404
|
+
if (update?.vector) updateRecordSet.embeddings = [update.vector];
|
|
405
|
+
if (update?.metadata) updateRecordSet.metadatas = [update.metadata];
|
|
406
|
+
return await collection.update(updateRecordSet);
|
|
407
|
+
} else if (filter) {
|
|
408
|
+
const translatedFilter = this.transformFilter(filter);
|
|
409
|
+
const vectorRows = (await collection.get({
|
|
410
|
+
where: translatedFilter ?? void 0,
|
|
411
|
+
include: ["embeddings", "metadatas"]
|
|
412
|
+
})).rows();
|
|
413
|
+
if (vectorRows.length === 0) return;
|
|
414
|
+
const updateRecordSet = { ids: vectorRows.map((row) => row.id) };
|
|
415
|
+
if (update?.vector) updateRecordSet.embeddings = vectorRows.map(() => update.vector);
|
|
416
|
+
if (update?.metadata) updateRecordSet.metadatas = vectorRows.map(() => update.metadata);
|
|
417
|
+
return await collection.update(updateRecordSet);
|
|
418
|
+
}
|
|
419
|
+
} catch (error) {
|
|
420
|
+
if (error instanceof MastraError) throw error;
|
|
421
|
+
throw new MastraError({
|
|
422
|
+
id: createVectorErrorId("CHROMA", "UPDATE_VECTOR", "FAILED"),
|
|
423
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
424
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
425
|
+
details: {
|
|
426
|
+
indexName,
|
|
427
|
+
...id && { id },
|
|
428
|
+
...filter && { filter: JSON.stringify(filter) }
|
|
429
|
+
}
|
|
430
|
+
}, error);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
async deleteVector({ indexName, id }) {
|
|
434
|
+
try {
|
|
435
|
+
await (await this.getCollection({ indexName })).delete({ ids: [id] });
|
|
436
|
+
} catch (error) {
|
|
437
|
+
if (error instanceof MastraError) throw error;
|
|
438
|
+
throw new MastraError({
|
|
439
|
+
id: createVectorErrorId("CHROMA", "DELETE_VECTOR", "FAILED"),
|
|
440
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
441
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
442
|
+
details: {
|
|
443
|
+
indexName,
|
|
444
|
+
...id && { id }
|
|
445
|
+
}
|
|
446
|
+
}, error);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Deletes multiple vectors by IDs or filter.
|
|
451
|
+
* @param indexName - The name of the index containing the vectors.
|
|
452
|
+
* @param ids - Array of vector IDs to delete (mutually exclusive with filter).
|
|
453
|
+
* @param filter - Filter to match vectors to delete (mutually exclusive with ids).
|
|
454
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
455
|
+
* @throws Will throw an error if both ids and filter are provided, or if neither is provided.
|
|
456
|
+
*/
|
|
457
|
+
async deleteVectors({ indexName, filter, ids }) {
|
|
458
|
+
if (ids && filter) throw new MastraError({
|
|
459
|
+
id: createVectorErrorId("CHROMA", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
|
|
460
|
+
text: "Cannot specify both ids and filter - they are mutually exclusive",
|
|
461
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
462
|
+
category: ErrorCategory.USER,
|
|
463
|
+
details: { indexName }
|
|
464
|
+
});
|
|
465
|
+
if (!ids && !filter) throw new MastraError({
|
|
466
|
+
id: createVectorErrorId("CHROMA", "DELETE_VECTORS", "NO_TARGET"),
|
|
467
|
+
text: "Either filter or ids must be provided",
|
|
468
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
469
|
+
category: ErrorCategory.USER,
|
|
470
|
+
details: { indexName }
|
|
471
|
+
});
|
|
472
|
+
if (ids && ids.length === 0) throw new MastraError({
|
|
473
|
+
id: createVectorErrorId("CHROMA", "DELETE_VECTORS", "EMPTY_IDS"),
|
|
474
|
+
text: "Cannot delete with empty ids array",
|
|
475
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
476
|
+
category: ErrorCategory.USER,
|
|
477
|
+
details: { indexName }
|
|
478
|
+
});
|
|
479
|
+
if (filter && Object.keys(filter).length === 0) throw new MastraError({
|
|
480
|
+
id: createVectorErrorId("CHROMA", "DELETE_VECTORS", "EMPTY_FILTER"),
|
|
481
|
+
text: "Cannot delete with empty filter object",
|
|
482
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
483
|
+
category: ErrorCategory.USER,
|
|
484
|
+
details: { indexName }
|
|
485
|
+
});
|
|
486
|
+
try {
|
|
487
|
+
const collection = await this.getCollection({ indexName });
|
|
488
|
+
if (ids) await collection.delete({ ids });
|
|
489
|
+
else if (filter) {
|
|
490
|
+
const translatedFilter = this.transformFilter(filter);
|
|
491
|
+
await collection.delete({ where: translatedFilter ?? void 0 });
|
|
492
|
+
}
|
|
493
|
+
} catch (error) {
|
|
494
|
+
if (error instanceof MastraError) throw error;
|
|
495
|
+
throw new MastraError({
|
|
496
|
+
id: createVectorErrorId("CHROMA", "DELETE_VECTORS", "FAILED"),
|
|
497
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
498
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
499
|
+
details: {
|
|
500
|
+
indexName,
|
|
501
|
+
...filter && { filter: JSON.stringify(filter) },
|
|
502
|
+
...ids && { idsCount: ids.length }
|
|
503
|
+
}
|
|
504
|
+
}, error);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
628
507
|
};
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/vector/prompt.ts
|
|
510
|
+
/**
|
|
511
|
+
* Vector store specific prompt that details supported operators and examples.
|
|
512
|
+
* This prompt helps users construct valid filters for Chroma Vector.
|
|
513
|
+
*/
|
|
514
|
+
const CHROMA_PROMPT = `When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
632
515
|
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
633
516
|
If a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.
|
|
634
517
|
|
|
@@ -696,7 +579,7 @@ Example Complex Query:
|
|
|
696
579
|
]}
|
|
697
580
|
]
|
|
698
581
|
}`;
|
|
699
|
-
|
|
582
|
+
//#endregion
|
|
700
583
|
export { CHROMA_PROMPT, ChromaVector };
|
|
701
|
-
|
|
584
|
+
|
|
702
585
|
//# sourceMappingURL=index.js.map
|