@mastra/chroma 0.11.3 → 0.11.4
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 +1 -1
- package/CHANGELOG.md +45 -0
- package/README.md +47 -21
- package/dist/index.cjs +113 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +114 -50
- package/dist/index.js.map +1 -1
- package/dist/vector/filter.d.ts +0 -3
- package/dist/vector/filter.d.ts.map +1 -1
- package/dist/vector/index.d.ts +33 -13
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/vector/filter.test.ts +3 -0
- package/src/vector/filter.ts +4 -12
- package/src/vector/index.test.ts +138 -16
- package/src/vector/index.ts +144 -66
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
2
2
|
import { MastraVector } from '@mastra/core/vector';
|
|
3
|
-
import { ChromaClient } from 'chromadb';
|
|
3
|
+
import { CloudClient, ChromaClient } from 'chromadb';
|
|
4
4
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
5
5
|
|
|
6
6
|
// src/vector/index.ts
|
|
@@ -22,7 +22,7 @@ var ChromaFilterTranslator = class extends BaseFilterTranslator {
|
|
|
22
22
|
}
|
|
23
23
|
translateNode(node, currentPath = "") {
|
|
24
24
|
if (this.isRegex(node)) {
|
|
25
|
-
throw new Error("Regex is
|
|
25
|
+
throw new Error("Regex is supported in Chroma via the `documentFilter` argument");
|
|
26
26
|
}
|
|
27
27
|
if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);
|
|
28
28
|
if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };
|
|
@@ -31,6 +31,9 @@ var ChromaFilterTranslator = class extends BaseFilterTranslator {
|
|
|
31
31
|
if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {
|
|
32
32
|
const [operator, value] = firstEntry;
|
|
33
33
|
const translated = this.translateOperator(operator, value);
|
|
34
|
+
if (this.isLogicalOperator(operator) && Array.isArray(translated) && translated.length === 1) {
|
|
35
|
+
return translated[0];
|
|
36
|
+
}
|
|
34
37
|
return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;
|
|
35
38
|
}
|
|
36
39
|
const result = {};
|
|
@@ -88,31 +91,46 @@ var ChromaFilterTranslator = class extends BaseFilterTranslator {
|
|
|
88
91
|
};
|
|
89
92
|
|
|
90
93
|
// src/vector/index.ts
|
|
94
|
+
var spaceMappings = {
|
|
95
|
+
cosine: "cosine",
|
|
96
|
+
euclidean: "l2",
|
|
97
|
+
dotproduct: "ip",
|
|
98
|
+
l2: "euclidean",
|
|
99
|
+
ip: "dotproduct"
|
|
100
|
+
};
|
|
91
101
|
var ChromaVector = class extends MastraVector {
|
|
92
102
|
client;
|
|
93
103
|
collections;
|
|
94
|
-
constructor({
|
|
95
|
-
path,
|
|
96
|
-
auth
|
|
97
|
-
}) {
|
|
104
|
+
constructor(chromaClientArgs) {
|
|
98
105
|
super();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
if (chromaClientArgs?.apiKey) {
|
|
107
|
+
this.client = new CloudClient({
|
|
108
|
+
apiKey: chromaClientArgs.apiKey,
|
|
109
|
+
tenant: chromaClientArgs.tenant,
|
|
110
|
+
database: chromaClientArgs.database
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
this.client = new ChromaClient(chromaClientArgs);
|
|
114
|
+
}
|
|
103
115
|
this.collections = /* @__PURE__ */ new Map();
|
|
104
116
|
}
|
|
105
|
-
async getCollection(indexName,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
async getCollection({ indexName, forceUpdate = false }) {
|
|
118
|
+
let collection = this.collections.get(indexName);
|
|
119
|
+
if (forceUpdate || !collection) {
|
|
120
|
+
try {
|
|
121
|
+
collection = await this.client.getCollection({ name: indexName });
|
|
122
|
+
this.collections.set(indexName, collection);
|
|
123
|
+
return collection;
|
|
124
|
+
} catch {
|
|
125
|
+
throw new MastraError({
|
|
126
|
+
id: "CHROMA_COLLECTION_GET_FAILED",
|
|
127
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
128
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
129
|
+
details: { indexName }
|
|
130
|
+
});
|
|
112
131
|
}
|
|
113
|
-
return null;
|
|
114
132
|
}
|
|
115
|
-
return
|
|
133
|
+
return collection;
|
|
116
134
|
}
|
|
117
135
|
validateVectorDimensions(vectors, dimension) {
|
|
118
136
|
for (let i = 0; i < vectors.length; i++) {
|
|
@@ -125,15 +143,14 @@ var ChromaVector = class extends MastraVector {
|
|
|
125
143
|
}
|
|
126
144
|
async upsert({ indexName, vectors, metadata, ids, documents }) {
|
|
127
145
|
try {
|
|
128
|
-
const collection = await this.getCollection(indexName);
|
|
146
|
+
const collection = await this.getCollection({ indexName });
|
|
129
147
|
const stats = await this.describeIndex({ indexName });
|
|
130
148
|
this.validateVectorDimensions(vectors, stats.dimension);
|
|
131
149
|
const generatedIds = ids || vectors.map(() => crypto.randomUUID());
|
|
132
|
-
const normalizedMetadata = metadata || vectors.map(() => ({}));
|
|
133
150
|
await collection.upsert({
|
|
134
151
|
ids: generatedIds,
|
|
135
152
|
embeddings: vectors,
|
|
136
|
-
metadatas:
|
|
153
|
+
metadatas: metadata,
|
|
137
154
|
documents
|
|
138
155
|
});
|
|
139
156
|
return generatedIds;
|
|
@@ -150,13 +167,6 @@ var ChromaVector = class extends MastraVector {
|
|
|
150
167
|
);
|
|
151
168
|
}
|
|
152
169
|
}
|
|
153
|
-
HnswSpaceMap = {
|
|
154
|
-
cosine: "cosine",
|
|
155
|
-
euclidean: "l2",
|
|
156
|
-
dotproduct: "ip",
|
|
157
|
-
l2: "euclidean",
|
|
158
|
-
ip: "dotproduct"
|
|
159
|
-
};
|
|
160
170
|
async createIndex({ indexName, dimension, metric = "cosine" }) {
|
|
161
171
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
162
172
|
throw new MastraError({
|
|
@@ -167,7 +177,7 @@ var ChromaVector = class extends MastraVector {
|
|
|
167
177
|
details: { dimension }
|
|
168
178
|
});
|
|
169
179
|
}
|
|
170
|
-
const hnswSpace =
|
|
180
|
+
const hnswSpace = spaceMappings[metric];
|
|
171
181
|
if (!hnswSpace || !["cosine", "l2", "ip"].includes(hnswSpace)) {
|
|
172
182
|
throw new MastraError({
|
|
173
183
|
id: "CHROMA_VECTOR_CREATE_INDEX_INVALID_METRIC",
|
|
@@ -178,13 +188,13 @@ var ChromaVector = class extends MastraVector {
|
|
|
178
188
|
});
|
|
179
189
|
}
|
|
180
190
|
try {
|
|
181
|
-
await this.client.createCollection({
|
|
191
|
+
const collection = await this.client.createCollection({
|
|
182
192
|
name: indexName,
|
|
183
|
-
metadata: {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
193
|
+
metadata: { dimension },
|
|
194
|
+
configuration: { hnsw: { space: hnswSpace } },
|
|
195
|
+
embeddingFunction: null
|
|
187
196
|
});
|
|
197
|
+
this.collections.set(indexName, collection);
|
|
188
198
|
} catch (error) {
|
|
189
199
|
const message = error?.message || error?.toString();
|
|
190
200
|
if (message && message.toLowerCase().includes("already exists")) {
|
|
@@ -204,7 +214,8 @@ var ChromaVector = class extends MastraVector {
|
|
|
204
214
|
}
|
|
205
215
|
transformFilter(filter) {
|
|
206
216
|
const translator = new ChromaFilterTranslator();
|
|
207
|
-
|
|
217
|
+
const translatedFilter = translator.translate(filter);
|
|
218
|
+
return translatedFilter ? translatedFilter : void 0;
|
|
208
219
|
}
|
|
209
220
|
async query({
|
|
210
221
|
indexName,
|
|
@@ -215,21 +226,21 @@ var ChromaVector = class extends MastraVector {
|
|
|
215
226
|
documentFilter
|
|
216
227
|
}) {
|
|
217
228
|
try {
|
|
218
|
-
const collection = await this.getCollection(indexName
|
|
229
|
+
const collection = await this.getCollection({ indexName });
|
|
219
230
|
const defaultInclude = ["documents", "metadatas", "distances"];
|
|
220
231
|
const translatedFilter = this.transformFilter(filter);
|
|
221
232
|
const results = await collection.query({
|
|
222
233
|
queryEmbeddings: [queryVector],
|
|
223
234
|
nResults: topK,
|
|
224
|
-
where: translatedFilter,
|
|
225
|
-
whereDocument: documentFilter,
|
|
235
|
+
where: translatedFilter ?? void 0,
|
|
236
|
+
whereDocument: documentFilter ?? void 0,
|
|
226
237
|
include: includeVector ? [...defaultInclude, "embeddings"] : defaultInclude
|
|
227
238
|
});
|
|
228
239
|
return (results.ids[0] || []).map((id, index) => ({
|
|
229
240
|
id,
|
|
230
241
|
score: results.distances?.[0]?.[index] || 0,
|
|
231
242
|
metadata: results.metadatas?.[0]?.[index] || {},
|
|
232
|
-
document: results.documents?.[0]?.[index],
|
|
243
|
+
document: results.documents?.[0]?.[index] ?? void 0,
|
|
233
244
|
...includeVector && { vector: results.embeddings?.[0]?.[index] || [] }
|
|
234
245
|
}));
|
|
235
246
|
} catch (error) {
|
|
@@ -245,10 +256,45 @@ var ChromaVector = class extends MastraVector {
|
|
|
245
256
|
);
|
|
246
257
|
}
|
|
247
258
|
}
|
|
259
|
+
async get({
|
|
260
|
+
indexName,
|
|
261
|
+
ids,
|
|
262
|
+
filter,
|
|
263
|
+
includeVector = false,
|
|
264
|
+
documentFilter,
|
|
265
|
+
offset,
|
|
266
|
+
limit
|
|
267
|
+
}) {
|
|
268
|
+
try {
|
|
269
|
+
const collection = await this.getCollection({ indexName });
|
|
270
|
+
const defaultInclude = ["documents", "metadatas"];
|
|
271
|
+
const translatedFilter = this.transformFilter(filter);
|
|
272
|
+
const result = await collection.get({
|
|
273
|
+
ids,
|
|
274
|
+
where: translatedFilter ?? void 0,
|
|
275
|
+
whereDocument: documentFilter ?? void 0,
|
|
276
|
+
offset,
|
|
277
|
+
limit,
|
|
278
|
+
include: includeVector ? [...defaultInclude, "embeddings"] : defaultInclude
|
|
279
|
+
});
|
|
280
|
+
return result.rows();
|
|
281
|
+
} catch (error) {
|
|
282
|
+
if (error instanceof MastraError) throw error;
|
|
283
|
+
throw new MastraError(
|
|
284
|
+
{
|
|
285
|
+
id: "CHROMA_VECTOR_GET_FAILED",
|
|
286
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
287
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
288
|
+
details: { indexName }
|
|
289
|
+
},
|
|
290
|
+
error
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
248
294
|
async listIndexes() {
|
|
249
295
|
try {
|
|
250
296
|
const collections = await this.client.listCollections();
|
|
251
|
-
return collections.map((collection) => collection);
|
|
297
|
+
return collections.map((collection) => collection.name);
|
|
252
298
|
} catch (error) {
|
|
253
299
|
throw new MastraError(
|
|
254
300
|
{
|
|
@@ -268,14 +314,14 @@ var ChromaVector = class extends MastraVector {
|
|
|
268
314
|
*/
|
|
269
315
|
async describeIndex({ indexName }) {
|
|
270
316
|
try {
|
|
271
|
-
const collection = await this.getCollection(indexName);
|
|
317
|
+
const collection = await this.getCollection({ indexName });
|
|
272
318
|
const count = await collection.count();
|
|
273
319
|
const metadata = collection.metadata;
|
|
274
|
-
const
|
|
320
|
+
const space = collection.configuration.hnsw?.space || collection.configuration.spann?.space || void 0;
|
|
275
321
|
return {
|
|
276
322
|
dimension: metadata?.dimension || 0,
|
|
277
323
|
count,
|
|
278
|
-
metric:
|
|
324
|
+
metric: space ? spaceMappings[space] : void 0
|
|
279
325
|
};
|
|
280
326
|
} catch (error) {
|
|
281
327
|
if (error instanceof MastraError) throw error;
|
|
@@ -306,6 +352,24 @@ var ChromaVector = class extends MastraVector {
|
|
|
306
352
|
);
|
|
307
353
|
}
|
|
308
354
|
}
|
|
355
|
+
async forkIndex({ indexName, newIndexName }) {
|
|
356
|
+
try {
|
|
357
|
+
const collection = await this.getCollection({ indexName, forceUpdate: true });
|
|
358
|
+
const forkedCollection = await collection.fork({ name: newIndexName });
|
|
359
|
+
this.collections.set(newIndexName, forkedCollection);
|
|
360
|
+
} catch (error) {
|
|
361
|
+
if (error instanceof MastraError) throw error;
|
|
362
|
+
throw new MastraError(
|
|
363
|
+
{
|
|
364
|
+
id: "CHROMA_INDEX_FORK_FAILED",
|
|
365
|
+
domain: ErrorDomain.MASTRA_VECTOR,
|
|
366
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
367
|
+
details: { indexName }
|
|
368
|
+
},
|
|
369
|
+
error
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
309
373
|
/**
|
|
310
374
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
311
375
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -327,17 +391,17 @@ var ChromaVector = class extends MastraVector {
|
|
|
327
391
|
});
|
|
328
392
|
}
|
|
329
393
|
try {
|
|
330
|
-
const collection = await this.getCollection(indexName
|
|
331
|
-
const
|
|
394
|
+
const collection = await this.getCollection({ indexName });
|
|
395
|
+
const updateRecordSet = { ids: [id] };
|
|
332
396
|
if (update?.vector) {
|
|
333
397
|
const stats = await this.describeIndex({ indexName });
|
|
334
398
|
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
335
|
-
|
|
399
|
+
updateRecordSet.embeddings = [update.vector];
|
|
336
400
|
}
|
|
337
401
|
if (update?.metadata) {
|
|
338
|
-
|
|
402
|
+
updateRecordSet.metadatas = [update.metadata];
|
|
339
403
|
}
|
|
340
|
-
return await collection.update(
|
|
404
|
+
return await collection.update(updateRecordSet);
|
|
341
405
|
} catch (error) {
|
|
342
406
|
if (error instanceof MastraError) throw error;
|
|
343
407
|
throw new MastraError(
|
|
@@ -353,7 +417,7 @@ var ChromaVector = class extends MastraVector {
|
|
|
353
417
|
}
|
|
354
418
|
async deleteVector({ indexName, id }) {
|
|
355
419
|
try {
|
|
356
|
-
const collection = await this.getCollection(indexName
|
|
420
|
+
const collection = await this.getCollection({ indexName });
|
|
357
421
|
await collection.delete({ ids: [id] });
|
|
358
422
|
} catch (error) {
|
|
359
423
|
if (error instanceof MastraError) throw error;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"names":[],"mappings":";;;;;;AAuCO,IAAM,sBAAA,GAAN,cAAqC,oBAAA,CAAyC;AAAA,EAChE,qBAAA,GAAyC;AAC1D,IAAA,OAAO;AAAA,MACL,GAAG,oBAAA,CAAqB,iBAAA;AAAA,MACxB,OAAA,EAAS,CAAC,MAAA,EAAQ,KAAK,CAAA;AAAA,MACvB,KAAA,EAAO,CAAC,KAAA,EAAO,MAAM,CAAA;AAAA,MACrB,SAAS,EAAC;AAAA,MACV,OAAO,EAAC;AAAA,MACR,QAAQ;AAAC,KACX;AAAA,EACF;AAAA,EAEA,UAAU,MAAA,EAAiD;AACzD,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,MAAM,CAAA,EAAG,OAAO,MAAA;AACjC,IAAA,IAAA,CAAK,eAAe,MAAM,CAAA;AAE1B,IAAA,OAAO,IAAA,CAAK,cAAc,MAAM,CAAA;AAAA,EAClC;AAAA,EAEQ,aAAA,CAAc,IAAA,EAA0B,WAAA,GAAsB,EAAA,EAAS;AAE7E,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,IAAI,CAAA,EAAG;AACtB,MAAA,MAAM,IAAI,MAAM,kCAAkC,CAAA;AAAA,IACpD;AACA,IAAA,IAAI,KAAK,WAAA,CAAY,IAAI,GAAG,OAAO,IAAA,CAAK,yBAAyB,IAAI,CAAA;AACrE,IAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,IAAI,CAAA,EAAG,OAAO,EAAE,GAAA,EAAK,IAAA,CAAK,oBAAA,CAAqB,IAAI,CAAA,EAAE;AAEvE,IAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,IAA2B,CAAA;AAC1D,IAAA,MAAM,UAAA,GAAa,QAAQ,CAAC,CAAA;AAE5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EAAI,6BAAA;AAAA,UACJ,QAAQ,WAAA,CAAY,aAAA;AAAA,UACpB,UAAU,aAAA,CAAc,WAAA;AAAA,UACxB,OAAA,EAAS,EAAE,SAAA,EAAW,EAAA;AAAG,SAC3B;AAAA,QACA;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACF;;;AC/UO,IAAM,aAAA,GAAgB,CAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA","file":"index.js","sourcesContent":["import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n OperatorSupport,\n QueryOperator,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype ChromaOperatorValueMap = Omit<OperatorValueMap, '$exists' | '$elemMatch' | '$regex' | '$options'>;\n\ntype ChromaLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not'>;\n\ntype ChromaBlacklisted = BlacklistedRootOperators | '$nor' | '$not';\n\nexport type ChromaVectorFilter = VectorFilter<\n keyof ChromaOperatorValueMap,\n ChromaOperatorValueMap,\n ChromaLogicalOperatorValueMap,\n ChromaBlacklisted\n>;\n\ntype ChromaDocumentOperatorValueMap = ChromaOperatorValueMap;\n\ntype ChromaDocumentBlacklisted = Exclude<ChromaBlacklisted, '$contains'>;\n\nexport type ChromaVectorDocumentFilter = VectorFilter<\n keyof ChromaDocumentOperatorValueMap,\n ChromaDocumentOperatorValueMap,\n ChromaLogicalOperatorValueMap,\n ChromaDocumentBlacklisted\n>;\n\n/**\n * Translator for Chroma filter queries.\n * Maintains MongoDB-compatible syntax while ensuring proper validation\n * and normalization of values.\n */\nexport class ChromaFilterTranslator extends BaseFilterTranslator<ChromaVectorFilter> {\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: ['$and', '$or'],\n array: ['$in', '$nin'],\n element: [],\n regex: [],\n custom: [],\n };\n }\n\n translate(filter?: ChromaVectorFilter): ChromaVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n\n return this.translateNode(filter);\n }\n\n private translateNode(node: ChromaVectorFilter, currentPath: string = ''): any {\n // Handle primitive values and arrays\n if (this.isRegex(node)) {\n throw new Error('Regex is not supported in Chroma');\n }\n if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);\n if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };\n\n const entries = Object.entries(node as Record<string, any>);\n const firstEntry = entries[0];\n // Handle single operator case\n if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {\n const [operator, value] = firstEntry;\n const translated = this.translateOperator(operator, value);\n return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;\n }\n\n // Process each entry\n const result: Record<string, any> = {};\n const multiOperatorConditions: any[] = [];\n\n for (const [key, value] of entries) {\n const newPath = currentPath ? `${currentPath}.${key}` : key;\n\n if (this.isOperator(key)) {\n result[key] = this.translateOperator(key, value);\n continue;\n }\n\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n // Check for multiple operators on same field\n const valueEntries = Object.entries(value);\n if (valueEntries.every(([op]) => this.isOperator(op)) && valueEntries.length > 1) {\n valueEntries.forEach(([op, opValue]) => {\n multiOperatorConditions.push({\n [newPath]: { [op]: this.normalizeComparisonValue(opValue) },\n });\n });\n continue;\n }\n\n // Check if the nested object contains operators\n if (Object.keys(value).length === 0) {\n result[newPath] = this.translateNode(value);\n } else {\n const hasOperators = Object.keys(value).some(k => this.isOperator(k));\n if (hasOperators) {\n // For objects with operators, normalize each operator value\n const normalizedValue: Record<string, any> = {};\n for (const [op, opValue] of Object.entries(value)) {\n normalizedValue[op] = this.isOperator(op) ? this.translateOperator(op, opValue) : opValue;\n }\n result[newPath] = normalizedValue;\n } else {\n // For objects without operators, flatten them\n Object.assign(result, this.translateNode(value, newPath));\n }\n }\n } else {\n result[newPath] = this.translateNode(value);\n }\n }\n\n // If we have multiple operators, return them combined with $and\n if (multiOperatorConditions.length > 0) {\n return { $and: multiOperatorConditions };\n }\n\n // Wrap in $and if there are multiple top-level fields\n if (Object.keys(result).length > 1 && !currentPath) {\n return {\n $and: Object.entries(result).map(([key, value]) => ({ [key]: value })),\n };\n }\n\n return result;\n }\n\n private translateOperator(operator: QueryOperator, value: any): any {\n // Handle logical operators\n if (this.isLogicalOperator(operator)) {\n return Array.isArray(value) ? value.map(item => this.translateNode(item)) : this.translateNode(value);\n }\n\n // Handle comparison and element operators\n return this.normalizeComparisonValue(value);\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { MastraVector } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n} from '@mastra/core/vector';\nimport { ChromaClient } from 'chromadb';\nimport type { UpdateRecordsParams, Collection } from 'chromadb';\nimport type { ChromaVectorDocumentFilter, ChromaVectorFilter } from './filter';\nimport { ChromaFilterTranslator } from './filter';\n\ninterface ChromaUpsertVectorParams extends UpsertVectorParams {\n documents?: string[];\n}\n\ninterface ChromaQueryVectorParams extends QueryVectorParams<ChromaVectorFilter> {\n documentFilter?: ChromaVectorDocumentFilter;\n}\n\nexport class ChromaVector extends MastraVector<ChromaVectorFilter> {\n private client: ChromaClient;\n private collections: Map<string, any>;\n\n constructor({\n path,\n auth,\n }: {\n path: string;\n auth?: {\n provider: string;\n credentials: string;\n };\n }) {\n super();\n this.client = new ChromaClient({\n path,\n auth,\n });\n this.collections = new Map();\n }\n\n async getCollection(indexName: string, throwIfNotExists: boolean = true) {\n try {\n const collection = await this.client.getCollection({ name: indexName, embeddingFunction: undefined as any });\n this.collections.set(indexName, collection);\n } catch {\n if (throwIfNotExists) {\n throw new Error(`Index ${indexName} does not exist`);\n }\n return null;\n }\n return this.collections.get(indexName);\n }\n\n private validateVectorDimensions(vectors: number[][], dimension: number): void {\n for (let i = 0; i < vectors.length; i++) {\n if (vectors?.[i]?.length !== dimension) {\n throw new Error(\n `Vector at index ${i} has invalid dimension ${vectors?.[i]?.length}. Expected ${dimension} dimensions.`,\n );\n }\n }\n }\n\n async upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]> {\n try {\n const collection = await this.getCollection(indexName);\n\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions(vectors, stats.dimension);\n const generatedIds = ids || vectors.map(() => crypto.randomUUID());\n const normalizedMetadata = metadata || vectors.map(() => ({}));\n\n await collection.upsert({\n ids: generatedIds,\n embeddings: vectors,\n metadatas: normalizedMetadata,\n documents: documents,\n });\n\n return generatedIds;\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_UPSERT_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n private HnswSpaceMap = {\n cosine: 'cosine',\n euclidean: 'l2',\n dotproduct: 'ip',\n l2: 'euclidean',\n ip: 'dotproduct',\n };\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new MastraError({\n id: 'CHROMA_VECTOR_CREATE_INDEX_INVALID_DIMENSION',\n text: 'Dimension must be a positive integer',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { dimension },\n });\n }\n const hnswSpace = this.HnswSpaceMap[metric];\n if (!hnswSpace || !['cosine', 'l2', 'ip'].includes(hnswSpace)) {\n throw new MastraError({\n id: 'CHROMA_VECTOR_CREATE_INDEX_INVALID_METRIC',\n text: `Invalid metric: \"${metric}\". Must be one of: cosine, euclidean, dotproduct`,\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { metric },\n });\n }\n try {\n await this.client.createCollection({\n name: indexName,\n metadata: {\n dimension,\n 'hnsw:space': hnswSpace,\n },\n });\n } catch (error: any) {\n // Check for 'already exists' error\n const message = error?.message || error?.toString();\n if (message && message.toLowerCase().includes('already exists')) {\n // Fetch collection info and check dimension\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_CREATE_INDEX_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: ChromaVectorFilter) {\n const translator = new ChromaFilterTranslator();\n return translator.translate(filter);\n }\n async query({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n documentFilter,\n }: ChromaQueryVectorParams): Promise<QueryResult[]> {\n try {\n const collection = await this.getCollection(indexName, true);\n\n const defaultInclude = ['documents', 'metadatas', 'distances'];\n\n const translatedFilter = this.transformFilter(filter);\n const results = await collection.query({\n queryEmbeddings: [queryVector],\n nResults: topK,\n where: translatedFilter,\n whereDocument: documentFilter,\n include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,\n });\n\n return (results.ids[0] || []).map((id: string, index: number) => ({\n id,\n score: results.distances?.[0]?.[index] || 0,\n metadata: results.metadatas?.[0]?.[index] || {},\n document: results.documents?.[0]?.[index],\n ...(includeVector && { vector: results.embeddings?.[0]?.[index] || [] }),\n }));\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_QUERY_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const collections = await this.client.listCollections();\n return collections.map(collection => collection);\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_LIST_INDEXES_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const collection = await this.getCollection(indexName);\n const count = await collection.count();\n const metadata = collection.metadata;\n\n const hnswSpace = metadata?.['hnsw:space'] as 'cosine' | 'l2' | 'ip';\n\n return {\n dimension: metadata?.dimension || 0,\n count,\n metric: this.HnswSpaceMap[hnswSpace] as 'cosine' | 'euclidean' | 'dotproduct',\n };\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_DESCRIBE_INDEX_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.deleteCollection({ name: indexName });\n this.collections.delete(indexName);\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_DELETE_INDEX_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID with the provided vector and/or metadata.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to update.\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {\n if (!update.vector && !update.metadata) {\n throw new MastraError({\n id: 'CHROMA_VECTOR_UPDATE_NO_PAYLOAD',\n text: 'No updates provided for vector',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName, id },\n });\n }\n\n try {\n const collection: Collection = await this.getCollection(indexName, true);\n\n const updateOptions: UpdateRecordsParams = { ids: [id] };\n\n if (update?.vector) {\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions([update.vector], stats.dimension);\n updateOptions.embeddings = [update.vector];\n }\n\n if (update?.metadata) {\n updateOptions.metadatas = [update.metadata];\n }\n\n return await collection.update(updateOptions);\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_UPDATE_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n const collection: Collection = await this.getCollection(indexName, true);\n await collection.delete({ ids: [id] });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_DELETE_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Chroma Vector.\n */\nexport const CHROMA_PROMPT = `When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf 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.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nRestrictions:\n- Regex patterns are not supported\n- Element operators are not supported\n- Only $and and $or logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- If multiple top-level fields exist, they're wrapped in $and\n- Only logical operators ($and, $or) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$in\": [...] }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"$or\": [\n { \"inStock\": true },\n { \"preorder\": true }\n ]}\n ]\n}`;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"names":[],"mappings":";;;;;;AA4BO,IAAM,sBAAA,GAAN,cAAqC,oBAAA,CAAyC;AAAA,EAChE,qBAAA,GAAyC;AAC1D,IAAA,OAAO;AAAA,MACL,GAAG,oBAAA,CAAqB,iBAAA;AAAA,MACxB,OAAA,EAAS,CAAC,MAAA,EAAQ,KAAK,CAAA;AAAA,MACvB,KAAA,EAAO,CAAC,KAAA,EAAO,MAAM,CAAA;AAAA,MACrB,SAAS,EAAC;AAAA,MACV,OAAO,EAAC;AAAA,MACR,QAAQ;AAAC,KACX;AAAA,EACF;AAAA,EAEA,UAAU,MAAA,EAAiD;AACzD,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,MAAM,CAAA,EAAG,OAAO,MAAA;AACjC,IAAA,IAAA,CAAK,eAAe,MAAM,CAAA;AAE1B,IAAA,OAAO,IAAA,CAAK,cAAc,MAAM,CAAA;AAAA,EAClC;AAAA,EAEQ,aAAA,CAAc,IAAA,EAA0B,WAAA,GAAsB,EAAA,EAAS;AAE7E,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,IAAI,CAAA,EAAG;AACtB,MAAA,MAAM,IAAI,MAAM,gEAAgE,CAAA;AAAA,IAClF;AACA,IAAA,IAAI,KAAK,WAAA,CAAY,IAAI,GAAG,OAAO,IAAA,CAAK,yBAAyB,IAAI,CAAA;AACrE,IAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,IAAI,CAAA,EAAG,OAAO,EAAE,GAAA,EAAK,IAAA,CAAK,oBAAA,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;AACnB,MAAA,IAAI,KAAA,YAAiB,aAAa,MAAM,KAAA;AACxC,MAAA,MAAM,IAAI,WAAA;AAAA,QACR;AAAA,UACE,EAAA,EAAI,6BAAA;AAAA,UACJ,QAAQ,WAAA,CAAY,aAAA;AAAA,UACpB,UAAU,aAAA,CAAc,WAAA;AAAA,UACxB,OAAA,EAAS,EAAE,SAAA,EAAW,EAAA;AAAG,SAC3B;AAAA,QACA;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACF;;;AC7ZO,IAAM,aAAA,GAAgB,CAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA","file":"index.js","sourcesContent":["import { BaseFilterTranslator } from '@mastra/core/vector/filter';\nimport type {\n VectorFilter,\n OperatorSupport,\n QueryOperator,\n OperatorValueMap,\n LogicalOperatorValueMap,\n BlacklistedRootOperators,\n} from '@mastra/core/vector/filter';\n\ntype ChromaOperatorValueMap = Omit<OperatorValueMap, '$exists' | '$elemMatch' | '$regex' | '$options'>;\n\ntype ChromaLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not'>;\n\ntype ChromaBlacklisted = BlacklistedRootOperators | '$nor' | '$not';\n\nexport type ChromaVectorFilter = VectorFilter<\n keyof ChromaOperatorValueMap,\n ChromaOperatorValueMap,\n ChromaLogicalOperatorValueMap,\n ChromaBlacklisted\n>;\n\n/**\n * Translator for Chroma filter queries.\n * Maintains MongoDB-compatible syntax while ensuring proper validation\n * and normalization of values.\n */\nexport class ChromaFilterTranslator extends BaseFilterTranslator<ChromaVectorFilter> {\n protected override getSupportedOperators(): OperatorSupport {\n return {\n ...BaseFilterTranslator.DEFAULT_OPERATORS,\n logical: ['$and', '$or'],\n array: ['$in', '$nin'],\n element: [],\n regex: [],\n custom: [],\n };\n }\n\n translate(filter?: ChromaVectorFilter): ChromaVectorFilter {\n if (this.isEmpty(filter)) return filter;\n this.validateFilter(filter);\n\n return this.translateNode(filter);\n }\n\n private translateNode(node: ChromaVectorFilter, currentPath: string = ''): any {\n // Handle primitive values and arrays\n if (this.isRegex(node)) {\n throw new Error('Regex is supported in Chroma via the `documentFilter` argument');\n }\n if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);\n if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };\n\n const entries = Object.entries(node as Record<string, any>);\n const firstEntry = entries[0];\n // Handle single operator case\n if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {\n const [operator, value] = firstEntry;\n const translated = this.translateOperator(operator, value);\n if (this.isLogicalOperator(operator) && Array.isArray(translated) && translated.length === 1) {\n return translated[0];\n }\n return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;\n }\n\n // Process each entry\n const result: Record<string, any> = {};\n const multiOperatorConditions: any[] = [];\n\n for (const [key, value] of entries) {\n const newPath = currentPath ? `${currentPath}.${key}` : key;\n\n if (this.isOperator(key)) {\n result[key] = this.translateOperator(key, value);\n continue;\n }\n\n if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n // Check for multiple operators on same field\n const valueEntries = Object.entries(value);\n if (valueEntries.every(([op]) => this.isOperator(op)) && valueEntries.length > 1) {\n valueEntries.forEach(([op, opValue]) => {\n multiOperatorConditions.push({\n [newPath]: { [op]: this.normalizeComparisonValue(opValue) },\n });\n });\n continue;\n }\n\n // Check if the nested object contains operators\n if (Object.keys(value).length === 0) {\n result[newPath] = this.translateNode(value);\n } else {\n const hasOperators = Object.keys(value).some(k => this.isOperator(k));\n if (hasOperators) {\n // For objects with operators, normalize each operator value\n const normalizedValue: Record<string, any> = {};\n for (const [op, opValue] of Object.entries(value)) {\n normalizedValue[op] = this.isOperator(op) ? this.translateOperator(op, opValue) : opValue;\n }\n result[newPath] = normalizedValue;\n } else {\n // For objects without operators, flatten them\n Object.assign(result, this.translateNode(value, newPath));\n }\n }\n } else {\n result[newPath] = this.translateNode(value);\n }\n }\n\n // If we have multiple operators, return them combined with $and\n if (multiOperatorConditions.length > 0) {\n return { $and: multiOperatorConditions };\n }\n\n // Wrap in $and if there are multiple top-level fields\n if (Object.keys(result).length > 1 && !currentPath) {\n return {\n $and: Object.entries(result).map(([key, value]) => ({ [key]: value })),\n };\n }\n\n return result;\n }\n\n private translateOperator(operator: QueryOperator, value: any): any {\n // Handle logical operators\n if (this.isLogicalOperator(operator)) {\n return Array.isArray(value) ? value.map(item => this.translateNode(item)) : this.translateNode(value);\n }\n\n // Handle comparison and element operators\n return this.normalizeComparisonValue(value);\n }\n}\n","import { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport { MastraVector } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n} from '@mastra/core/vector';\nimport { ChromaClient, CloudClient } from 'chromadb';\nimport type { ChromaClientArgs, RecordSet, Where, WhereDocument, Collection, Metadata } from 'chromadb';\nimport type { ChromaVectorFilter } from './filter';\nimport { ChromaFilterTranslator } from './filter';\n\ninterface ChromaUpsertVectorParams extends UpsertVectorParams {\n documents?: string[];\n}\n\ninterface ChromaQueryVectorParams extends QueryVectorParams<ChromaVectorFilter> {\n documentFilter?: WhereDocument | null;\n}\n\ninterface ChromaGetRecordsParams {\n indexName: string;\n ids?: string[];\n filter?: ChromaVectorFilter;\n documentFilter?: WhereDocument | null;\n includeVector?: boolean;\n limit?: number;\n offset?: number;\n}\n\ntype MastraMetadata = {\n dimension?: number;\n};\n\ntype ChromaVectorArgs = ChromaClientArgs & { apiKey?: string };\n\nconst spaceMappings = {\n cosine: 'cosine',\n euclidean: 'l2',\n dotproduct: 'ip',\n l2: 'euclidean',\n ip: 'dotproduct',\n};\n\nexport class ChromaVector extends MastraVector<ChromaVectorFilter> {\n private client: ChromaClient;\n private collections: Map<string, Collection>;\n\n constructor(chromaClientArgs?: ChromaVectorArgs) {\n super();\n if (chromaClientArgs?.apiKey) {\n this.client = new CloudClient({\n apiKey: chromaClientArgs.apiKey,\n tenant: chromaClientArgs.tenant,\n database: chromaClientArgs.database,\n });\n } else {\n this.client = new ChromaClient(chromaClientArgs);\n }\n this.collections = new Map();\n }\n\n async getCollection({ indexName, forceUpdate = false }: { indexName: string; forceUpdate?: boolean }) {\n let collection = this.collections.get(indexName);\n if (forceUpdate || !collection) {\n try {\n collection = await this.client.getCollection({ name: indexName });\n this.collections.set(indexName, collection);\n return collection;\n } catch {\n throw new MastraError({\n id: 'CHROMA_COLLECTION_GET_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n });\n }\n }\n return collection;\n }\n\n private validateVectorDimensions(vectors: number[][], dimension: number): void {\n for (let i = 0; i < vectors.length; i++) {\n if (vectors?.[i]?.length !== dimension) {\n throw new Error(\n `Vector at index ${i} has invalid dimension ${vectors?.[i]?.length}. Expected ${dimension} dimensions.`,\n );\n }\n }\n }\n\n async upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]> {\n try {\n const collection = await this.getCollection({ indexName });\n\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions(vectors, stats.dimension);\n const generatedIds = ids || vectors.map(() => crypto.randomUUID());\n\n await collection.upsert({\n ids: generatedIds,\n embeddings: vectors,\n metadatas: metadata,\n documents: documents,\n });\n\n return generatedIds;\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_UPSERT_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new MastraError({\n id: 'CHROMA_VECTOR_CREATE_INDEX_INVALID_DIMENSION',\n text: 'Dimension must be a positive integer',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { dimension },\n });\n }\n\n const hnswSpace = spaceMappings[metric] as 'cosine' | 'l2' | 'ip' | undefined;\n\n if (!hnswSpace || !['cosine', 'l2', 'ip'].includes(hnswSpace)) {\n throw new MastraError({\n id: 'CHROMA_VECTOR_CREATE_INDEX_INVALID_METRIC',\n text: `Invalid metric: \"${metric}\". Must be one of: cosine, euclidean, dotproduct`,\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { metric },\n });\n }\n\n try {\n const collection = await this.client.createCollection({\n name: indexName,\n metadata: { dimension },\n configuration: { hnsw: { space: hnswSpace } },\n embeddingFunction: null,\n });\n this.collections.set(indexName, collection);\n } catch (error: any) {\n // Check for 'already exists' error\n const message = error?.message || error?.toString();\n if (message && message.toLowerCase().includes('already exists')) {\n // Fetch collection info and check dimension\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_CREATE_INDEX_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n transformFilter(filter?: ChromaVectorFilter) {\n const translator = new ChromaFilterTranslator();\n const translatedFilter = translator.translate(filter);\n return translatedFilter ? (translatedFilter as Where) : undefined;\n }\n\n async query<T extends Metadata = Metadata>({\n indexName,\n queryVector,\n topK = 10,\n filter,\n includeVector = false,\n documentFilter,\n }: ChromaQueryVectorParams): Promise<QueryResult[]> {\n try {\n const collection = await this.getCollection({ indexName });\n\n const defaultInclude: ['documents', 'metadatas', 'distances'] = ['documents', 'metadatas', 'distances'];\n\n const translatedFilter = this.transformFilter(filter);\n const results = await collection.query<T>({\n queryEmbeddings: [queryVector],\n nResults: topK,\n where: translatedFilter ?? undefined,\n whereDocument: documentFilter ?? undefined,\n include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,\n });\n\n return (results.ids[0] || []).map((id: string, index: number) => ({\n id,\n score: results.distances?.[0]?.[index] || 0,\n metadata: results.metadatas?.[0]?.[index] || {},\n document: results.documents?.[0]?.[index] ?? undefined,\n ...(includeVector && { vector: results.embeddings?.[0]?.[index] || [] }),\n }));\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_QUERY_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async get<T extends Metadata = Metadata>({\n indexName,\n ids,\n filter,\n includeVector = false,\n documentFilter,\n offset,\n limit,\n }: ChromaGetRecordsParams) {\n try {\n const collection = await this.getCollection({ indexName });\n\n const defaultInclude: ['documents', 'metadatas'] = ['documents', 'metadatas'];\n const translatedFilter = this.transformFilter(filter);\n\n const result = await collection.get<T>({\n ids,\n where: translatedFilter ?? undefined,\n whereDocument: documentFilter ?? undefined,\n offset,\n limit,\n include: includeVector ? [...defaultInclude, 'embeddings'] : defaultInclude,\n });\n return result.rows();\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_GET_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n const collections = await this.client.listCollections();\n return collections.map(collection => collection.name);\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_LIST_INDEXES_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n const collection = await this.getCollection({ indexName });\n const count = await collection.count();\n const metadata = collection.metadata as MastraMetadata | undefined;\n const space = collection.configuration.hnsw?.space || collection.configuration.spann?.space || undefined;\n\n return {\n dimension: metadata?.dimension || 0,\n count,\n metric: space ? (spaceMappings[space] as 'cosine' | 'euclidean' | 'dotproduct') : undefined,\n };\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_DESCRIBE_INDEX_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.client.deleteCollection({ name: indexName });\n this.collections.delete(indexName);\n } catch (error: any) {\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_DELETE_INDEX_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n async forkIndex({ indexName, newIndexName }: { indexName: string; newIndexName: string }): Promise<void> {\n try {\n const collection = await this.getCollection({ indexName, forceUpdate: true });\n const forkedCollection = await collection.fork({ name: newIndexName });\n this.collections.set(newIndexName, forkedCollection);\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_INDEX_FORK_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID with the provided vector and/or metadata.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to update.\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {\n if (!update.vector && !update.metadata) {\n throw new MastraError({\n id: 'CHROMA_VECTOR_UPDATE_NO_PAYLOAD',\n text: 'No updates provided for vector',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.USER,\n details: { indexName, id },\n });\n }\n\n try {\n const collection: Collection = await this.getCollection({ indexName });\n\n const updateRecordSet: RecordSet = { ids: [id] };\n\n if (update?.vector) {\n const stats = await this.describeIndex({ indexName });\n this.validateVectorDimensions([update.vector], stats.dimension);\n updateRecordSet.embeddings = [update.vector];\n }\n\n if (update?.metadata) {\n updateRecordSet.metadatas = [update.metadata];\n }\n\n return await collection.update(updateRecordSet);\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_UPDATE_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n\n async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {\n try {\n const collection: Collection = await this.getCollection({ indexName });\n await collection.delete({ ids: [id] });\n } catch (error: any) {\n if (error instanceof MastraError) throw error;\n throw new MastraError(\n {\n id: 'CHROMA_VECTOR_DELETE_FAILED',\n domain: ErrorDomain.MASTRA_VECTOR,\n category: ErrorCategory.THIRD_PARTY,\n details: { indexName, id },\n },\n error,\n );\n }\n }\n}\n","/**\n * Vector store specific prompt that details supported operators and examples.\n * This prompt helps users construct valid filters for Chroma Vector.\n */\nexport const CHROMA_PROMPT = `When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf 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.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nRestrictions:\n- Regex patterns are not supported\n- Element operators are not supported\n- Only $and and $or logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- If multiple top-level fields exist, they're wrapped in $and\n- Only logical operators ($and, $or) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$in\": [...] }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"$or\": [\n { \"inStock\": true },\n { \"preorder\": true }\n ]}\n ]\n}`;\n"]}
|
package/dist/vector/filter.d.ts
CHANGED
|
@@ -4,9 +4,6 @@ type ChromaOperatorValueMap = Omit<OperatorValueMap, '$exists' | '$elemMatch' |
|
|
|
4
4
|
type ChromaLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not'>;
|
|
5
5
|
type ChromaBlacklisted = BlacklistedRootOperators | '$nor' | '$not';
|
|
6
6
|
export type ChromaVectorFilter = VectorFilter<keyof ChromaOperatorValueMap, ChromaOperatorValueMap, ChromaLogicalOperatorValueMap, ChromaBlacklisted>;
|
|
7
|
-
type ChromaDocumentOperatorValueMap = ChromaOperatorValueMap;
|
|
8
|
-
type ChromaDocumentBlacklisted = Exclude<ChromaBlacklisted, '$contains'>;
|
|
9
|
-
export type ChromaVectorDocumentFilter = VectorFilter<keyof ChromaDocumentOperatorValueMap, ChromaDocumentOperatorValueMap, ChromaLogicalOperatorValueMap, ChromaDocumentBlacklisted>;
|
|
10
7
|
/**
|
|
11
8
|
* Translator for Chroma filter queries.
|
|
12
9
|
* Maintains MongoDB-compatible syntax while ensuring proper validation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/vector/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAEf,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,4BA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CAS1B"}
|
package/dist/vector/index.d.ts
CHANGED
|
@@ -1,29 +1,45 @@
|
|
|
1
1
|
import { MastraVector } from '@mastra/core/vector';
|
|
2
2
|
import type { QueryResult, IndexStats, CreateIndexParams, UpsertVectorParams, QueryVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, UpdateVectorParams } from '@mastra/core/vector';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ChromaClientArgs, Where, WhereDocument, Collection, Metadata } from 'chromadb';
|
|
4
|
+
import type { ChromaVectorFilter } from './filter.js';
|
|
4
5
|
interface ChromaUpsertVectorParams extends UpsertVectorParams {
|
|
5
6
|
documents?: string[];
|
|
6
7
|
}
|
|
7
8
|
interface ChromaQueryVectorParams extends QueryVectorParams<ChromaVectorFilter> {
|
|
8
|
-
documentFilter?:
|
|
9
|
+
documentFilter?: WhereDocument | null;
|
|
9
10
|
}
|
|
11
|
+
interface ChromaGetRecordsParams {
|
|
12
|
+
indexName: string;
|
|
13
|
+
ids?: string[];
|
|
14
|
+
filter?: ChromaVectorFilter;
|
|
15
|
+
documentFilter?: WhereDocument | null;
|
|
16
|
+
includeVector?: boolean;
|
|
17
|
+
limit?: number;
|
|
18
|
+
offset?: number;
|
|
19
|
+
}
|
|
20
|
+
type ChromaVectorArgs = ChromaClientArgs & {
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
};
|
|
10
23
|
export declare class ChromaVector extends MastraVector<ChromaVectorFilter> {
|
|
11
24
|
private client;
|
|
12
25
|
private collections;
|
|
13
|
-
constructor(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
getCollection(indexName: string, throwIfNotExists?: boolean): Promise<any>;
|
|
26
|
+
constructor(chromaClientArgs?: ChromaVectorArgs);
|
|
27
|
+
getCollection({ indexName, forceUpdate }: {
|
|
28
|
+
indexName: string;
|
|
29
|
+
forceUpdate?: boolean;
|
|
30
|
+
}): Promise<Collection>;
|
|
21
31
|
private validateVectorDimensions;
|
|
22
32
|
upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]>;
|
|
23
|
-
private HnswSpaceMap;
|
|
24
33
|
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
25
|
-
transformFilter(filter?: ChromaVectorFilter):
|
|
26
|
-
query({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: ChromaQueryVectorParams): Promise<QueryResult[]>;
|
|
34
|
+
transformFilter(filter?: ChromaVectorFilter): Where | undefined;
|
|
35
|
+
query<T extends Metadata = Metadata>({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: ChromaQueryVectorParams): Promise<QueryResult[]>;
|
|
36
|
+
get<T extends Metadata = Metadata>({ indexName, ids, filter, includeVector, documentFilter, offset, limit, }: ChromaGetRecordsParams): Promise<{
|
|
37
|
+
id: string;
|
|
38
|
+
document: string | null | undefined;
|
|
39
|
+
embedding: number[] | undefined;
|
|
40
|
+
metadata: T | null | undefined;
|
|
41
|
+
uri: string | null | undefined;
|
|
42
|
+
}[]>;
|
|
27
43
|
listIndexes(): Promise<string[]>;
|
|
28
44
|
/**
|
|
29
45
|
* Retrieves statistics about a vector index.
|
|
@@ -33,6 +49,10 @@ export declare class ChromaVector extends MastraVector<ChromaVectorFilter> {
|
|
|
33
49
|
*/
|
|
34
50
|
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
35
51
|
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
52
|
+
forkIndex({ indexName, newIndexName }: {
|
|
53
|
+
indexName: string;
|
|
54
|
+
newIndexName: string;
|
|
55
|
+
}): Promise<void>;
|
|
36
56
|
/**
|
|
37
57
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
38
58
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector/index.ts"],"names":[],"mappings":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S,EAAE,YAAY,EAAE,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBxG;;;;;;;;;OASG;IACG,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyC1E,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBzE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/chroma",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.4",
|
|
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
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"chromadb": "^
|
|
23
|
+
"chromadb": "^3.0.11"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@microsoft/api-extractor": "^7.52.8",
|
|
@@ -29,12 +29,13 @@
|
|
|
29
29
|
"tsup": "^8.5.0",
|
|
30
30
|
"typescript": "^5.8.3",
|
|
31
31
|
"vitest": "^3.2.4",
|
|
32
|
-
"@internal/lint": "0.0.
|
|
33
|
-
"@mastra/core": "0.
|
|
34
|
-
"@internal/types-builder": "0.0.
|
|
32
|
+
"@internal/lint": "0.0.30",
|
|
33
|
+
"@mastra/core": "0.14.0",
|
|
34
|
+
"@internal/types-builder": "0.0.5",
|
|
35
|
+
"@internal/storage-test-utils": "0.0.26"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
|
-
"@mastra/core": ">=0.10.7-0 <0.
|
|
38
|
+
"@mastra/core": ">=0.10.7-0 <0.15.0-0"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
41
|
"build": "tsup --silent --config tsup.config.ts",
|
|
@@ -355,6 +355,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
355
355
|
},
|
|
356
356
|
];
|
|
357
357
|
|
|
358
|
+
// @ts-expect-error
|
|
358
359
|
invalidFilters.forEach(filter => {
|
|
359
360
|
expect(() => translator.translate(filter)).toThrow(/Unsupported operator/);
|
|
360
361
|
});
|
|
@@ -390,6 +391,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
390
391
|
{ field: { $all: [{ $eq: 'value' }] } },
|
|
391
392
|
];
|
|
392
393
|
|
|
394
|
+
// @ts-expect-error
|
|
393
395
|
unsupportedFilters.forEach(filter => {
|
|
394
396
|
expect(() => translator.translate(filter)).toThrow(/Unsupported operator/);
|
|
395
397
|
});
|
|
@@ -402,6 +404,7 @@ describe('ChromaFilterTranslator', () => {
|
|
|
402
404
|
it('throws error for non-logical operators at top level', () => {
|
|
403
405
|
const invalidFilters: any = [{ $gt: 100 }, { $in: ['value1', 'value2'] }, { $eq: true }];
|
|
404
406
|
|
|
407
|
+
// @ts-expect-error
|
|
405
408
|
invalidFilters.forEach(filter => {
|
|
406
409
|
expect(() => translator.translate(filter)).toThrow(/Invalid top-level operator/);
|
|
407
410
|
});
|