@mastra/chroma 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-vector-sources-20250516175436

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,6 +1,121 @@
1
1
  # @mastra/chroma
2
2
 
3
- ## 0.0.0-trigger-playground-ui-package-20250506151043
3
+ ## 0.0.0-vector-sources-20250516175436
4
+
5
+ ### Patch Changes
6
+
7
+ - d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
8
+ - Updated dependencies [f53a6ac]
9
+ - Updated dependencies [eabdcd9]
10
+ - Updated dependencies [d0ee3c6]
11
+ - Updated dependencies [23f258c]
12
+ - Updated dependencies [2672a05]
13
+ - @mastra/core@0.0.0-vector-sources-20250516175436
14
+
15
+ ## 0.2.15
16
+
17
+ ### Patch Changes
18
+
19
+ - c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
20
+ - Updated dependencies [396be50]
21
+ - Updated dependencies [ab80e7e]
22
+ - Updated dependencies [c3bd795]
23
+ - Updated dependencies [da082f8]
24
+ - Updated dependencies [a5810ce]
25
+ - Updated dependencies [3e9c131]
26
+ - Updated dependencies [3171b5b]
27
+ - Updated dependencies [973e5ac]
28
+ - Updated dependencies [daf942f]
29
+ - Updated dependencies [0b8b868]
30
+ - Updated dependencies [9e1eff5]
31
+ - Updated dependencies [6fa1ad1]
32
+ - Updated dependencies [c28d7a0]
33
+ - Updated dependencies [edf1e88]
34
+ - @mastra/core@0.9.4
35
+
36
+ ## 0.2.15-alpha.4
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [3e9c131]
41
+ - @mastra/core@0.9.4-alpha.4
42
+
43
+ ## 0.2.15-alpha.3
44
+
45
+ ### Patch Changes
46
+
47
+ - c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
48
+ - Updated dependencies [396be50]
49
+ - Updated dependencies [c3bd795]
50
+ - Updated dependencies [da082f8]
51
+ - Updated dependencies [a5810ce]
52
+ - @mastra/core@0.9.4-alpha.3
53
+
54
+ ## 0.2.15-alpha.2
55
+
56
+ ### Patch Changes
57
+
58
+ - Updated dependencies [3171b5b]
59
+ - Updated dependencies [973e5ac]
60
+ - Updated dependencies [9e1eff5]
61
+ - @mastra/core@0.9.4-alpha.2
62
+
63
+ ## 0.2.15-alpha.1
64
+
65
+ ### Patch Changes
66
+
67
+ - Updated dependencies [ab80e7e]
68
+ - Updated dependencies [6fa1ad1]
69
+ - Updated dependencies [c28d7a0]
70
+ - Updated dependencies [edf1e88]
71
+ - @mastra/core@0.9.4-alpha.1
72
+
73
+ ## 0.2.15-alpha.0
74
+
75
+ ### Patch Changes
76
+
77
+ - Updated dependencies [daf942f]
78
+ - Updated dependencies [0b8b868]
79
+ - @mastra/core@0.9.4-alpha.0
80
+
81
+ ## 0.2.14
82
+
83
+ ### Patch Changes
84
+
85
+ - 9cd1a46: [MASTRA-3338] update naming scheme for embedding index based on vector store rules and added duplicate index checks
86
+ - Updated dependencies [e450778]
87
+ - Updated dependencies [8902157]
88
+ - Updated dependencies [ca0dc88]
89
+ - Updated dependencies [526c570]
90
+ - Updated dependencies [d7a6a33]
91
+ - Updated dependencies [9cd1a46]
92
+ - Updated dependencies [b5d2de0]
93
+ - Updated dependencies [644f8ad]
94
+ - Updated dependencies [70dbf51]
95
+ - @mastra/core@0.9.3
96
+
97
+ ## 0.2.14-alpha.1
98
+
99
+ ### Patch Changes
100
+
101
+ - 9cd1a46: [MASTRA-3338] update naming scheme for embedding index based on vector store rules and added duplicate index checks
102
+ - Updated dependencies [e450778]
103
+ - Updated dependencies [8902157]
104
+ - Updated dependencies [ca0dc88]
105
+ - Updated dependencies [9cd1a46]
106
+ - Updated dependencies [70dbf51]
107
+ - @mastra/core@0.9.3-alpha.1
108
+
109
+ ## 0.2.14-alpha.0
110
+
111
+ ### Patch Changes
112
+
113
+ - Updated dependencies [526c570]
114
+ - Updated dependencies [b5d2de0]
115
+ - Updated dependencies [644f8ad]
116
+ - @mastra/core@0.9.3-alpha.0
117
+
118
+ ## 0.2.13
4
119
 
5
120
  ### Patch Changes
6
121
 
@@ -18,8 +133,20 @@
18
133
  - Updated dependencies [17826a9]
19
134
  - Updated dependencies [7d8b7c7]
20
135
  - Updated dependencies [fba031f]
136
+ - Updated dependencies [3a5f1e1]
21
137
  - Updated dependencies [51e6923]
22
- - @mastra/core@0.0.0-trigger-playground-ui-package-20250506151043
138
+ - Updated dependencies [8398d89]
139
+ - @mastra/core@0.9.2
140
+
141
+ ## 0.2.13-alpha.6
142
+
143
+ ### Patch Changes
144
+
145
+ - Updated dependencies [6052aa6]
146
+ - Updated dependencies [7d8b7c7]
147
+ - Updated dependencies [3a5f1e1]
148
+ - Updated dependencies [8398d89]
149
+ - @mastra/core@0.9.2-alpha.6
23
150
 
24
151
  ## 0.2.13-alpha.5
25
152
 
@@ -1,5 +1,8 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
2
  import type { CreateIndexParams } from '@mastra/core/vector';
3
+ import type { DeleteIndexParams } from '@mastra/core/vector';
4
+ import type { DeleteVectorParams } from '@mastra/core/vector';
5
+ import type { DescribeIndexParams } from '@mastra/core/vector';
3
6
  import type { IndexStats } from '@mastra/core/vector';
4
7
  import { MastraVector } from '@mastra/core/vector';
5
8
  import type { OperatorSupport } from '@mastra/core/vector/filter';
@@ -7,6 +10,7 @@ import type { ParamsToArgs } from '@mastra/core/vector';
7
10
  import type { QueryResult } from '@mastra/core/vector';
8
11
  import type { QueryVectorArgs } from '@mastra/core/vector';
9
12
  import type { QueryVectorParams } from '@mastra/core/vector';
13
+ import type { UpdateVectorParams } from '@mastra/core/vector';
10
14
  import type { UpsertVectorArgs } from '@mastra/core/vector';
11
15
  import type { UpsertVectorParams } from '@mastra/core/vector';
12
16
  import type { VectorFilter } from '@mastra/core/vector/filter';
@@ -61,13 +65,60 @@ declare class ChromaVector extends MastraVector {
61
65
  transformFilter(filter?: VectorFilter): VectorFilter;
62
66
  query(...args: ParamsToArgs<ChromaQueryVectorParams> | ChromaQueryArgs): Promise<QueryResult[]>;
63
67
  listIndexes(): Promise<string[]>;
64
- describeIndex(indexName: string): Promise<IndexStats>;
65
- deleteIndex(indexName: string): Promise<void>;
68
+ /**
69
+ * Retrieves statistics about a vector index.
70
+ *
71
+ * @param params - The parameters for describing an index
72
+ * @param params.indexName - The name of the index to describe
73
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
74
+ */
75
+ describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
76
+ deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
77
+ /**
78
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
79
+ *
80
+ * Updates a vector by its ID with the provided vector and/or metadata.
81
+ * @param indexName - The name of the index containing the vector.
82
+ * @param id - The ID of the vector to update.
83
+ * @param update - An object containing the vector and/or metadata to update.
84
+ * @param update.vector - An optional array of numbers representing the new vector.
85
+ * @param update.metadata - An optional record containing the new metadata.
86
+ * @returns A promise that resolves when the update is complete.
87
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
88
+ */
66
89
  updateIndexById(indexName: string, id: string, update: {
67
90
  vector?: number[];
68
91
  metadata?: Record<string, any>;
69
92
  }): Promise<void>;
93
+ /**
94
+ * Updates a vector by its ID with the provided vector and/or metadata.
95
+ * @param indexName - The name of the index containing the vector.
96
+ * @param id - The ID of the vector to update.
97
+ * @param update - An object containing the vector and/or metadata to update.
98
+ * @param update.vector - An optional array of numbers representing the new vector.
99
+ * @param update.metadata - An optional record containing the new metadata.
100
+ * @returns A promise that resolves when the update is complete.
101
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
102
+ */
103
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
104
+ /**
105
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
106
+ *
107
+ * Deletes a vector by its ID.
108
+ * @param indexName - The name of the index containing the vector.
109
+ * @param id - The ID of the vector to delete.
110
+ * @returns A promise that resolves when the deletion is complete.
111
+ * @throws Will throw an error if the deletion operation fails.
112
+ */
70
113
  deleteIndexById(indexName: string, id: string): Promise<void>;
114
+ /**
115
+ * Deletes a vector by its ID.
116
+ * @param indexName - The name of the index containing the vector.
117
+ * @param id - The ID of the vector to delete.
118
+ * @returns A promise that resolves when the deletion is complete.
119
+ * @throws Will throw an error if the deletion operation fails.
120
+ */
121
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
71
122
  }
72
123
  export { ChromaVector }
73
124
  export { ChromaVector as ChromaVector_alias_1 }
@@ -1,5 +1,8 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
2
  import type { CreateIndexParams } from '@mastra/core/vector';
3
+ import type { DeleteIndexParams } from '@mastra/core/vector';
4
+ import type { DeleteVectorParams } from '@mastra/core/vector';
5
+ import type { DescribeIndexParams } from '@mastra/core/vector';
3
6
  import type { IndexStats } from '@mastra/core/vector';
4
7
  import { MastraVector } from '@mastra/core/vector';
5
8
  import type { OperatorSupport } from '@mastra/core/vector/filter';
@@ -7,6 +10,7 @@ import type { ParamsToArgs } from '@mastra/core/vector';
7
10
  import type { QueryResult } from '@mastra/core/vector';
8
11
  import type { QueryVectorArgs } from '@mastra/core/vector';
9
12
  import type { QueryVectorParams } from '@mastra/core/vector';
13
+ import type { UpdateVectorParams } from '@mastra/core/vector';
10
14
  import type { UpsertVectorArgs } from '@mastra/core/vector';
11
15
  import type { UpsertVectorParams } from '@mastra/core/vector';
12
16
  import type { VectorFilter } from '@mastra/core/vector/filter';
@@ -61,13 +65,60 @@ declare class ChromaVector extends MastraVector {
61
65
  transformFilter(filter?: VectorFilter): VectorFilter;
62
66
  query(...args: ParamsToArgs<ChromaQueryVectorParams> | ChromaQueryArgs): Promise<QueryResult[]>;
63
67
  listIndexes(): Promise<string[]>;
64
- describeIndex(indexName: string): Promise<IndexStats>;
65
- deleteIndex(indexName: string): Promise<void>;
68
+ /**
69
+ * Retrieves statistics about a vector index.
70
+ *
71
+ * @param params - The parameters for describing an index
72
+ * @param params.indexName - The name of the index to describe
73
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
74
+ */
75
+ describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
76
+ deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
77
+ /**
78
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
79
+ *
80
+ * Updates a vector by its ID with the provided vector and/or metadata.
81
+ * @param indexName - The name of the index containing the vector.
82
+ * @param id - The ID of the vector to update.
83
+ * @param update - An object containing the vector and/or metadata to update.
84
+ * @param update.vector - An optional array of numbers representing the new vector.
85
+ * @param update.metadata - An optional record containing the new metadata.
86
+ * @returns A promise that resolves when the update is complete.
87
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
88
+ */
66
89
  updateIndexById(indexName: string, id: string, update: {
67
90
  vector?: number[];
68
91
  metadata?: Record<string, any>;
69
92
  }): Promise<void>;
93
+ /**
94
+ * Updates a vector by its ID with the provided vector and/or metadata.
95
+ * @param indexName - The name of the index containing the vector.
96
+ * @param id - The ID of the vector to update.
97
+ * @param update - An object containing the vector and/or metadata to update.
98
+ * @param update.vector - An optional array of numbers representing the new vector.
99
+ * @param update.metadata - An optional record containing the new metadata.
100
+ * @returns A promise that resolves when the update is complete.
101
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
102
+ */
103
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
104
+ /**
105
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
106
+ *
107
+ * Deletes a vector by its ID.
108
+ * @param indexName - The name of the index containing the vector.
109
+ * @param id - The ID of the vector to delete.
110
+ * @returns A promise that resolves when the deletion is complete.
111
+ * @throws Will throw an error if the deletion operation fails.
112
+ */
70
113
  deleteIndexById(indexName: string, id: string): Promise<void>;
114
+ /**
115
+ * Deletes a vector by its ID.
116
+ * @param indexName - The name of the index containing the vector.
117
+ * @param id - The ID of the vector to delete.
118
+ * @returns A promise that resolves when the deletion is complete.
119
+ * @throws Will throw an error if the deletion operation fails.
120
+ */
121
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
71
122
  }
72
123
  export { ChromaVector }
73
124
  export { ChromaVector as ChromaVector_alias_1 }
package/dist/index.cjs CHANGED
@@ -128,7 +128,7 @@ var ChromaVector = class extends vector.MastraVector {
128
128
  const params = this.normalizeArgs("upsert", args, ["documents"]);
129
129
  const { indexName, vectors, metadata, ids, documents } = params;
130
130
  const collection = await this.getCollection(indexName);
131
- const stats = await this.describeIndex(indexName);
131
+ const stats = await this.describeIndex({ indexName });
132
132
  this.validateVectorDimensions(vectors, stats.dimension);
133
133
  const generatedIds = ids || vectors.map(() => crypto.randomUUID());
134
134
  const normalizedMetadata = metadata || vectors.map(() => ({}));
@@ -157,13 +157,22 @@ var ChromaVector = class extends vector.MastraVector {
157
157
  if (!["cosine", "l2", "ip"].includes(hnswSpace)) {
158
158
  throw new Error(`Invalid metric: "${metric}". Must be one of: cosine, euclidean, dotproduct`);
159
159
  }
160
- await this.client.createCollection({
161
- name: indexName,
162
- metadata: {
163
- dimension,
164
- "hnsw:space": this.HnswSpaceMap[metric]
160
+ try {
161
+ await this.client.createCollection({
162
+ name: indexName,
163
+ metadata: {
164
+ dimension,
165
+ "hnsw:space": hnswSpace
166
+ }
167
+ });
168
+ } catch (error) {
169
+ const message = error?.message || error?.toString();
170
+ if (message && message.toLowerCase().includes("already exists")) {
171
+ await this.validateExistingIndex(indexName, dimension, metric);
172
+ return;
165
173
  }
166
- });
174
+ throw error;
175
+ }
167
176
  }
168
177
  transformFilter(filter) {
169
178
  const translator = new ChromaFilterTranslator();
@@ -194,7 +203,16 @@ var ChromaVector = class extends vector.MastraVector {
194
203
  const collections = await this.client.listCollections();
195
204
  return collections.map((collection) => collection);
196
205
  }
197
- async describeIndex(indexName) {
206
+ /**
207
+ * Retrieves statistics about a vector index.
208
+ *
209
+ * @param params - The parameters for describing an index
210
+ * @param params.indexName - The name of the index to describe
211
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
212
+ */
213
+ async describeIndex(...args) {
214
+ const params = this.normalizeArgs("describeIndex", args);
215
+ const { indexName } = params;
198
216
  const collection = await this.getCollection(indexName);
199
217
  const count = await collection.count();
200
218
  const metadata = collection.metadata;
@@ -205,30 +223,94 @@ var ChromaVector = class extends vector.MastraVector {
205
223
  metric: this.HnswSpaceMap[hnswSpace]
206
224
  };
207
225
  }
208
- async deleteIndex(indexName) {
226
+ async deleteIndex(...args) {
227
+ const params = this.normalizeArgs("deleteIndex", args);
228
+ const { indexName } = params;
209
229
  await this.client.deleteCollection({ name: indexName });
210
230
  this.collections.delete(indexName);
211
231
  }
232
+ /**
233
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
234
+ *
235
+ * Updates a vector by its ID with the provided vector and/or metadata.
236
+ * @param indexName - The name of the index containing the vector.
237
+ * @param id - The ID of the vector to update.
238
+ * @param update - An object containing the vector and/or metadata to update.
239
+ * @param update.vector - An optional array of numbers representing the new vector.
240
+ * @param update.metadata - An optional record containing the new metadata.
241
+ * @returns A promise that resolves when the update is complete.
242
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
243
+ */
212
244
  async updateIndexById(indexName, id, update) {
213
- if (!update.vector && !update.metadata) {
214
- throw new Error("No updates provided");
215
- }
216
- const collection = await this.getCollection(indexName, true);
217
- const updateOptions = { ids: [id] };
218
- if (update?.vector) {
219
- updateOptions.embeddings = [update.vector];
220
- }
221
- if (update?.metadata) {
222
- updateOptions.metadatas = [update.metadata];
245
+ this.logger.warn(
246
+ `Deprecation Warning: updateIndexById() is deprecated.
247
+ Please use updateVector() instead.
248
+ updateIndexById() will be removed on May 20th, 2025.`
249
+ );
250
+ await this.updateVector({ indexName, id, update });
251
+ }
252
+ /**
253
+ * Updates a vector by its ID with the provided vector and/or metadata.
254
+ * @param indexName - The name of the index containing the vector.
255
+ * @param id - The ID of the vector to update.
256
+ * @param update - An object containing the vector and/or metadata to update.
257
+ * @param update.vector - An optional array of numbers representing the new vector.
258
+ * @param update.metadata - An optional record containing the new metadata.
259
+ * @returns A promise that resolves when the update is complete.
260
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
261
+ */
262
+ async updateVector(...args) {
263
+ const params = this.normalizeArgs("updateVector", args);
264
+ const { indexName, id, update } = params;
265
+ try {
266
+ if (!update.vector && !update.metadata) {
267
+ throw new Error("No updates provided");
268
+ }
269
+ const collection = await this.getCollection(indexName, true);
270
+ const updateOptions = { ids: [id] };
271
+ if (update?.vector) {
272
+ const stats = await this.describeIndex({ indexName });
273
+ this.validateVectorDimensions([update.vector], stats.dimension);
274
+ updateOptions.embeddings = [update.vector];
275
+ }
276
+ if (update?.metadata) {
277
+ updateOptions.metadatas = [update.metadata];
278
+ }
279
+ return await collection.update(updateOptions);
280
+ } catch (error) {
281
+ throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
223
282
  }
224
- return await collection.update(updateOptions);
225
283
  }
284
+ /**
285
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
286
+ *
287
+ * Deletes a vector by its ID.
288
+ * @param indexName - The name of the index containing the vector.
289
+ * @param id - The ID of the vector to delete.
290
+ * @returns A promise that resolves when the deletion is complete.
291
+ * @throws Will throw an error if the deletion operation fails.
292
+ */
226
293
  async deleteIndexById(indexName, id) {
294
+ this.logger.warn(
295
+ `Deprecation Warning: deleteIndexById() is deprecated. Please use deleteVector() instead. deleteIndexById() will be removed on May 20th.`
296
+ );
297
+ await this.deleteVector(indexName, id);
298
+ }
299
+ /**
300
+ * Deletes a vector by its ID.
301
+ * @param indexName - The name of the index containing the vector.
302
+ * @param id - The ID of the vector to delete.
303
+ * @returns A promise that resolves when the deletion is complete.
304
+ * @throws Will throw an error if the deletion operation fails.
305
+ */
306
+ async deleteVector(...args) {
307
+ const params = this.normalizeArgs("deleteVector", args);
308
+ const { indexName, id } = params;
227
309
  try {
228
310
  const collection = await this.getCollection(indexName, true);
229
311
  await collection.delete({ ids: [id] });
230
312
  } catch (error) {
231
- throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
313
+ throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
232
314
  }
233
315
  }
234
316
  };
package/dist/index.js CHANGED
@@ -126,7 +126,7 @@ var ChromaVector = class extends MastraVector {
126
126
  const params = this.normalizeArgs("upsert", args, ["documents"]);
127
127
  const { indexName, vectors, metadata, ids, documents } = params;
128
128
  const collection = await this.getCollection(indexName);
129
- const stats = await this.describeIndex(indexName);
129
+ const stats = await this.describeIndex({ indexName });
130
130
  this.validateVectorDimensions(vectors, stats.dimension);
131
131
  const generatedIds = ids || vectors.map(() => crypto.randomUUID());
132
132
  const normalizedMetadata = metadata || vectors.map(() => ({}));
@@ -155,13 +155,22 @@ var ChromaVector = class extends MastraVector {
155
155
  if (!["cosine", "l2", "ip"].includes(hnswSpace)) {
156
156
  throw new Error(`Invalid metric: "${metric}". Must be one of: cosine, euclidean, dotproduct`);
157
157
  }
158
- await this.client.createCollection({
159
- name: indexName,
160
- metadata: {
161
- dimension,
162
- "hnsw:space": this.HnswSpaceMap[metric]
158
+ try {
159
+ await this.client.createCollection({
160
+ name: indexName,
161
+ metadata: {
162
+ dimension,
163
+ "hnsw:space": hnswSpace
164
+ }
165
+ });
166
+ } catch (error) {
167
+ const message = error?.message || error?.toString();
168
+ if (message && message.toLowerCase().includes("already exists")) {
169
+ await this.validateExistingIndex(indexName, dimension, metric);
170
+ return;
163
171
  }
164
- });
172
+ throw error;
173
+ }
165
174
  }
166
175
  transformFilter(filter) {
167
176
  const translator = new ChromaFilterTranslator();
@@ -192,7 +201,16 @@ var ChromaVector = class extends MastraVector {
192
201
  const collections = await this.client.listCollections();
193
202
  return collections.map((collection) => collection);
194
203
  }
195
- async describeIndex(indexName) {
204
+ /**
205
+ * Retrieves statistics about a vector index.
206
+ *
207
+ * @param params - The parameters for describing an index
208
+ * @param params.indexName - The name of the index to describe
209
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
210
+ */
211
+ async describeIndex(...args) {
212
+ const params = this.normalizeArgs("describeIndex", args);
213
+ const { indexName } = params;
196
214
  const collection = await this.getCollection(indexName);
197
215
  const count = await collection.count();
198
216
  const metadata = collection.metadata;
@@ -203,30 +221,94 @@ var ChromaVector = class extends MastraVector {
203
221
  metric: this.HnswSpaceMap[hnswSpace]
204
222
  };
205
223
  }
206
- async deleteIndex(indexName) {
224
+ async deleteIndex(...args) {
225
+ const params = this.normalizeArgs("deleteIndex", args);
226
+ const { indexName } = params;
207
227
  await this.client.deleteCollection({ name: indexName });
208
228
  this.collections.delete(indexName);
209
229
  }
230
+ /**
231
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
232
+ *
233
+ * Updates a vector by its ID with the provided vector and/or metadata.
234
+ * @param indexName - The name of the index containing the vector.
235
+ * @param id - The ID of the vector to update.
236
+ * @param update - An object containing the vector and/or metadata to update.
237
+ * @param update.vector - An optional array of numbers representing the new vector.
238
+ * @param update.metadata - An optional record containing the new metadata.
239
+ * @returns A promise that resolves when the update is complete.
240
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
241
+ */
210
242
  async updateIndexById(indexName, id, update) {
211
- if (!update.vector && !update.metadata) {
212
- throw new Error("No updates provided");
213
- }
214
- const collection = await this.getCollection(indexName, true);
215
- const updateOptions = { ids: [id] };
216
- if (update?.vector) {
217
- updateOptions.embeddings = [update.vector];
218
- }
219
- if (update?.metadata) {
220
- updateOptions.metadatas = [update.metadata];
243
+ this.logger.warn(
244
+ `Deprecation Warning: updateIndexById() is deprecated.
245
+ Please use updateVector() instead.
246
+ updateIndexById() will be removed on May 20th, 2025.`
247
+ );
248
+ await this.updateVector({ indexName, id, update });
249
+ }
250
+ /**
251
+ * Updates a vector by its ID with the provided vector and/or metadata.
252
+ * @param indexName - The name of the index containing the vector.
253
+ * @param id - The ID of the vector to update.
254
+ * @param update - An object containing the vector and/or metadata to update.
255
+ * @param update.vector - An optional array of numbers representing the new vector.
256
+ * @param update.metadata - An optional record containing the new metadata.
257
+ * @returns A promise that resolves when the update is complete.
258
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
259
+ */
260
+ async updateVector(...args) {
261
+ const params = this.normalizeArgs("updateVector", args);
262
+ const { indexName, id, update } = params;
263
+ try {
264
+ if (!update.vector && !update.metadata) {
265
+ throw new Error("No updates provided");
266
+ }
267
+ const collection = await this.getCollection(indexName, true);
268
+ const updateOptions = { ids: [id] };
269
+ if (update?.vector) {
270
+ const stats = await this.describeIndex({ indexName });
271
+ this.validateVectorDimensions([update.vector], stats.dimension);
272
+ updateOptions.embeddings = [update.vector];
273
+ }
274
+ if (update?.metadata) {
275
+ updateOptions.metadatas = [update.metadata];
276
+ }
277
+ return await collection.update(updateOptions);
278
+ } catch (error) {
279
+ throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
221
280
  }
222
- return await collection.update(updateOptions);
223
281
  }
282
+ /**
283
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
284
+ *
285
+ * Deletes a vector by its ID.
286
+ * @param indexName - The name of the index containing the vector.
287
+ * @param id - The ID of the vector to delete.
288
+ * @returns A promise that resolves when the deletion is complete.
289
+ * @throws Will throw an error if the deletion operation fails.
290
+ */
224
291
  async deleteIndexById(indexName, id) {
292
+ this.logger.warn(
293
+ `Deprecation Warning: deleteIndexById() is deprecated. Please use deleteVector() instead. deleteIndexById() will be removed on May 20th.`
294
+ );
295
+ await this.deleteVector(indexName, id);
296
+ }
297
+ /**
298
+ * Deletes a vector by its ID.
299
+ * @param indexName - The name of the index containing the vector.
300
+ * @param id - The ID of the vector to delete.
301
+ * @returns A promise that resolves when the deletion is complete.
302
+ * @throws Will throw an error if the deletion operation fails.
303
+ */
304
+ async deleteVector(...args) {
305
+ const params = this.normalizeArgs("deleteVector", args);
306
+ const { indexName, id } = params;
225
307
  try {
226
308
  const collection = await this.getCollection(indexName, true);
227
309
  await collection.delete({ ids: [id] });
228
310
  } catch (error) {
229
- throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
311
+ throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
230
312
  }
231
313
  }
232
314
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/chroma",
3
- "version": "0.0.0-trigger-playground-ui-package-20250506151043",
3
+ "version": "0.0.0-vector-sources-20250516175436",
4
4
  "description": "Chroma vector store provider for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,7 +21,7 @@
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
23
  "chromadb": "^2.2.0",
24
- "@mastra/core": "0.0.0-trigger-playground-ui-package-20250506151043"
24
+ "@mastra/core": "0.0.0-vector-sources-20250516175436"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@microsoft/api-extractor": "^7.52.5",
@@ -30,7 +30,7 @@
30
30
  "tsup": "^8.4.0",
31
31
  "typescript": "^5.8.2",
32
32
  "vitest": "^3.1.2",
33
- "@internal/lint": "0.0.0-trigger-playground-ui-package-20250506151043"
33
+ "@internal/lint": "0.0.0-vector-sources-20250516175436"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
@@ -16,7 +16,7 @@ describe('ChromaVector Integration Tests', () => {
16
16
  beforeEach(async () => {
17
17
  // Clean up any existing test index
18
18
  try {
19
- await vectorDB.deleteIndex(testIndexName);
19
+ await vectorDB.deleteIndex({ indexName: testIndexName });
20
20
  } catch {
21
21
  // Ignore errors if index doesn't exist
22
22
  }
@@ -26,7 +26,7 @@ describe('ChromaVector Integration Tests', () => {
26
26
  afterEach(async () => {
27
27
  // Cleanup after tests
28
28
  try {
29
- await vectorDB.deleteIndex(testIndexName);
29
+ await vectorDB.deleteIndex({ indexName: testIndexName });
30
30
  } catch {
31
31
  // Ignore cleanup errors
32
32
  }
@@ -39,14 +39,14 @@ describe('ChromaVector Integration Tests', () => {
39
39
  });
40
40
 
41
41
  it('should describe index correctly', async () => {
42
- const stats: IndexStats = await vectorDB.describeIndex(testIndexName);
42
+ const stats: IndexStats = await vectorDB.describeIndex({ indexName: testIndexName });
43
43
  expect(stats.dimension).toBe(dimension);
44
44
  expect(stats.count).toBe(0);
45
45
  expect(stats.metric).toBe('cosine');
46
46
  });
47
47
 
48
48
  it('should delete index', async () => {
49
- await vectorDB.deleteIndex(testIndexName);
49
+ await vectorDB.deleteIndex({ indexName: testIndexName });
50
50
  const indexes = await vectorDB.listIndexes();
51
51
  expect(indexes).not.toContain(testIndexName);
52
52
  });
@@ -58,10 +58,10 @@ describe('ChromaVector Integration Tests', () => {
58
58
  const testIndex = `test-index-${metric}`;
59
59
  await vectorDB.createIndex({ indexName: testIndex, dimension, metric });
60
60
 
61
- const stats = await vectorDB.describeIndex(testIndex);
61
+ const stats = await vectorDB.describeIndex({ indexName: testIndex });
62
62
  expect(stats.metric).toBe(metric);
63
63
 
64
- await vectorDB.deleteIndex(testIndex);
64
+ await vectorDB.deleteIndex({ indexName: testIndex });
65
65
  }
66
66
  });
67
67
  });
@@ -80,14 +80,14 @@ describe('ChromaVector Integration Tests', () => {
80
80
  expect(ids).toHaveLength(testVectors.length);
81
81
  ids.forEach(id => expect(typeof id).toBe('string'));
82
82
 
83
- const stats = await vectorDB.describeIndex(testIndexName);
83
+ const stats = await vectorDB.describeIndex({ indexName: testIndexName });
84
84
  expect(stats.count).toBe(testVectors.length);
85
85
  });
86
86
 
87
87
  it('should upsert vectors with provided ids and metadata', async () => {
88
88
  await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors, metadata: testMetadata, ids: testIds });
89
89
 
90
- const stats = await vectorDB.describeIndex(testIndexName);
90
+ const stats = await vectorDB.describeIndex({ indexName: testIndexName });
91
91
  expect(stats.count).toBe(testVectors.length);
92
92
 
93
93
  // Query each vector to verify metadata
@@ -133,7 +133,7 @@ describe('ChromaVector Integration Tests', () => {
133
133
  metadata: newMetaData,
134
134
  };
135
135
 
136
- await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
136
+ await vectorDB.updateVector({ indexName: testIndexName, id: idToBeUpdated, update });
137
137
 
138
138
  const results: QueryResult[] = await vectorDB.query({
139
139
  indexName: testIndexName,
@@ -159,7 +159,7 @@ describe('ChromaVector Integration Tests', () => {
159
159
  metadata: newMetaData,
160
160
  };
161
161
 
162
- await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
162
+ await vectorDB.updateVector({ indexName: testIndexName, id: idToBeUpdated, update });
163
163
 
164
164
  const results: QueryResult[] = await vectorDB.query({
165
165
  indexName: testIndexName,
@@ -183,7 +183,7 @@ describe('ChromaVector Integration Tests', () => {
183
183
  vector: newVector,
184
184
  };
185
185
 
186
- await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
186
+ await vectorDB.updateVector({ indexName: testIndexName, id: idToBeUpdated, update });
187
187
 
188
188
  const results: QueryResult[] = await vectorDB.query({
189
189
  indexName: testIndexName,
@@ -196,7 +196,9 @@ describe('ChromaVector Integration Tests', () => {
196
196
  });
197
197
 
198
198
  it('should throw exception when no updates are given', async () => {
199
- await expect(vectorDB.updateIndexById(testIndexName, 'id', {})).rejects.toThrow('No updates provided');
199
+ await expect(vectorDB.updateVector({ indexName: testIndexName, id: 'id', update: {} })).rejects.toThrow(
200
+ 'No updates provided',
201
+ );
200
202
  });
201
203
 
202
204
  it('should delete the vector by id', async () => {
@@ -204,7 +206,7 @@ describe('ChromaVector Integration Tests', () => {
204
206
  expect(ids).toHaveLength(3);
205
207
  const idToBeDeleted = ids[0];
206
208
 
207
- await vectorDB.deleteIndexById(testIndexName, idToBeDeleted);
209
+ await vectorDB.deleteVector({ indexName: testIndexName, id: idToBeDeleted });
208
210
 
209
211
  const results: QueryResult[] = await vectorDB.query({
210
212
  indexName: testIndexName,
@@ -273,8 +275,17 @@ describe('ChromaVector Integration Tests', () => {
273
275
  });
274
276
 
275
277
  describe('Error Handling', () => {
278
+ const testIndexName = 'test_index_error';
279
+ beforeAll(async () => {
280
+ await vectorDB.createIndex({ indexName: testIndexName, dimension: 3 });
281
+ });
282
+
283
+ afterAll(async () => {
284
+ await vectorDB.deleteIndex({ indexName: testIndexName });
285
+ });
286
+
276
287
  it('should handle non-existent index queries', async () => {
277
- await expect(vectorDB.query({ indexName: 'non-existent-index-yu', queryVector: [1, 2, 3] })).rejects.toThrow();
288
+ await expect(vectorDB.query({ indexName: 'non-existent-index', queryVector: [1, 2, 3] })).rejects.toThrow();
278
289
  });
279
290
 
280
291
  it('should handle invalid dimension vectors', async () => {
@@ -282,10 +293,59 @@ describe('ChromaVector Integration Tests', () => {
282
293
  await expect(vectorDB.upsert({ indexName: testIndexName, vectors: [invalidVector] })).rejects.toThrow();
283
294
  });
284
295
 
285
- it('should handle mismatched metadata and vectors length', async () => {
286
- const vectors = [[1, 2, 3]];
287
- const metadata = [{}, {}]; // More metadata than vectors
288
- await expect(vectorDB.upsert({ indexName: testIndexName, vectors, metadata })).rejects.toThrow();
296
+ it('should handle duplicate index creation gracefully', async () => {
297
+ const infoSpy = vi.spyOn(vectorDB['logger'], 'info');
298
+ const warnSpy = vi.spyOn(vectorDB['logger'], 'warn');
299
+
300
+ const duplicateIndexName = `duplicate-test`;
301
+ const dimension = 768;
302
+
303
+ try {
304
+ // Create index first time
305
+ await vectorDB.createIndex({
306
+ indexName: duplicateIndexName,
307
+ dimension,
308
+ metric: 'cosine',
309
+ });
310
+
311
+ // Try to create with same dimensions - should not throw
312
+ await expect(
313
+ vectorDB.createIndex({
314
+ indexName: duplicateIndexName,
315
+ dimension,
316
+ metric: 'cosine',
317
+ }),
318
+ ).resolves.not.toThrow();
319
+
320
+ expect(infoSpy).toHaveBeenCalledWith(expect.stringContaining('already exists with'));
321
+
322
+ // Try to create with same dimensions and different metric - should not throw
323
+ await expect(
324
+ vectorDB.createIndex({
325
+ indexName: duplicateIndexName,
326
+ dimension,
327
+ metric: 'euclidean',
328
+ }),
329
+ ).resolves.not.toThrow();
330
+
331
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Attempted to create index with metric'));
332
+
333
+ // Try to create with different dimensions - should throw
334
+ await expect(
335
+ vectorDB.createIndex({
336
+ indexName: duplicateIndexName,
337
+ dimension: dimension + 1,
338
+ metric: 'cosine',
339
+ }),
340
+ ).rejects.toThrow(
341
+ `Index "${duplicateIndexName}" already exists with ${dimension} dimensions, but ${dimension + 1} dimensions were requested`,
342
+ );
343
+ } finally {
344
+ infoSpy.mockRestore();
345
+ warnSpy.mockRestore();
346
+ // Cleanup
347
+ await vectorDB.deleteIndex({ indexName: duplicateIndexName });
348
+ }
289
349
  });
290
350
  });
291
351
 
@@ -461,7 +521,7 @@ describe('ChromaVector Integration Tests', () => {
461
521
  // Set up test vectors and metadata
462
522
  beforeAll(async () => {
463
523
  try {
464
- await vectorDB.deleteIndex(testIndexName2);
524
+ await vectorDB.deleteIndex({ indexName: testIndexName2 });
465
525
  } catch {
466
526
  // Ignore errors if index doesn't exist
467
527
  }
@@ -509,7 +569,7 @@ describe('ChromaVector Integration Tests', () => {
509
569
  afterAll(async () => {
510
570
  // Cleanup after tests
511
571
  try {
512
- await vectorDB.deleteIndex(testIndexName2);
572
+ await vectorDB.deleteIndex({ indexName: testIndexName2 });
513
573
  } catch {
514
574
  // Ignore cleanup errors
515
575
  }
@@ -1180,7 +1240,7 @@ describe('ChromaVector Integration Tests', () => {
1180
1240
 
1181
1241
  beforeAll(async () => {
1182
1242
  try {
1183
- await vectorDB.deleteIndex(testIndexName3);
1243
+ await vectorDB.deleteIndex({ indexName: testIndexName3 });
1184
1244
  } catch {
1185
1245
  // Ignore errors if index doesn't exist
1186
1246
  }
@@ -1214,7 +1274,7 @@ describe('ChromaVector Integration Tests', () => {
1214
1274
  afterAll(async () => {
1215
1275
  // Cleanup after tests
1216
1276
  try {
1217
- await vectorDB.deleteIndex(testIndexName3);
1277
+ await vectorDB.deleteIndex({ indexName: testIndexName3 });
1218
1278
  } catch {
1219
1279
  // Ignore cleanup errors
1220
1280
  }
@@ -1410,17 +1470,17 @@ describe('ChromaVector Integration Tests', () => {
1410
1470
  let warnSpy;
1411
1471
 
1412
1472
  beforeAll(async () => {
1413
- await vectorDB.createIndex({ indexName: indexName, dimension: 3 });
1473
+ await vectorDB.createIndex({ indexName, dimension: 3 });
1414
1474
  });
1415
1475
 
1416
1476
  afterAll(async () => {
1417
1477
  try {
1418
- await vectorDB.deleteIndex(indexName);
1478
+ await vectorDB.deleteIndex({ indexName });
1419
1479
  } catch {
1420
1480
  // Ignore errors if index doesn't exist
1421
1481
  }
1422
1482
  try {
1423
- await vectorDB.deleteIndex(indexName2);
1483
+ await vectorDB.deleteIndex({ indexName: indexName2 });
1424
1484
  } catch {
1425
1485
  // Ignore errors if index doesn't exist
1426
1486
  }
@@ -1433,7 +1493,7 @@ describe('ChromaVector Integration Tests', () => {
1433
1493
  afterEach(async () => {
1434
1494
  warnSpy.mockRestore();
1435
1495
  try {
1436
- await vectorDB.deleteIndex(indexName2);
1496
+ await vectorDB.deleteIndex({ indexName: indexName2 });
1437
1497
  } catch {
1438
1498
  // Ignore errors if index doesn't exist
1439
1499
  }
@@ -1517,7 +1577,7 @@ describe('ChromaVector Integration Tests', () => {
1517
1577
 
1518
1578
  beforeEach(async () => {
1519
1579
  try {
1520
- await vectorDB.deleteIndex(perfTestIndex);
1580
+ await vectorDB.deleteIndex({ indexName: perfTestIndex });
1521
1581
  } catch {
1522
1582
  // Ignore errors if index doesn't exist
1523
1583
  }
@@ -1526,7 +1586,7 @@ describe('ChromaVector Integration Tests', () => {
1526
1586
 
1527
1587
  afterEach(async () => {
1528
1588
  try {
1529
- await vectorDB.deleteIndex(perfTestIndex);
1589
+ await vectorDB.deleteIndex({ indexName: perfTestIndex });
1530
1590
  } catch {
1531
1591
  // Ignore cleanup errors
1532
1592
  }
@@ -1569,7 +1629,7 @@ describe('ChromaVector Integration Tests', () => {
1569
1629
  });
1570
1630
 
1571
1631
  // Verify all vectors were inserted
1572
- const stats = await vectorDB.describeIndex(perfTestIndex);
1632
+ const stats = await vectorDB.describeIndex({ indexName: perfTestIndex });
1573
1633
  expect(stats.count).toBe(batchSize);
1574
1634
 
1575
1635
  const results = await vectorDB.query({
@@ -8,6 +8,10 @@ import type {
8
8
  ParamsToArgs,
9
9
  QueryVectorArgs,
10
10
  UpsertVectorArgs,
11
+ DescribeIndexParams,
12
+ DeleteIndexParams,
13
+ DeleteVectorParams,
14
+ UpdateVectorParams,
11
15
  } from '@mastra/core/vector';
12
16
 
13
17
  import type { VectorFilter } from '@mastra/core/vector/filter';
@@ -80,7 +84,7 @@ export class ChromaVector extends MastraVector {
80
84
  const collection = await this.getCollection(indexName);
81
85
 
82
86
  // Get index stats to check dimension
83
- const stats = await this.describeIndex(indexName);
87
+ const stats = await this.describeIndex({ indexName });
84
88
 
85
89
  // Validate vector dimensions
86
90
  this.validateVectorDimensions(vectors, stats.dimension);
@@ -111,7 +115,6 @@ export class ChromaVector extends MastraVector {
111
115
 
112
116
  async createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void> {
113
117
  const params = this.normalizeArgs<CreateIndexParams>('createIndex', args);
114
-
115
118
  const { indexName, dimension, metric = 'cosine' } = params;
116
119
 
117
120
  if (!Number.isInteger(dimension) || dimension <= 0) {
@@ -121,13 +124,24 @@ export class ChromaVector extends MastraVector {
121
124
  if (!['cosine', 'l2', 'ip'].includes(hnswSpace)) {
122
125
  throw new Error(`Invalid metric: "${metric}". Must be one of: cosine, euclidean, dotproduct`);
123
126
  }
124
- await this.client.createCollection({
125
- name: indexName,
126
- metadata: {
127
- dimension,
128
- 'hnsw:space': this.HnswSpaceMap[metric],
129
- },
130
- });
127
+ try {
128
+ await this.client.createCollection({
129
+ name: indexName,
130
+ metadata: {
131
+ dimension,
132
+ 'hnsw:space': hnswSpace,
133
+ },
134
+ });
135
+ } catch (error: any) {
136
+ // Check for 'already exists' error
137
+ const message = error?.message || error?.toString();
138
+ if (message && message.toLowerCase().includes('already exists')) {
139
+ // Fetch collection info and check dimension
140
+ await this.validateExistingIndex(indexName, dimension, metric);
141
+ return;
142
+ }
143
+ throw error;
144
+ }
131
145
  }
132
146
 
133
147
  transformFilter(filter?: VectorFilter) {
@@ -167,7 +181,17 @@ export class ChromaVector extends MastraVector {
167
181
  return collections.map(collection => collection);
168
182
  }
169
183
 
170
- async describeIndex(indexName: string): Promise<IndexStats> {
184
+ /**
185
+ * Retrieves statistics about a vector index.
186
+ *
187
+ * @param params - The parameters for describing an index
188
+ * @param params.indexName - The name of the index to describe
189
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
190
+ */
191
+ async describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats> {
192
+ const params = this.normalizeArgs<DescribeIndexParams>('describeIndex', args);
193
+ const { indexName } = params;
194
+
171
195
  const collection = await this.getCollection(indexName);
172
196
  const count = await collection.count();
173
197
  const metadata = collection.metadata;
@@ -181,41 +205,108 @@ export class ChromaVector extends MastraVector {
181
205
  };
182
206
  }
183
207
 
184
- async deleteIndex(indexName: string): Promise<void> {
208
+ async deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void> {
209
+ const params = this.normalizeArgs<DeleteIndexParams>('deleteIndex', args);
210
+ const { indexName } = params;
185
211
  await this.client.deleteCollection({ name: indexName });
186
212
  this.collections.delete(indexName);
187
213
  }
188
214
 
215
+ /**
216
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
217
+ *
218
+ * Updates a vector by its ID with the provided vector and/or metadata.
219
+ * @param indexName - The name of the index containing the vector.
220
+ * @param id - The ID of the vector to update.
221
+ * @param update - An object containing the vector and/or metadata to update.
222
+ * @param update.vector - An optional array of numbers representing the new vector.
223
+ * @param update.metadata - An optional record containing the new metadata.
224
+ * @returns A promise that resolves when the update is complete.
225
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
226
+ */
189
227
  async updateIndexById(
190
228
  indexName: string,
191
229
  id: string,
192
230
  update: { vector?: number[]; metadata?: Record<string, any> },
193
231
  ): Promise<void> {
194
- if (!update.vector && !update.metadata) {
195
- throw new Error('No updates provided');
196
- }
232
+ this.logger.warn(
233
+ `Deprecation Warning: updateIndexById() is deprecated.
234
+ Please use updateVector() instead.
235
+ updateIndexById() will be removed on May 20th, 2025.`,
236
+ );
237
+ await this.updateVector({ indexName, id, update });
238
+ }
197
239
 
198
- const collection: Collection = await this.getCollection(indexName, true);
240
+ /**
241
+ * Updates a vector by its ID with the provided vector and/or metadata.
242
+ * @param indexName - The name of the index containing the vector.
243
+ * @param id - The ID of the vector to update.
244
+ * @param update - An object containing the vector and/or metadata to update.
245
+ * @param update.vector - An optional array of numbers representing the new vector.
246
+ * @param update.metadata - An optional record containing the new metadata.
247
+ * @returns A promise that resolves when the update is complete.
248
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
249
+ */
250
+ async updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void> {
251
+ const params = this.normalizeArgs<UpdateVectorParams>('updateVector', args);
252
+ const { indexName, id, update } = params;
253
+ try {
254
+ if (!update.vector && !update.metadata) {
255
+ throw new Error('No updates provided');
256
+ }
199
257
 
200
- const updateOptions: UpdateRecordsParams = { ids: [id] };
258
+ const collection: Collection = await this.getCollection(indexName, true);
201
259
 
202
- if (update?.vector) {
203
- updateOptions.embeddings = [update.vector];
204
- }
260
+ const updateOptions: UpdateRecordsParams = { ids: [id] };
205
261
 
206
- if (update?.metadata) {
207
- updateOptions.metadatas = [update.metadata];
208
- }
262
+ if (update?.vector) {
263
+ const stats = await this.describeIndex({ indexName });
264
+ this.validateVectorDimensions([update.vector], stats.dimension);
265
+ updateOptions.embeddings = [update.vector];
266
+ }
267
+
268
+ if (update?.metadata) {
269
+ updateOptions.metadatas = [update.metadata];
270
+ }
209
271
 
210
- return await collection.update(updateOptions);
272
+ return await collection.update(updateOptions);
273
+ } catch (error: any) {
274
+ throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
275
+ }
211
276
  }
212
277
 
278
+ /**
279
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
280
+ *
281
+ * Deletes a vector by its ID.
282
+ * @param indexName - The name of the index containing the vector.
283
+ * @param id - The ID of the vector to delete.
284
+ * @returns A promise that resolves when the deletion is complete.
285
+ * @throws Will throw an error if the deletion operation fails.
286
+ */
213
287
  async deleteIndexById(indexName: string, id: string): Promise<void> {
288
+ this.logger.warn(
289
+ `Deprecation Warning: deleteIndexById() is deprecated. Please use deleteVector() instead. deleteIndexById() will be removed on May 20th.`,
290
+ );
291
+ await this.deleteVector(indexName, id);
292
+ }
293
+
294
+ /**
295
+ * Deletes a vector by its ID.
296
+ * @param indexName - The name of the index containing the vector.
297
+ * @param id - The ID of the vector to delete.
298
+ * @returns A promise that resolves when the deletion is complete.
299
+ * @throws Will throw an error if the deletion operation fails.
300
+ */
301
+ async deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void> {
302
+ const params = this.normalizeArgs<DeleteVectorParams>('deleteVector', args);
303
+
304
+ const { indexName, id } = params;
214
305
  try {
215
306
  const collection: Collection = await this.getCollection(indexName, true);
216
307
  await collection.delete({ ids: [id] });
217
308
  } catch (error: any) {
218
- throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
309
+ throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
219
310
  }
220
311
  }
221
312
  }