@mastra/chroma 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-unified-sidebar-20251010130811
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 +700 -4
- package/LICENSE.md +12 -4
- package/README.md +47 -21
- package/dist/index.cjs +308 -103
- 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 +308 -103
- 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 +32 -14
- package/dist/_tsup-dts-rollup.d.cts +0 -75
- package/dist/_tsup-dts-rollup.d.ts +0 -75
- package/dist/index.d.cts +0 -2
- package/docker-compose.yaml +0 -7
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -2
- package/src/vector/filter.test.ts +0 -413
- package/src/vector/filter.ts +0 -115
- package/src/vector/index.test.ts +0 -1599
- package/src/vector/index.ts +0 -221
- package/src/vector/prompt.ts +0 -72
- package/tsconfig.json +0 -5
- package/vitest.config.ts +0 -8
package/LICENSE.md
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
# Apache License 2.0
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mastra/chroma
|
|
2
2
|
|
|
3
|
-
Vector store implementation for
|
|
3
|
+
Vector store implementation for Chroma using the official `chromadb` client with added dimension validation, collection management, and document storage capabilities.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,18 +8,56 @@ Vector store implementation for ChromaDB using the official chromadb client with
|
|
|
8
8
|
npm install @mastra/chroma
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Instantiation
|
|
12
|
+
|
|
13
|
+
### Local or Self-Deployments
|
|
14
|
+
|
|
15
|
+
To run a Chroma server, use the [Chroma CLI](https://docs.trychroma.com/docs/cli/db). It is available to you when you install this package.
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
chroma run
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
You will now have a Chroma server running on `localhost:8000`.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { ChromaVector } from '@mastra/chroma';
|
|
25
|
+
|
|
26
|
+
const vectorStore = new ChromaVector();
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
If you run a Chroma server locally with a different configuration, or [deploy](https://docs.trychroma.com/guides/deploy/client-server-mode) a Chroma server yourself, you can configure your `ChromaVector` instantiation with specific connection details:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { ChromaVector } from '@mastra/chroma';
|
|
33
|
+
|
|
34
|
+
const vectorStore = new ChromaVector({
|
|
35
|
+
host: 'your-host-address',
|
|
36
|
+
port: 8000,
|
|
37
|
+
ssl: false,
|
|
38
|
+
headers: {}, // any HTTP headers to send,
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Chroma Cloud
|
|
43
|
+
|
|
44
|
+
Provide your Chroma Cloud API key, tenant, and database.
|
|
45
|
+
|
|
46
|
+
You can use the [Chroma CLI](https://docs.trychroma.com/docs/cli/db) to set these as environment variables: `chroma db connect [DB-NAME] --env-file`.
|
|
12
47
|
|
|
13
48
|
```typescript
|
|
14
49
|
import { ChromaVector } from '@mastra/chroma';
|
|
15
50
|
|
|
16
51
|
const vectorStore = new ChromaVector({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
credentials: 'your-token'
|
|
21
|
-
}
|
|
52
|
+
apiKey: process.env.CHROMA_API_KEY,
|
|
53
|
+
tenant: process.env.CHROMA_TENANT,
|
|
54
|
+
database: process.env.CHROMA_DATABASE,
|
|
22
55
|
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
23
61
|
|
|
24
62
|
// Create a new collection
|
|
25
63
|
await vectorStore.createIndex({ indexName: 'myCollection', dimension: 1536, metric: 'cosine' });
|
|
@@ -46,18 +84,6 @@ const results = await vectorStore.query({
|
|
|
46
84
|
});
|
|
47
85
|
```
|
|
48
86
|
|
|
49
|
-
## Configuration
|
|
50
|
-
|
|
51
|
-
Required:
|
|
52
|
-
|
|
53
|
-
- `path`: URL of your ChromaDB server
|
|
54
|
-
|
|
55
|
-
Optional:
|
|
56
|
-
|
|
57
|
-
- `auth`: Authentication configuration
|
|
58
|
-
- `provider`: Authentication provider
|
|
59
|
-
- `credentials`: Authentication credentials
|
|
60
|
-
|
|
61
87
|
## Features
|
|
62
88
|
|
|
63
89
|
- Vector similarity search with cosine, euclidean, and dot product metrics
|
|
@@ -92,5 +118,5 @@ Query results include:
|
|
|
92
118
|
|
|
93
119
|
## Related Links
|
|
94
120
|
|
|
95
|
-
- [
|
|
96
|
-
- [
|
|
121
|
+
- [Chroma Documentation](https://docs.trychroma.com/)
|
|
122
|
+
- [Chroma API Reference](https://docs.trychroma.com/api/client)
|
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,111 +143,295 @@ 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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
dimension,
|
|
164
|
-
|
|
192
|
+
try {
|
|
193
|
+
const collection = await this.client.createCollection({
|
|
194
|
+
name: indexName,
|
|
195
|
+
metadata: { dimension },
|
|
196
|
+
configuration: { hnsw: { space: hnswSpace } },
|
|
197
|
+
embeddingFunction: null
|
|
198
|
+
});
|
|
199
|
+
this.collections.set(indexName, collection);
|
|
200
|
+
} catch (error$1) {
|
|
201
|
+
const message = error$1?.message || error$1?.toString();
|
|
202
|
+
if (message && message.toLowerCase().includes("already exists")) {
|
|
203
|
+
await this.validateExistingIndex(indexName, dimension, metric);
|
|
204
|
+
return;
|
|
165
205
|
}
|
|
166
|
-
|
|
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
|
+
);
|
|
215
|
+
}
|
|
167
216
|
}
|
|
168
217
|
transformFilter(filter) {
|
|
169
218
|
const translator = new ChromaFilterTranslator();
|
|
170
|
-
|
|
219
|
+
const translatedFilter = translator.translate(filter);
|
|
220
|
+
return translatedFilter ? translatedFilter : void 0;
|
|
171
221
|
}
|
|
172
|
-
async query(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
+
}
|
|
192
295
|
}
|
|
193
296
|
async listIndexes() {
|
|
194
|
-
|
|
195
|
-
|
|
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
|
+
}
|
|
196
310
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
311
|
+
/**
|
|
312
|
+
* Retrieves statistics about a vector index.
|
|
313
|
+
*
|
|
314
|
+
* @param {string} indexName - The name of the index to describe
|
|
315
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
316
|
+
*/
|
|
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
|
+
}
|
|
207
340
|
}
|
|
208
|
-
async deleteIndex(indexName) {
|
|
209
|
-
|
|
210
|
-
|
|
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
|
+
}
|
|
211
356
|
}
|
|
212
|
-
async
|
|
213
|
-
|
|
214
|
-
|
|
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
|
+
);
|
|
215
373
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
377
|
+
* @param indexName - The name of the index containing the vector.
|
|
378
|
+
* @param id - The ID of the vector to update.
|
|
379
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
380
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
381
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
382
|
+
* @returns A promise that resolves when the update is complete.
|
|
383
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
384
|
+
*/
|
|
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
|
+
});
|
|
220
394
|
}
|
|
221
|
-
|
|
222
|
-
|
|
395
|
+
try {
|
|
396
|
+
const collection = await this.getCollection({ indexName });
|
|
397
|
+
const updateRecordSet = { ids: [id] };
|
|
398
|
+
if (update?.vector) {
|
|
399
|
+
const stats = await this.describeIndex({ indexName });
|
|
400
|
+
this.validateVectorDimensions([update.vector], stats.dimension);
|
|
401
|
+
updateRecordSet.embeddings = [update.vector];
|
|
402
|
+
}
|
|
403
|
+
if (update?.metadata) {
|
|
404
|
+
updateRecordSet.metadatas = [update.metadata];
|
|
405
|
+
}
|
|
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
|
+
);
|
|
223
418
|
}
|
|
224
|
-
return await collection.update(updateOptions);
|
|
225
419
|
}
|
|
226
|
-
async
|
|
420
|
+
async deleteVector({ indexName, id }) {
|
|
227
421
|
try {
|
|
228
|
-
const collection = await this.getCollection(indexName
|
|
422
|
+
const collection = await this.getCollection({ indexName });
|
|
229
423
|
await collection.delete({ ids: [id] });
|
|
230
|
-
} catch (error) {
|
|
231
|
-
|
|
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
|
+
);
|
|
232
435
|
}
|
|
233
436
|
}
|
|
234
437
|
};
|
|
@@ -305,3 +508,5 @@ Example Complex Query:
|
|
|
305
508
|
|
|
306
509
|
exports.CHROMA_PROMPT = CHROMA_PROMPT;
|
|
307
510
|
exports.ChromaVector = ChromaVector;
|
|
511
|
+
//# sourceMappingURL=index.cjs.map
|
|
512
|
+
//# sourceMappingURL=index.cjs.map
|