@mastra/chroma 0.0.0-switch-to-core-20250424015131 → 0.0.0-vector-query-sources-20250516172905
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 +279 -2
- package/dist/_tsup-dts-rollup.d.cts +61 -2
- package/dist/_tsup-dts-rollup.d.ts +61 -2
- package/dist/index.cjs +174 -21
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +174 -22
- package/package.json +5 -5
- package/src/index.ts +1 -0
- package/src/vector/index.test.ts +89 -29
- package/src/vector/index.ts +115 -24
- package/src/vector/prompt.ts +72 -0
package/dist/index.cjs
CHANGED
|
@@ -128,7 +128,7 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
128
128
|
const params = this.normalizeArgs("upsert", args, ["documents"]);
|
|
129
129
|
const { indexName, vectors, metadata, ids, documents } = params;
|
|
130
130
|
const collection = await this.getCollection(indexName);
|
|
131
|
-
const stats = await this.describeIndex(indexName);
|
|
131
|
+
const stats = await this.describeIndex({ indexName });
|
|
132
132
|
this.validateVectorDimensions(vectors, stats.dimension);
|
|
133
133
|
const generatedIds = ids || vectors.map(() => crypto.randomUUID());
|
|
134
134
|
const normalizedMetadata = metadata || vectors.map(() => ({}));
|
|
@@ -157,13 +157,22 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
157
157
|
if (!["cosine", "l2", "ip"].includes(hnswSpace)) {
|
|
158
158
|
throw new Error(`Invalid metric: "${metric}". Must be one of: cosine, euclidean, dotproduct`);
|
|
159
159
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
try {
|
|
161
|
+
await this.client.createCollection({
|
|
162
|
+
name: indexName,
|
|
163
|
+
metadata: {
|
|
164
|
+
dimension,
|
|
165
|
+
"hnsw:space": hnswSpace
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
} catch (error) {
|
|
169
|
+
const message = error?.message || error?.toString();
|
|
170
|
+
if (message && message.toLowerCase().includes("already exists")) {
|
|
171
|
+
await this.validateExistingIndex(indexName, dimension, metric);
|
|
172
|
+
return;
|
|
165
173
|
}
|
|
166
|
-
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
167
176
|
}
|
|
168
177
|
transformFilter(filter) {
|
|
169
178
|
const translator = new ChromaFilterTranslator();
|
|
@@ -194,7 +203,16 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
194
203
|
const collections = await this.client.listCollections();
|
|
195
204
|
return collections.map((collection) => collection);
|
|
196
205
|
}
|
|
197
|
-
|
|
206
|
+
/**
|
|
207
|
+
* Retrieves statistics about a vector index.
|
|
208
|
+
*
|
|
209
|
+
* @param params - The parameters for describing an index
|
|
210
|
+
* @param params.indexName - The name of the index to describe
|
|
211
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
212
|
+
*/
|
|
213
|
+
async describeIndex(...args) {
|
|
214
|
+
const params = this.normalizeArgs("describeIndex", args);
|
|
215
|
+
const { indexName } = params;
|
|
198
216
|
const collection = await this.getCollection(indexName);
|
|
199
217
|
const count = await collection.count();
|
|
200
218
|
const metadata = collection.metadata;
|
|
@@ -205,32 +223,167 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
205
223
|
metric: this.HnswSpaceMap[hnswSpace]
|
|
206
224
|
};
|
|
207
225
|
}
|
|
208
|
-
async deleteIndex(
|
|
226
|
+
async deleteIndex(...args) {
|
|
227
|
+
const params = this.normalizeArgs("deleteIndex", args);
|
|
228
|
+
const { indexName } = params;
|
|
209
229
|
await this.client.deleteCollection({ name: indexName });
|
|
210
230
|
this.collections.delete(indexName);
|
|
211
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
234
|
+
*
|
|
235
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
236
|
+
* @param indexName - The name of the index containing the vector.
|
|
237
|
+
* @param id - The ID of the vector to update.
|
|
238
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
239
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
240
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
241
|
+
* @returns A promise that resolves when the update is complete.
|
|
242
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
243
|
+
*/
|
|
212
244
|
async updateIndexById(indexName, id, update) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
245
|
+
this.logger.warn(
|
|
246
|
+
`Deprecation Warning: updateIndexById() is deprecated.
|
|
247
|
+
Please use updateVector() instead.
|
|
248
|
+
updateIndexById() will be removed on May 20th, 2025.`
|
|
249
|
+
);
|
|
250
|
+
await this.updateVector({ indexName, id, update });
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
254
|
+
* @param indexName - The name of the index containing the vector.
|
|
255
|
+
* @param id - The ID of the vector to update.
|
|
256
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
257
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
258
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
259
|
+
* @returns A promise that resolves when the update is complete.
|
|
260
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
261
|
+
*/
|
|
262
|
+
async updateVector(...args) {
|
|
263
|
+
const params = this.normalizeArgs("updateVector", args);
|
|
264
|
+
const { indexName, id, update } = params;
|
|
265
|
+
try {
|
|
266
|
+
if (!update.vector && !update.metadata) {
|
|
267
|
+
throw new Error("No updates provided");
|
|
268
|
+
}
|
|
269
|
+
const collection = await this.getCollection(indexName, true);
|
|
270
|
+
const updateOptions = { ids: [id] };
|
|
271
|
+
if (update?.vector) {
|
|
272
|
+
const stats = await this.describeIndex({ indexName });
|
|
273
|
+
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
274
|
+
updateOptions.embeddings = [update.vector];
|
|
275
|
+
}
|
|
276
|
+
if (update?.metadata) {
|
|
277
|
+
updateOptions.metadatas = [update.metadata];
|
|
278
|
+
}
|
|
279
|
+
return await collection.update(updateOptions);
|
|
280
|
+
} catch (error) {
|
|
281
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
223
282
|
}
|
|
224
|
-
return await collection.update(updateOptions);
|
|
225
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
286
|
+
*
|
|
287
|
+
* Deletes a vector by its ID.
|
|
288
|
+
* @param indexName - The name of the index containing the vector.
|
|
289
|
+
* @param id - The ID of the vector to delete.
|
|
290
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
291
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
292
|
+
*/
|
|
226
293
|
async deleteIndexById(indexName, id) {
|
|
294
|
+
this.logger.warn(
|
|
295
|
+
`Deprecation Warning: deleteIndexById() is deprecated. Please use deleteVector() instead. deleteIndexById() will be removed on May 20th.`
|
|
296
|
+
);
|
|
297
|
+
await this.deleteVector(indexName, id);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Deletes a vector by its ID.
|
|
301
|
+
* @param indexName - The name of the index containing the vector.
|
|
302
|
+
* @param id - The ID of the vector to delete.
|
|
303
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
304
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
305
|
+
*/
|
|
306
|
+
async deleteVector(...args) {
|
|
307
|
+
const params = this.normalizeArgs("deleteVector", args);
|
|
308
|
+
const { indexName, id } = params;
|
|
227
309
|
try {
|
|
228
310
|
const collection = await this.getCollection(indexName, true);
|
|
229
311
|
await collection.delete({ ids: [id] });
|
|
230
312
|
} catch (error) {
|
|
231
|
-
throw new Error(`Failed to delete
|
|
313
|
+
throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
232
314
|
}
|
|
233
315
|
}
|
|
234
316
|
};
|
|
235
317
|
|
|
318
|
+
// src/vector/prompt.ts
|
|
319
|
+
var CHROMA_PROMPT = `When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
320
|
+
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
321
|
+
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.
|
|
322
|
+
|
|
323
|
+
Basic Comparison Operators:
|
|
324
|
+
- $eq: Exact match (default when using field: value)
|
|
325
|
+
Example: { "category": "electronics" }
|
|
326
|
+
- $ne: Not equal
|
|
327
|
+
Example: { "category": { "$ne": "electronics" } }
|
|
328
|
+
- $gt: Greater than
|
|
329
|
+
Example: { "price": { "$gt": 100 } }
|
|
330
|
+
- $gte: Greater than or equal
|
|
331
|
+
Example: { "price": { "$gte": 100 } }
|
|
332
|
+
- $lt: Less than
|
|
333
|
+
Example: { "price": { "$lt": 100 } }
|
|
334
|
+
- $lte: Less than or equal
|
|
335
|
+
Example: { "price": { "$lte": 100 } }
|
|
336
|
+
|
|
337
|
+
Array Operators:
|
|
338
|
+
- $in: Match any value in array
|
|
339
|
+
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
340
|
+
- $nin: Does not match any value in array
|
|
341
|
+
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
342
|
+
|
|
343
|
+
Logical Operators:
|
|
344
|
+
- $and: Logical AND
|
|
345
|
+
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
346
|
+
- $or: Logical OR
|
|
347
|
+
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
348
|
+
|
|
349
|
+
Restrictions:
|
|
350
|
+
- Regex patterns are not supported
|
|
351
|
+
- Element operators are not supported
|
|
352
|
+
- Only $and and $or logical operators are supported
|
|
353
|
+
- Nested fields are supported using dot notation
|
|
354
|
+
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
355
|
+
- Empty arrays in $in/$nin will return no results
|
|
356
|
+
- If multiple top-level fields exist, they're wrapped in $and
|
|
357
|
+
- Only logical operators ($and, $or) can be used at the top level
|
|
358
|
+
- All other operators must be used within a field condition
|
|
359
|
+
Valid: { "field": { "$gt": 100 } }
|
|
360
|
+
Valid: { "$and": [...] }
|
|
361
|
+
Invalid: { "$gt": 100 }
|
|
362
|
+
Invalid: { "$in": [...] }
|
|
363
|
+
- Logical operators must contain field conditions, not direct operators
|
|
364
|
+
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
365
|
+
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
366
|
+
- Logical operators ($and, $or):
|
|
367
|
+
- Can only be used at top level or nested within other logical operators
|
|
368
|
+
- Can not be used on a field level, or be nested inside a field
|
|
369
|
+
- Can not be used inside an operator
|
|
370
|
+
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
371
|
+
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
372
|
+
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
373
|
+
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
374
|
+
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
375
|
+
|
|
376
|
+
Example Complex Query:
|
|
377
|
+
{
|
|
378
|
+
"$and": [
|
|
379
|
+
{ "category": { "$in": ["electronics", "computers"] } },
|
|
380
|
+
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
381
|
+
{ "$or": [
|
|
382
|
+
{ "inStock": true },
|
|
383
|
+
{ "preorder": true }
|
|
384
|
+
]}
|
|
385
|
+
]
|
|
386
|
+
}`;
|
|
387
|
+
|
|
388
|
+
exports.CHROMA_PROMPT = CHROMA_PROMPT;
|
|
236
389
|
exports.ChromaVector = ChromaVector;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -126,7 +126,7 @@ var ChromaVector = class extends MastraVector {
|
|
|
126
126
|
const params = this.normalizeArgs("upsert", args, ["documents"]);
|
|
127
127
|
const { indexName, vectors, metadata, ids, documents } = params;
|
|
128
128
|
const collection = await this.getCollection(indexName);
|
|
129
|
-
const stats = await this.describeIndex(indexName);
|
|
129
|
+
const stats = await this.describeIndex({ indexName });
|
|
130
130
|
this.validateVectorDimensions(vectors, stats.dimension);
|
|
131
131
|
const generatedIds = ids || vectors.map(() => crypto.randomUUID());
|
|
132
132
|
const normalizedMetadata = metadata || vectors.map(() => ({}));
|
|
@@ -155,13 +155,22 @@ var ChromaVector = class extends MastraVector {
|
|
|
155
155
|
if (!["cosine", "l2", "ip"].includes(hnswSpace)) {
|
|
156
156
|
throw new Error(`Invalid metric: "${metric}". Must be one of: cosine, euclidean, dotproduct`);
|
|
157
157
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
try {
|
|
159
|
+
await this.client.createCollection({
|
|
160
|
+
name: indexName,
|
|
161
|
+
metadata: {
|
|
162
|
+
dimension,
|
|
163
|
+
"hnsw:space": hnswSpace
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
} catch (error) {
|
|
167
|
+
const message = error?.message || error?.toString();
|
|
168
|
+
if (message && message.toLowerCase().includes("already exists")) {
|
|
169
|
+
await this.validateExistingIndex(indexName, dimension, metric);
|
|
170
|
+
return;
|
|
163
171
|
}
|
|
164
|
-
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
165
174
|
}
|
|
166
175
|
transformFilter(filter) {
|
|
167
176
|
const translator = new ChromaFilterTranslator();
|
|
@@ -192,7 +201,16 @@ var ChromaVector = class extends MastraVector {
|
|
|
192
201
|
const collections = await this.client.listCollections();
|
|
193
202
|
return collections.map((collection) => collection);
|
|
194
203
|
}
|
|
195
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Retrieves statistics about a vector index.
|
|
206
|
+
*
|
|
207
|
+
* @param params - The parameters for describing an index
|
|
208
|
+
* @param params.indexName - The name of the index to describe
|
|
209
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
210
|
+
*/
|
|
211
|
+
async describeIndex(...args) {
|
|
212
|
+
const params = this.normalizeArgs("describeIndex", args);
|
|
213
|
+
const { indexName } = params;
|
|
196
214
|
const collection = await this.getCollection(indexName);
|
|
197
215
|
const count = await collection.count();
|
|
198
216
|
const metadata = collection.metadata;
|
|
@@ -203,32 +221,166 @@ var ChromaVector = class extends MastraVector {
|
|
|
203
221
|
metric: this.HnswSpaceMap[hnswSpace]
|
|
204
222
|
};
|
|
205
223
|
}
|
|
206
|
-
async deleteIndex(
|
|
224
|
+
async deleteIndex(...args) {
|
|
225
|
+
const params = this.normalizeArgs("deleteIndex", args);
|
|
226
|
+
const { indexName } = params;
|
|
207
227
|
await this.client.deleteCollection({ name: indexName });
|
|
208
228
|
this.collections.delete(indexName);
|
|
209
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
232
|
+
*
|
|
233
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
234
|
+
* @param indexName - The name of the index containing the vector.
|
|
235
|
+
* @param id - The ID of the vector to update.
|
|
236
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
237
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
238
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
239
|
+
* @returns A promise that resolves when the update is complete.
|
|
240
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
241
|
+
*/
|
|
210
242
|
async updateIndexById(indexName, id, update) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
243
|
+
this.logger.warn(
|
|
244
|
+
`Deprecation Warning: updateIndexById() is deprecated.
|
|
245
|
+
Please use updateVector() instead.
|
|
246
|
+
updateIndexById() will be removed on May 20th, 2025.`
|
|
247
|
+
);
|
|
248
|
+
await this.updateVector({ indexName, id, update });
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
252
|
+
* @param indexName - The name of the index containing the vector.
|
|
253
|
+
* @param id - The ID of the vector to update.
|
|
254
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
255
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
256
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
257
|
+
* @returns A promise that resolves when the update is complete.
|
|
258
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
259
|
+
*/
|
|
260
|
+
async updateVector(...args) {
|
|
261
|
+
const params = this.normalizeArgs("updateVector", args);
|
|
262
|
+
const { indexName, id, update } = params;
|
|
263
|
+
try {
|
|
264
|
+
if (!update.vector && !update.metadata) {
|
|
265
|
+
throw new Error("No updates provided");
|
|
266
|
+
}
|
|
267
|
+
const collection = await this.getCollection(indexName, true);
|
|
268
|
+
const updateOptions = { ids: [id] };
|
|
269
|
+
if (update?.vector) {
|
|
270
|
+
const stats = await this.describeIndex({ indexName });
|
|
271
|
+
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
272
|
+
updateOptions.embeddings = [update.vector];
|
|
273
|
+
}
|
|
274
|
+
if (update?.metadata) {
|
|
275
|
+
updateOptions.metadatas = [update.metadata];
|
|
276
|
+
}
|
|
277
|
+
return await collection.update(updateOptions);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
221
280
|
}
|
|
222
|
-
return await collection.update(updateOptions);
|
|
223
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
284
|
+
*
|
|
285
|
+
* Deletes a vector by its ID.
|
|
286
|
+
* @param indexName - The name of the index containing the vector.
|
|
287
|
+
* @param id - The ID of the vector to delete.
|
|
288
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
289
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
290
|
+
*/
|
|
224
291
|
async deleteIndexById(indexName, id) {
|
|
292
|
+
this.logger.warn(
|
|
293
|
+
`Deprecation Warning: deleteIndexById() is deprecated. Please use deleteVector() instead. deleteIndexById() will be removed on May 20th.`
|
|
294
|
+
);
|
|
295
|
+
await this.deleteVector(indexName, id);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Deletes a vector by its ID.
|
|
299
|
+
* @param indexName - The name of the index containing the vector.
|
|
300
|
+
* @param id - The ID of the vector to delete.
|
|
301
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
302
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
303
|
+
*/
|
|
304
|
+
async deleteVector(...args) {
|
|
305
|
+
const params = this.normalizeArgs("deleteVector", args);
|
|
306
|
+
const { indexName, id } = params;
|
|
225
307
|
try {
|
|
226
308
|
const collection = await this.getCollection(indexName, true);
|
|
227
309
|
await collection.delete({ ids: [id] });
|
|
228
310
|
} catch (error) {
|
|
229
|
-
throw new Error(`Failed to delete
|
|
311
|
+
throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
230
312
|
}
|
|
231
313
|
}
|
|
232
314
|
};
|
|
233
315
|
|
|
234
|
-
|
|
316
|
+
// src/vector/prompt.ts
|
|
317
|
+
var CHROMA_PROMPT = `When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
318
|
+
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
319
|
+
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.
|
|
320
|
+
|
|
321
|
+
Basic Comparison Operators:
|
|
322
|
+
- $eq: Exact match (default when using field: value)
|
|
323
|
+
Example: { "category": "electronics" }
|
|
324
|
+
- $ne: Not equal
|
|
325
|
+
Example: { "category": { "$ne": "electronics" } }
|
|
326
|
+
- $gt: Greater than
|
|
327
|
+
Example: { "price": { "$gt": 100 } }
|
|
328
|
+
- $gte: Greater than or equal
|
|
329
|
+
Example: { "price": { "$gte": 100 } }
|
|
330
|
+
- $lt: Less than
|
|
331
|
+
Example: { "price": { "$lt": 100 } }
|
|
332
|
+
- $lte: Less than or equal
|
|
333
|
+
Example: { "price": { "$lte": 100 } }
|
|
334
|
+
|
|
335
|
+
Array Operators:
|
|
336
|
+
- $in: Match any value in array
|
|
337
|
+
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
338
|
+
- $nin: Does not match any value in array
|
|
339
|
+
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
340
|
+
|
|
341
|
+
Logical Operators:
|
|
342
|
+
- $and: Logical AND
|
|
343
|
+
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
344
|
+
- $or: Logical OR
|
|
345
|
+
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
346
|
+
|
|
347
|
+
Restrictions:
|
|
348
|
+
- Regex patterns are not supported
|
|
349
|
+
- Element operators are not supported
|
|
350
|
+
- Only $and and $or logical operators are supported
|
|
351
|
+
- Nested fields are supported using dot notation
|
|
352
|
+
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
353
|
+
- Empty arrays in $in/$nin will return no results
|
|
354
|
+
- If multiple top-level fields exist, they're wrapped in $and
|
|
355
|
+
- Only logical operators ($and, $or) can be used at the top level
|
|
356
|
+
- All other operators must be used within a field condition
|
|
357
|
+
Valid: { "field": { "$gt": 100 } }
|
|
358
|
+
Valid: { "$and": [...] }
|
|
359
|
+
Invalid: { "$gt": 100 }
|
|
360
|
+
Invalid: { "$in": [...] }
|
|
361
|
+
- Logical operators must contain field conditions, not direct operators
|
|
362
|
+
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
363
|
+
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
364
|
+
- Logical operators ($and, $or):
|
|
365
|
+
- Can only be used at top level or nested within other logical operators
|
|
366
|
+
- Can not be used on a field level, or be nested inside a field
|
|
367
|
+
- Can not be used inside an operator
|
|
368
|
+
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
369
|
+
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
370
|
+
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
371
|
+
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
372
|
+
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
373
|
+
|
|
374
|
+
Example Complex Query:
|
|
375
|
+
{
|
|
376
|
+
"$and": [
|
|
377
|
+
{ "category": { "$in": ["electronics", "computers"] } },
|
|
378
|
+
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
379
|
+
{ "$or": [
|
|
380
|
+
{ "inStock": true },
|
|
381
|
+
{ "preorder": true }
|
|
382
|
+
]}
|
|
383
|
+
]
|
|
384
|
+
}`;
|
|
385
|
+
|
|
386
|
+
export { CHROMA_PROMPT, ChromaVector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/chroma",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-vector-query-sources-20250516172905",
|
|
4
4
|
"description": "Chroma vector store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"chromadb": "^2.2.0",
|
|
24
|
-
"@mastra/core": "0.0.0-
|
|
24
|
+
"@mastra/core": "0.0.0-vector-query-sources-20250516172905"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@microsoft/api-extractor": "^7.52.
|
|
27
|
+
"@microsoft/api-extractor": "^7.52.5",
|
|
28
28
|
"@types/node": "^20.17.27",
|
|
29
29
|
"eslint": "^9.23.0",
|
|
30
30
|
"tsup": "^8.4.0",
|
|
31
31
|
"typescript": "^5.8.2",
|
|
32
|
-
"vitest": "^3.
|
|
33
|
-
"@internal/lint": "0.0.
|
|
32
|
+
"vitest": "^3.1.2",
|
|
33
|
+
"@internal/lint": "0.0.0-vector-query-sources-20250516172905"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
package/src/index.ts
CHANGED