@mastra/chroma 0.0.0-vector-query-sources-20250516172905 → 0.0.0-vector-query-tool-provider-options-20250828222356
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +361 -4
- package/LICENSE.md +12 -4
- package/README.md +47 -21
- package/dist/index.cjs +280 -157
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +277 -154
- package/dist/index.js.map +1 -0
- package/dist/vector/filter.d.ts +19 -0
- package/dist/vector/filter.d.ts.map +1 -0
- package/dist/vector/index.d.ts +70 -0
- package/dist/vector/index.d.ts.map +1 -0
- package/dist/vector/prompt.d.ts +6 -0
- package/dist/vector/prompt.d.ts.map +1 -0
- package/package.json +18 -13
- package/src/vector/filter.test.ts +27 -19
- package/src/vector/filter.ts +28 -5
- package/src/vector/index.test.ts +142 -129
- package/src/vector/index.ts +306 -200
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +17 -0
- package/dist/_tsup-dts-rollup.d.cts +0 -126
- package/dist/_tsup-dts-rollup.d.ts +0 -126
- package/dist/index.d.cts +0 -2
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var error = require('@mastra/core/error');
|
|
3
4
|
var vector = require('@mastra/core/vector');
|
|
4
5
|
var chromadb = require('chromadb');
|
|
5
6
|
var filter = require('@mastra/core/vector/filter');
|
|
@@ -23,7 +24,7 @@ var ChromaFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
|
23
24
|
}
|
|
24
25
|
translateNode(node, currentPath = "") {
|
|
25
26
|
if (this.isRegex(node)) {
|
|
26
|
-
throw new Error("Regex is
|
|
27
|
+
throw new Error("Regex is supported in Chroma via the `documentFilter` argument");
|
|
27
28
|
}
|
|
28
29
|
if (this.isPrimitive(node)) return this.normalizeComparisonValue(node);
|
|
29
30
|
if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };
|
|
@@ -32,6 +33,9 @@ var ChromaFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
|
32
33
|
if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {
|
|
33
34
|
const [operator, value] = firstEntry;
|
|
34
35
|
const translated = this.translateOperator(operator, value);
|
|
36
|
+
if (this.isLogicalOperator(operator) && Array.isArray(translated) && translated.length === 1) {
|
|
37
|
+
return translated[0];
|
|
38
|
+
}
|
|
35
39
|
return this.isLogicalOperator(operator) ? { [operator]: translated } : translated;
|
|
36
40
|
}
|
|
37
41
|
const result = {};
|
|
@@ -89,31 +93,46 @@ var ChromaFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
|
89
93
|
};
|
|
90
94
|
|
|
91
95
|
// src/vector/index.ts
|
|
96
|
+
var spaceMappings = {
|
|
97
|
+
cosine: "cosine",
|
|
98
|
+
euclidean: "l2",
|
|
99
|
+
dotproduct: "ip",
|
|
100
|
+
l2: "euclidean",
|
|
101
|
+
ip: "dotproduct"
|
|
102
|
+
};
|
|
92
103
|
var ChromaVector = class extends vector.MastraVector {
|
|
93
104
|
client;
|
|
94
105
|
collections;
|
|
95
|
-
constructor({
|
|
96
|
-
path,
|
|
97
|
-
auth
|
|
98
|
-
}) {
|
|
106
|
+
constructor(chromaClientArgs) {
|
|
99
107
|
super();
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
if (chromaClientArgs?.apiKey) {
|
|
109
|
+
this.client = new chromadb.CloudClient({
|
|
110
|
+
apiKey: chromaClientArgs.apiKey,
|
|
111
|
+
tenant: chromaClientArgs.tenant,
|
|
112
|
+
database: chromaClientArgs.database
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
this.client = new chromadb.ChromaClient(chromaClientArgs);
|
|
116
|
+
}
|
|
104
117
|
this.collections = /* @__PURE__ */ new Map();
|
|
105
118
|
}
|
|
106
|
-
async getCollection(indexName,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
119
|
+
async getCollection({ indexName, forceUpdate = false }) {
|
|
120
|
+
let collection = this.collections.get(indexName);
|
|
121
|
+
if (forceUpdate || !collection) {
|
|
122
|
+
try {
|
|
123
|
+
collection = await this.client.getCollection({ name: indexName });
|
|
124
|
+
this.collections.set(indexName, collection);
|
|
125
|
+
return collection;
|
|
126
|
+
} catch {
|
|
127
|
+
throw new error.MastraError({
|
|
128
|
+
id: "CHROMA_COLLECTION_GET_FAILED",
|
|
129
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
130
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
131
|
+
details: { indexName }
|
|
132
|
+
});
|
|
113
133
|
}
|
|
114
|
-
return null;
|
|
115
134
|
}
|
|
116
|
-
return
|
|
135
|
+
return collection;
|
|
117
136
|
}
|
|
118
137
|
validateVectorDimensions(vectors, dimension) {
|
|
119
138
|
for (let i = 0; i < vectors.length; i++) {
|
|
@@ -124,130 +143,234 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
124
143
|
}
|
|
125
144
|
}
|
|
126
145
|
}
|
|
127
|
-
async upsert(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
})
|
|
141
|
-
|
|
146
|
+
async upsert({ indexName, vectors, metadata, ids, documents }) {
|
|
147
|
+
try {
|
|
148
|
+
const collection = await this.getCollection({ indexName });
|
|
149
|
+
const stats = await this.describeIndex({ indexName });
|
|
150
|
+
this.validateVectorDimensions(vectors, stats.dimension);
|
|
151
|
+
const generatedIds = ids || vectors.map(() => crypto.randomUUID());
|
|
152
|
+
await collection.upsert({
|
|
153
|
+
ids: generatedIds,
|
|
154
|
+
embeddings: vectors,
|
|
155
|
+
metadatas: metadata,
|
|
156
|
+
documents
|
|
157
|
+
});
|
|
158
|
+
return generatedIds;
|
|
159
|
+
} catch (error$1) {
|
|
160
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
161
|
+
throw new error.MastraError(
|
|
162
|
+
{
|
|
163
|
+
id: "CHROMA_VECTOR_UPSERT_FAILED",
|
|
164
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
165
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
166
|
+
details: { indexName }
|
|
167
|
+
},
|
|
168
|
+
error$1
|
|
169
|
+
);
|
|
170
|
+
}
|
|
142
171
|
}
|
|
143
|
-
|
|
144
|
-
cosine: "cosine",
|
|
145
|
-
euclidean: "l2",
|
|
146
|
-
dotproduct: "ip",
|
|
147
|
-
l2: "euclidean",
|
|
148
|
-
ip: "dotproduct"
|
|
149
|
-
};
|
|
150
|
-
async createIndex(...args) {
|
|
151
|
-
const params = this.normalizeArgs("createIndex", args);
|
|
152
|
-
const { indexName, dimension, metric = "cosine" } = params;
|
|
172
|
+
async createIndex({ indexName, dimension, metric = "cosine" }) {
|
|
153
173
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
154
|
-
throw new
|
|
174
|
+
throw new error.MastraError({
|
|
175
|
+
id: "CHROMA_VECTOR_CREATE_INDEX_INVALID_DIMENSION",
|
|
176
|
+
text: "Dimension must be a positive integer",
|
|
177
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
178
|
+
category: error.ErrorCategory.USER,
|
|
179
|
+
details: { dimension }
|
|
180
|
+
});
|
|
155
181
|
}
|
|
156
|
-
const hnswSpace =
|
|
157
|
-
if (!["cosine", "l2", "ip"].includes(hnswSpace)) {
|
|
158
|
-
throw new
|
|
182
|
+
const hnswSpace = spaceMappings[metric];
|
|
183
|
+
if (!hnswSpace || !["cosine", "l2", "ip"].includes(hnswSpace)) {
|
|
184
|
+
throw new error.MastraError({
|
|
185
|
+
id: "CHROMA_VECTOR_CREATE_INDEX_INVALID_METRIC",
|
|
186
|
+
text: `Invalid metric: "${metric}". Must be one of: cosine, euclidean, dotproduct`,
|
|
187
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
188
|
+
category: error.ErrorCategory.USER,
|
|
189
|
+
details: { metric }
|
|
190
|
+
});
|
|
159
191
|
}
|
|
160
192
|
try {
|
|
161
|
-
await this.client.createCollection({
|
|
193
|
+
const collection = await this.client.createCollection({
|
|
162
194
|
name: indexName,
|
|
163
|
-
metadata: {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
195
|
+
metadata: { dimension },
|
|
196
|
+
configuration: { hnsw: { space: hnswSpace } },
|
|
197
|
+
embeddingFunction: null
|
|
167
198
|
});
|
|
168
|
-
|
|
169
|
-
|
|
199
|
+
this.collections.set(indexName, collection);
|
|
200
|
+
} catch (error$1) {
|
|
201
|
+
const message = error$1?.message || error$1?.toString();
|
|
170
202
|
if (message && message.toLowerCase().includes("already exists")) {
|
|
171
203
|
await this.validateExistingIndex(indexName, dimension, metric);
|
|
172
204
|
return;
|
|
173
205
|
}
|
|
174
|
-
throw error
|
|
206
|
+
throw new error.MastraError(
|
|
207
|
+
{
|
|
208
|
+
id: "CHROMA_VECTOR_CREATE_INDEX_FAILED",
|
|
209
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
210
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
211
|
+
details: { indexName }
|
|
212
|
+
},
|
|
213
|
+
error$1
|
|
214
|
+
);
|
|
175
215
|
}
|
|
176
216
|
}
|
|
177
217
|
transformFilter(filter) {
|
|
178
218
|
const translator = new ChromaFilterTranslator();
|
|
179
|
-
|
|
219
|
+
const translatedFilter = translator.translate(filter);
|
|
220
|
+
return translatedFilter ? translatedFilter : void 0;
|
|
180
221
|
}
|
|
181
|
-
async query(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
222
|
+
async query({
|
|
223
|
+
indexName,
|
|
224
|
+
queryVector,
|
|
225
|
+
topK = 10,
|
|
226
|
+
filter,
|
|
227
|
+
includeVector = false,
|
|
228
|
+
documentFilter
|
|
229
|
+
}) {
|
|
230
|
+
try {
|
|
231
|
+
const collection = await this.getCollection({ indexName });
|
|
232
|
+
const defaultInclude = ["documents", "metadatas", "distances"];
|
|
233
|
+
const translatedFilter = this.transformFilter(filter);
|
|
234
|
+
const results = await collection.query({
|
|
235
|
+
queryEmbeddings: [queryVector],
|
|
236
|
+
nResults: topK,
|
|
237
|
+
where: translatedFilter ?? void 0,
|
|
238
|
+
whereDocument: documentFilter ?? void 0,
|
|
239
|
+
include: includeVector ? [...defaultInclude, "embeddings"] : defaultInclude
|
|
240
|
+
});
|
|
241
|
+
return (results.ids[0] || []).map((id, index) => ({
|
|
242
|
+
id,
|
|
243
|
+
score: results.distances?.[0]?.[index] || 0,
|
|
244
|
+
metadata: results.metadatas?.[0]?.[index] || {},
|
|
245
|
+
document: results.documents?.[0]?.[index] ?? void 0,
|
|
246
|
+
...includeVector && { vector: results.embeddings?.[0]?.[index] || [] }
|
|
247
|
+
}));
|
|
248
|
+
} catch (error$1) {
|
|
249
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
250
|
+
throw new error.MastraError(
|
|
251
|
+
{
|
|
252
|
+
id: "CHROMA_VECTOR_QUERY_FAILED",
|
|
253
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
254
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
255
|
+
details: { indexName }
|
|
256
|
+
},
|
|
257
|
+
error$1
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async get({
|
|
262
|
+
indexName,
|
|
263
|
+
ids,
|
|
264
|
+
filter,
|
|
265
|
+
includeVector = false,
|
|
266
|
+
documentFilter,
|
|
267
|
+
offset,
|
|
268
|
+
limit
|
|
269
|
+
}) {
|
|
270
|
+
try {
|
|
271
|
+
const collection = await this.getCollection({ indexName });
|
|
272
|
+
const defaultInclude = ["documents", "metadatas"];
|
|
273
|
+
const translatedFilter = this.transformFilter(filter);
|
|
274
|
+
const result = await collection.get({
|
|
275
|
+
ids,
|
|
276
|
+
where: translatedFilter ?? void 0,
|
|
277
|
+
whereDocument: documentFilter ?? void 0,
|
|
278
|
+
offset,
|
|
279
|
+
limit,
|
|
280
|
+
include: includeVector ? [...defaultInclude, "embeddings"] : defaultInclude
|
|
281
|
+
});
|
|
282
|
+
return result.rows();
|
|
283
|
+
} catch (error$1) {
|
|
284
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
285
|
+
throw new error.MastraError(
|
|
286
|
+
{
|
|
287
|
+
id: "CHROMA_VECTOR_GET_FAILED",
|
|
288
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
289
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
290
|
+
details: { indexName }
|
|
291
|
+
},
|
|
292
|
+
error$1
|
|
293
|
+
);
|
|
294
|
+
}
|
|
201
295
|
}
|
|
202
296
|
async listIndexes() {
|
|
203
|
-
|
|
204
|
-
|
|
297
|
+
try {
|
|
298
|
+
const collections = await this.client.listCollections();
|
|
299
|
+
return collections.map((collection) => collection.name);
|
|
300
|
+
} catch (error$1) {
|
|
301
|
+
throw new error.MastraError(
|
|
302
|
+
{
|
|
303
|
+
id: "CHROMA_VECTOR_LIST_INDEXES_FAILED",
|
|
304
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
305
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
306
|
+
},
|
|
307
|
+
error$1
|
|
308
|
+
);
|
|
309
|
+
}
|
|
205
310
|
}
|
|
206
311
|
/**
|
|
207
312
|
* Retrieves statistics about a vector index.
|
|
208
313
|
*
|
|
209
|
-
* @param
|
|
210
|
-
* @param params.indexName - The name of the index to describe
|
|
314
|
+
* @param {string} indexName - The name of the index to describe
|
|
211
315
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
212
316
|
*/
|
|
213
|
-
async describeIndex(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
317
|
+
async describeIndex({ indexName }) {
|
|
318
|
+
try {
|
|
319
|
+
const collection = await this.getCollection({ indexName });
|
|
320
|
+
const count = await collection.count();
|
|
321
|
+
const metadata = collection.metadata;
|
|
322
|
+
const space = collection.configuration.hnsw?.space || collection.configuration.spann?.space || void 0;
|
|
323
|
+
return {
|
|
324
|
+
dimension: metadata?.dimension || 0,
|
|
325
|
+
count,
|
|
326
|
+
metric: space ? spaceMappings[space] : void 0
|
|
327
|
+
};
|
|
328
|
+
} catch (error$1) {
|
|
329
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
330
|
+
throw new error.MastraError(
|
|
331
|
+
{
|
|
332
|
+
id: "CHROMA_VECTOR_DESCRIBE_INDEX_FAILED",
|
|
333
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
334
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
335
|
+
details: { indexName }
|
|
336
|
+
},
|
|
337
|
+
error$1
|
|
338
|
+
);
|
|
339
|
+
}
|
|
225
340
|
}
|
|
226
|
-
async deleteIndex(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
341
|
+
async deleteIndex({ indexName }) {
|
|
342
|
+
try {
|
|
343
|
+
await this.client.deleteCollection({ name: indexName });
|
|
344
|
+
this.collections.delete(indexName);
|
|
345
|
+
} catch (error$1) {
|
|
346
|
+
throw new error.MastraError(
|
|
347
|
+
{
|
|
348
|
+
id: "CHROMA_VECTOR_DELETE_INDEX_FAILED",
|
|
349
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
350
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
351
|
+
details: { indexName }
|
|
352
|
+
},
|
|
353
|
+
error$1
|
|
354
|
+
);
|
|
355
|
+
}
|
|
231
356
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
);
|
|
250
|
-
await this.updateVector({ indexName, id, update });
|
|
357
|
+
async forkIndex({ indexName, newIndexName }) {
|
|
358
|
+
try {
|
|
359
|
+
const collection = await this.getCollection({ indexName, forceUpdate: true });
|
|
360
|
+
const forkedCollection = await collection.fork({ name: newIndexName });
|
|
361
|
+
this.collections.set(newIndexName, forkedCollection);
|
|
362
|
+
} catch (error$1) {
|
|
363
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
364
|
+
throw new error.MastraError(
|
|
365
|
+
{
|
|
366
|
+
id: "CHROMA_INDEX_FORK_FAILED",
|
|
367
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
368
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
369
|
+
details: { indexName }
|
|
370
|
+
},
|
|
371
|
+
error$1
|
|
372
|
+
);
|
|
373
|
+
}
|
|
251
374
|
}
|
|
252
375
|
/**
|
|
253
376
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
@@ -259,58 +382,56 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
259
382
|
* @returns A promise that resolves when the update is complete.
|
|
260
383
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
261
384
|
*/
|
|
262
|
-
async updateVector(
|
|
263
|
-
|
|
264
|
-
|
|
385
|
+
async updateVector({ indexName, id, update }) {
|
|
386
|
+
if (!update.vector && !update.metadata) {
|
|
387
|
+
throw new error.MastraError({
|
|
388
|
+
id: "CHROMA_VECTOR_UPDATE_NO_PAYLOAD",
|
|
389
|
+
text: "No updates provided for vector",
|
|
390
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
391
|
+
category: error.ErrorCategory.USER,
|
|
392
|
+
details: { indexName, id }
|
|
393
|
+
});
|
|
394
|
+
}
|
|
265
395
|
try {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
const collection = await this.getCollection(indexName, true);
|
|
270
|
-
const updateOptions = { ids: [id] };
|
|
396
|
+
const collection = await this.getCollection({ indexName });
|
|
397
|
+
const updateRecordSet = { ids: [id] };
|
|
271
398
|
if (update?.vector) {
|
|
272
399
|
const stats = await this.describeIndex({ indexName });
|
|
273
400
|
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
274
|
-
|
|
401
|
+
updateRecordSet.embeddings = [update.vector];
|
|
275
402
|
}
|
|
276
403
|
if (update?.metadata) {
|
|
277
|
-
|
|
404
|
+
updateRecordSet.metadatas = [update.metadata];
|
|
278
405
|
}
|
|
279
|
-
return await collection.update(
|
|
280
|
-
} catch (error) {
|
|
281
|
-
|
|
406
|
+
return await collection.update(updateRecordSet);
|
|
407
|
+
} catch (error$1) {
|
|
408
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
409
|
+
throw new error.MastraError(
|
|
410
|
+
{
|
|
411
|
+
id: "CHROMA_VECTOR_UPDATE_FAILED",
|
|
412
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
413
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
414
|
+
details: { indexName, id }
|
|
415
|
+
},
|
|
416
|
+
error$1
|
|
417
|
+
);
|
|
282
418
|
}
|
|
283
419
|
}
|
|
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
|
-
*/
|
|
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;
|
|
420
|
+
async deleteVector({ indexName, id }) {
|
|
309
421
|
try {
|
|
310
|
-
const collection = await this.getCollection(indexName
|
|
422
|
+
const collection = await this.getCollection({ indexName });
|
|
311
423
|
await collection.delete({ ids: [id] });
|
|
312
|
-
} catch (error) {
|
|
313
|
-
|
|
424
|
+
} catch (error$1) {
|
|
425
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
426
|
+
throw new error.MastraError(
|
|
427
|
+
{
|
|
428
|
+
id: "CHROMA_VECTOR_DELETE_FAILED",
|
|
429
|
+
domain: error.ErrorDomain.MASTRA_VECTOR,
|
|
430
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
431
|
+
details: { indexName, id }
|
|
432
|
+
},
|
|
433
|
+
error$1
|
|
434
|
+
);
|
|
314
435
|
}
|
|
315
436
|
}
|
|
316
437
|
};
|
|
@@ -387,3 +508,5 @@ Example Complex Query:
|
|
|
387
508
|
|
|
388
509
|
exports.CHROMA_PROMPT = CHROMA_PROMPT;
|
|
389
510
|
exports.ChromaVector = ChromaVector;
|
|
511
|
+
//# sourceMappingURL=index.cjs.map
|
|
512
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vector/filter.ts","../src/vector/index.ts","../src/vector/prompt.ts"],"names":["BaseFilterTranslator","MastraVector","CloudClient","ChromaClient","MastraError","ErrorDomain","ErrorCategory","error"],"mappings":";;;;;;;;AA4BO,IAAM,sBAAA,GAAN,cAAqCA,2BAAA,CAAyC;AAAA,EAChE,qBAAA,GAAyC;AAC1D,IAAA,OAAO;AAAA,MACL,GAAGA,2BAAA,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,oB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,aAAA,CAAc,EAAE,WAAW,CAAA;AACrE,MAAA,MAAM,WAAW,MAAA,CAAO,EAAE,KAAK,CAAC,EAAE,GAAG,CAAA;AAAA,IACvC,SAASA,OAAA,EAAY;AACnB,MAAA,IAAIA,OAAA,YAAiBH,mBAAa,MAAMG,OAAA;AACxC,MAAA,MAAM,IAAIH,iBAAA;AAAA,QACR;AAAA,UACE,EAAA,EAAI,6BAAA;AAAA,UACJ,QAAQC,iBAAA,CAAY,aAAA;AAAA,UACpB,UAAUC,mBAAA,CAAc,WAAA;AAAA,UACxB,OAAA,EAAS,EAAE,SAAA,EAAW,EAAA;AAAG,SAC3B;AAAA,QACAC;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.cjs","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/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
1
|
+
export * from './vector/index.js';
|
|
2
|
+
export { CHROMA_PROMPT } from './vector/prompt.js';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|