@mastra/chroma 0.0.0-working-memory-per-user-20250620161509 → 0.0.0-zod-v4-compat-part-2-20250820135355

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 CHANGED
@@ -1,14 +1,124 @@
1
1
  # @mastra/chroma
2
2
 
3
- ## 0.0.0-working-memory-per-user-20250620161509
3
+ ## 0.0.0-zod-v4-compat-part-2-20250820135355
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - Updated dependencies [94f4812]
8
+ - Updated dependencies [e202b82]
9
+ - Updated dependencies [e00f6a0]
10
+ - Updated dependencies [35c5798]
11
+ - @mastra/core@0.0.0-zod-v4-compat-part-2-20250820135355
12
+
13
+ ## 0.11.2
14
+
15
+ ### Patch Changes
16
+
17
+ - f42c4c2: update peer deps for packages to latest core range
18
+ - Updated dependencies [510e2c8]
19
+ - Updated dependencies [2f72fb2]
20
+ - Updated dependencies [27cc97a]
21
+ - Updated dependencies [3f89307]
22
+ - Updated dependencies [9eda7d4]
23
+ - Updated dependencies [9d49408]
24
+ - Updated dependencies [41daa63]
25
+ - Updated dependencies [ad0a58b]
26
+ - Updated dependencies [254a36b]
27
+ - Updated dependencies [2ecf658]
28
+ - Updated dependencies [7a7754f]
29
+ - Updated dependencies [fc92d80]
30
+ - Updated dependencies [e0f73c6]
31
+ - Updated dependencies [0b89602]
32
+ - Updated dependencies [4d37822]
33
+ - Updated dependencies [23a6a7c]
34
+ - Updated dependencies [cda801d]
35
+ - Updated dependencies [a77c823]
36
+ - Updated dependencies [ff9c125]
37
+ - Updated dependencies [09bca64]
38
+ - Updated dependencies [b8efbb9]
39
+ - Updated dependencies [71466e7]
40
+ - Updated dependencies [0c99fbe]
41
+ - @mastra/core@0.12.0
42
+
43
+ ## 0.11.2-alpha.0
44
+
45
+ ### Patch Changes
46
+
47
+ - f42c4c2: update peer deps for packages to latest core range
48
+ - @mastra/core@0.12.0-alpha.5
49
+
50
+ ## 0.11.1
51
+
52
+ ### Patch Changes
53
+
54
+ - ce088f5: Update all peerdeps to latest core
55
+ - @mastra/core@0.11.1
56
+
57
+ ## 0.11.0
58
+
59
+ ### Minor Changes
60
+
61
+ - 8a3bfd2: Update peerdeps to latest core
62
+
63
+ ### Patch Changes
64
+
65
+ - 144eb0b: [MASTRA-3669] Metadata Filter Types
66
+ - 0e17048: Throw mastra errors in storage packages
67
+ - Updated dependencies [15e9d26]
68
+ - Updated dependencies [d1baedb]
7
69
  - Updated dependencies [d8f2d19]
70
+ - Updated dependencies [4d21bf2]
71
+ - Updated dependencies [07d6d88]
8
72
  - Updated dependencies [9d52b17]
9
73
  - Updated dependencies [2097952]
74
+ - Updated dependencies [792c4c0]
75
+ - Updated dependencies [5d74aab]
76
+ - Updated dependencies [a8b194f]
77
+ - Updated dependencies [4fb0cc2]
78
+ - Updated dependencies [d2a7a31]
79
+ - Updated dependencies [502fe05]
80
+ - Updated dependencies [144eb0b]
10
81
  - Updated dependencies [8ba1b51]
11
- - @mastra/core@0.0.0-working-memory-per-user-20250620161509
82
+ - Updated dependencies [4efcfa0]
83
+ - Updated dependencies [0e17048]
84
+ - @mastra/core@0.10.7
85
+
86
+ ## 0.11.0-alpha.2
87
+
88
+ ### Minor Changes
89
+
90
+ - 8a3bfd2: Update peerdeps to latest core
91
+
92
+ ### Patch Changes
93
+
94
+ - Updated dependencies [792c4c0]
95
+ - Updated dependencies [502fe05]
96
+ - Updated dependencies [4efcfa0]
97
+ - @mastra/core@0.10.7-alpha.3
98
+
99
+ ## 0.10.4-alpha.1
100
+
101
+ ### Patch Changes
102
+
103
+ - 144eb0b: [MASTRA-3669] Metadata Filter Types
104
+ - Updated dependencies [15e9d26]
105
+ - Updated dependencies [07d6d88]
106
+ - Updated dependencies [5d74aab]
107
+ - Updated dependencies [144eb0b]
108
+ - @mastra/core@0.10.7-alpha.2
109
+
110
+ ## 0.10.4-alpha.0
111
+
112
+ ### Patch Changes
113
+
114
+ - 0e17048: Throw mastra errors in storage packages
115
+ - Updated dependencies [d1baedb]
116
+ - Updated dependencies [4d21bf2]
117
+ - Updated dependencies [2097952]
118
+ - Updated dependencies [4fb0cc2]
119
+ - Updated dependencies [d2a7a31]
120
+ - Updated dependencies [0e17048]
121
+ - @mastra/core@0.10.7-alpha.1
12
122
 
13
123
  ## 0.10.3
14
124
 
@@ -1311,7 +1421,6 @@
1311
1421
  ### Minor Changes
1312
1422
 
1313
1423
  - 684d5d1: Move Chroma package from `@mastra/vector-chroma` to `@mastra/chroma`.
1314
-
1315
1424
  - Move package to `stores/chroma`
1316
1425
  - Reorganize source files into `src/vector`
1317
1426
  - Add deprecation notice to old package
@@ -1645,7 +1754,6 @@
1645
1754
  ### Minor Changes
1646
1755
 
1647
1756
  - 684d5d1: Move Chroma package from `@mastra/vector-chroma` to `@mastra/chroma`.
1648
-
1649
1757
  - Move package to `stores/chroma`
1650
1758
  - Reorganize source files into `src/vector`
1651
1759
  - Add deprecation notice to old package
package/LICENSE.md CHANGED
@@ -1,7 +1,15 @@
1
- Copyright 2025 Mastra AI, Inc.
1
+ # Apache License 2.0
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ Copyright (c) 2025 Kepler Software, Inc.
4
4
 
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
6
8
 
7
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
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');
@@ -125,18 +126,31 @@ var ChromaVector = class extends vector.MastraVector {
125
126
  }
126
127
  }
127
128
  async upsert({ indexName, vectors, metadata, ids, documents }) {
128
- const collection = await this.getCollection(indexName);
129
- const stats = await this.describeIndex({ indexName });
130
- this.validateVectorDimensions(vectors, stats.dimension);
131
- const generatedIds = ids || vectors.map(() => crypto.randomUUID());
132
- const normalizedMetadata = metadata || vectors.map(() => ({}));
133
- await collection.upsert({
134
- ids: generatedIds,
135
- embeddings: vectors,
136
- metadatas: normalizedMetadata,
137
- documents
138
- });
139
- return generatedIds;
129
+ try {
130
+ const collection = await this.getCollection(indexName);
131
+ const stats = await this.describeIndex({ indexName });
132
+ this.validateVectorDimensions(vectors, stats.dimension);
133
+ const generatedIds = ids || vectors.map(() => crypto.randomUUID());
134
+ const normalizedMetadata = metadata || vectors.map(() => ({}));
135
+ await collection.upsert({
136
+ ids: generatedIds,
137
+ embeddings: vectors,
138
+ metadatas: normalizedMetadata,
139
+ documents
140
+ });
141
+ return generatedIds;
142
+ } catch (error$1) {
143
+ if (error$1 instanceof error.MastraError) throw error$1;
144
+ throw new error.MastraError(
145
+ {
146
+ id: "CHROMA_VECTOR_UPSERT_FAILED",
147
+ domain: error.ErrorDomain.MASTRA_VECTOR,
148
+ category: error.ErrorCategory.THIRD_PARTY,
149
+ details: { indexName }
150
+ },
151
+ error$1
152
+ );
153
+ }
140
154
  }
141
155
  HnswSpaceMap = {
142
156
  cosine: "cosine",
@@ -147,11 +161,23 @@ var ChromaVector = class extends vector.MastraVector {
147
161
  };
148
162
  async createIndex({ indexName, dimension, metric = "cosine" }) {
149
163
  if (!Number.isInteger(dimension) || dimension <= 0) {
150
- throw new Error("Dimension must be a positive integer");
164
+ throw new error.MastraError({
165
+ id: "CHROMA_VECTOR_CREATE_INDEX_INVALID_DIMENSION",
166
+ text: "Dimension must be a positive integer",
167
+ domain: error.ErrorDomain.MASTRA_VECTOR,
168
+ category: error.ErrorCategory.USER,
169
+ details: { dimension }
170
+ });
151
171
  }
152
172
  const hnswSpace = this.HnswSpaceMap[metric];
153
- if (!["cosine", "l2", "ip"].includes(hnswSpace)) {
154
- throw new Error(`Invalid metric: "${metric}". Must be one of: cosine, euclidean, dotproduct`);
173
+ if (!hnswSpace || !["cosine", "l2", "ip"].includes(hnswSpace)) {
174
+ throw new error.MastraError({
175
+ id: "CHROMA_VECTOR_CREATE_INDEX_INVALID_METRIC",
176
+ text: `Invalid metric: "${metric}". Must be one of: cosine, euclidean, dotproduct`,
177
+ domain: error.ErrorDomain.MASTRA_VECTOR,
178
+ category: error.ErrorCategory.USER,
179
+ details: { metric }
180
+ });
155
181
  }
156
182
  try {
157
183
  await this.client.createCollection({
@@ -161,13 +187,21 @@ var ChromaVector = class extends vector.MastraVector {
161
187
  "hnsw:space": hnswSpace
162
188
  }
163
189
  });
164
- } catch (error) {
165
- const message = error?.message || error?.toString();
190
+ } catch (error$1) {
191
+ const message = error$1?.message || error$1?.toString();
166
192
  if (message && message.toLowerCase().includes("already exists")) {
167
193
  await this.validateExistingIndex(indexName, dimension, metric);
168
194
  return;
169
195
  }
170
- throw error;
196
+ throw new error.MastraError(
197
+ {
198
+ id: "CHROMA_VECTOR_CREATE_INDEX_FAILED",
199
+ domain: error.ErrorDomain.MASTRA_VECTOR,
200
+ category: error.ErrorCategory.THIRD_PARTY,
201
+ details: { indexName }
202
+ },
203
+ error$1
204
+ );
171
205
  }
172
206
  }
173
207
  transformFilter(filter) {
@@ -182,27 +216,51 @@ var ChromaVector = class extends vector.MastraVector {
182
216
  includeVector = false,
183
217
  documentFilter
184
218
  }) {
185
- const collection = await this.getCollection(indexName, true);
186
- const defaultInclude = ["documents", "metadatas", "distances"];
187
- const translatedFilter = this.transformFilter(filter);
188
- const results = await collection.query({
189
- queryEmbeddings: [queryVector],
190
- nResults: topK,
191
- where: translatedFilter,
192
- whereDocument: documentFilter,
193
- include: includeVector ? [...defaultInclude, "embeddings"] : defaultInclude
194
- });
195
- return (results.ids[0] || []).map((id, index) => ({
196
- id,
197
- score: results.distances?.[0]?.[index] || 0,
198
- metadata: results.metadatas?.[0]?.[index] || {},
199
- document: results.documents?.[0]?.[index],
200
- ...includeVector && { vector: results.embeddings?.[0]?.[index] || [] }
201
- }));
219
+ try {
220
+ const collection = await this.getCollection(indexName, true);
221
+ const defaultInclude = ["documents", "metadatas", "distances"];
222
+ const translatedFilter = this.transformFilter(filter);
223
+ const results = await collection.query({
224
+ queryEmbeddings: [queryVector],
225
+ nResults: topK,
226
+ where: translatedFilter,
227
+ whereDocument: documentFilter,
228
+ include: includeVector ? [...defaultInclude, "embeddings"] : defaultInclude
229
+ });
230
+ return (results.ids[0] || []).map((id, index) => ({
231
+ id,
232
+ score: results.distances?.[0]?.[index] || 0,
233
+ metadata: results.metadatas?.[0]?.[index] || {},
234
+ document: results.documents?.[0]?.[index],
235
+ ...includeVector && { vector: results.embeddings?.[0]?.[index] || [] }
236
+ }));
237
+ } catch (error$1) {
238
+ if (error$1 instanceof error.MastraError) throw error$1;
239
+ throw new error.MastraError(
240
+ {
241
+ id: "CHROMA_VECTOR_QUERY_FAILED",
242
+ domain: error.ErrorDomain.MASTRA_VECTOR,
243
+ category: error.ErrorCategory.THIRD_PARTY,
244
+ details: { indexName }
245
+ },
246
+ error$1
247
+ );
248
+ }
202
249
  }
203
250
  async listIndexes() {
204
- const collections = await this.client.listCollections();
205
- return collections.map((collection) => collection);
251
+ try {
252
+ const collections = await this.client.listCollections();
253
+ return collections.map((collection) => collection);
254
+ } catch (error$1) {
255
+ throw new error.MastraError(
256
+ {
257
+ id: "CHROMA_VECTOR_LIST_INDEXES_FAILED",
258
+ domain: error.ErrorDomain.MASTRA_VECTOR,
259
+ category: error.ErrorCategory.THIRD_PARTY
260
+ },
261
+ error$1
262
+ );
263
+ }
206
264
  }
207
265
  /**
208
266
  * Retrieves statistics about a vector index.
@@ -211,19 +269,44 @@ var ChromaVector = class extends vector.MastraVector {
211
269
  * @returns A promise that resolves to the index statistics including dimension, count and metric
212
270
  */
213
271
  async describeIndex({ indexName }) {
214
- const collection = await this.getCollection(indexName);
215
- const count = await collection.count();
216
- const metadata = collection.metadata;
217
- const hnswSpace = metadata?.["hnsw:space"];
218
- return {
219
- dimension: metadata?.dimension || 0,
220
- count,
221
- metric: this.HnswSpaceMap[hnswSpace]
222
- };
272
+ try {
273
+ const collection = await this.getCollection(indexName);
274
+ const count = await collection.count();
275
+ const metadata = collection.metadata;
276
+ const hnswSpace = metadata?.["hnsw:space"];
277
+ return {
278
+ dimension: metadata?.dimension || 0,
279
+ count,
280
+ metric: this.HnswSpaceMap[hnswSpace]
281
+ };
282
+ } catch (error$1) {
283
+ if (error$1 instanceof error.MastraError) throw error$1;
284
+ throw new error.MastraError(
285
+ {
286
+ id: "CHROMA_VECTOR_DESCRIBE_INDEX_FAILED",
287
+ domain: error.ErrorDomain.MASTRA_VECTOR,
288
+ category: error.ErrorCategory.THIRD_PARTY,
289
+ details: { indexName }
290
+ },
291
+ error$1
292
+ );
293
+ }
223
294
  }
224
295
  async deleteIndex({ indexName }) {
225
- await this.client.deleteCollection({ name: indexName });
226
- this.collections.delete(indexName);
296
+ try {
297
+ await this.client.deleteCollection({ name: indexName });
298
+ this.collections.delete(indexName);
299
+ } catch (error$1) {
300
+ throw new error.MastraError(
301
+ {
302
+ id: "CHROMA_VECTOR_DELETE_INDEX_FAILED",
303
+ domain: error.ErrorDomain.MASTRA_VECTOR,
304
+ category: error.ErrorCategory.THIRD_PARTY,
305
+ details: { indexName }
306
+ },
307
+ error$1
308
+ );
309
+ }
227
310
  }
228
311
  /**
229
312
  * Updates a vector by its ID with the provided vector and/or metadata.
@@ -236,10 +319,16 @@ var ChromaVector = class extends vector.MastraVector {
236
319
  * @throws Will throw an error if no updates are provided or if the update operation fails.
237
320
  */
238
321
  async updateVector({ indexName, id, update }) {
322
+ if (!update.vector && !update.metadata) {
323
+ throw new error.MastraError({
324
+ id: "CHROMA_VECTOR_UPDATE_NO_PAYLOAD",
325
+ text: "No updates provided for vector",
326
+ domain: error.ErrorDomain.MASTRA_VECTOR,
327
+ category: error.ErrorCategory.USER,
328
+ details: { indexName, id }
329
+ });
330
+ }
239
331
  try {
240
- if (!update.vector && !update.metadata) {
241
- throw new Error("No updates provided");
242
- }
243
332
  const collection = await this.getCollection(indexName, true);
244
333
  const updateOptions = { ids: [id] };
245
334
  if (update?.vector) {
@@ -251,23 +340,34 @@ var ChromaVector = class extends vector.MastraVector {
251
340
  updateOptions.metadatas = [update.metadata];
252
341
  }
253
342
  return await collection.update(updateOptions);
254
- } catch (error) {
255
- throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
343
+ } catch (error$1) {
344
+ if (error$1 instanceof error.MastraError) throw error$1;
345
+ throw new error.MastraError(
346
+ {
347
+ id: "CHROMA_VECTOR_UPDATE_FAILED",
348
+ domain: error.ErrorDomain.MASTRA_VECTOR,
349
+ category: error.ErrorCategory.THIRD_PARTY,
350
+ details: { indexName, id }
351
+ },
352
+ error$1
353
+ );
256
354
  }
257
355
  }
258
- /**
259
- * Deletes a vector by its ID.
260
- * @param indexName - The name of the index containing the vector.
261
- * @param id - The ID of the vector to delete.
262
- * @returns A promise that resolves when the deletion is complete.
263
- * @throws Will throw an error if the deletion operation fails.
264
- */
265
356
  async deleteVector({ indexName, id }) {
266
357
  try {
267
358
  const collection = await this.getCollection(indexName, true);
268
359
  await collection.delete({ ids: [id] });
269
- } catch (error) {
270
- throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
360
+ } catch (error$1) {
361
+ if (error$1 instanceof error.MastraError) throw error$1;
362
+ throw new error.MastraError(
363
+ {
364
+ id: "CHROMA_VECTOR_DELETE_FAILED",
365
+ domain: error.ErrorDomain.MASTRA_VECTOR,
366
+ category: error.ErrorCategory.THIRD_PARTY,
367
+ details: { indexName, id }
368
+ },
369
+ error$1
370
+ );
271
371
  }
272
372
  }
273
373
  };
@@ -344,3 +444,5 @@ Example Complex Query:
344
444
 
345
445
  exports.CHROMA_PROMPT = CHROMA_PROMPT;
346
446
  exports.ChromaVector = ChromaVector;
447
+ //# sourceMappingURL=index.cjs.map
448
+ //# 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","ChromaClient","error","MastraError","ErrorDomain","ErrorCategory"],"mappings":";;;;;;;;AAuCO,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,eA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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\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"]}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export { CHROMA_PROMPT } from './_tsup-dts-rollup.js';
2
- export { ChromaVector } from './_tsup-dts-rollup.js';
1
+ export * from './vector/index';
2
+ export { CHROMA_PROMPT } from './vector/prompt';
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"}