@mastra/chroma 0.0.0-vnext-inngest-20250508131921 → 0.0.0-vnextAgentNetwork-20250602134426

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,16 +1,187 @@
1
1
  # @mastra/chroma
2
2
 
3
- ## 0.0.0-vnext-inngest-20250508131921
3
+ ## 0.0.0-vnextAgentNetwork-20250602134426
4
+
5
+ ### Patch Changes
6
+
7
+ - f0d559f: Fix peerdeps for alpha channel
8
+ - Updated dependencies [ee77e78]
9
+ - Updated dependencies [592a2db]
10
+ - Updated dependencies [e5dc18d]
11
+ - Updated dependencies [ab5adbe]
12
+ - Updated dependencies [1e8bb40]
13
+ - Updated dependencies [195c428]
14
+ - Updated dependencies [f73e11b]
15
+ - Updated dependencies [c5bf1ce]
16
+ - Updated dependencies [12b7002]
17
+ - Updated dependencies [2901125]
18
+ - @mastra/core@0.0.0-vnextAgentNetwork-20250602134426
19
+
20
+ ## 0.10.1-alpha.0
21
+
22
+ ### Patch Changes
23
+
24
+ - f0d559f: Fix peerdeps for alpha channel
25
+ - Updated dependencies [1e8bb40]
26
+ - @mastra/core@0.10.2-alpha.2
27
+
28
+ ## 0.10.0
29
+
30
+ ### Minor Changes
31
+
32
+ - 83da932: Move @mastra/core to peerdeps
33
+
34
+ ### Patch Changes
35
+
36
+ - d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
37
+ - a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
38
+ - Updated dependencies [b3a3d63]
39
+ - Updated dependencies [344f453]
40
+ - Updated dependencies [0a3ae6d]
41
+ - Updated dependencies [95911be]
42
+ - Updated dependencies [f53a6ac]
43
+ - Updated dependencies [5eb5a99]
44
+ - Updated dependencies [7e632c5]
45
+ - Updated dependencies [1e9fbfa]
46
+ - Updated dependencies [eabdcd9]
47
+ - Updated dependencies [90be034]
48
+ - Updated dependencies [99f050a]
49
+ - Updated dependencies [d0ee3c6]
50
+ - Updated dependencies [b2ae5aa]
51
+ - Updated dependencies [23f258c]
52
+ - Updated dependencies [a7292b0]
53
+ - Updated dependencies [0dcb9f0]
54
+ - Updated dependencies [2672a05]
55
+ - @mastra/core@0.10.0
56
+
57
+ ## 0.3.0-alpha.1
58
+
59
+ ### Minor Changes
60
+
61
+ - 83da932: Move @mastra/core to peerdeps
62
+
63
+ ### Patch Changes
64
+
65
+ - a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
66
+ - Updated dependencies [b3a3d63]
67
+ - Updated dependencies [344f453]
68
+ - Updated dependencies [0a3ae6d]
69
+ - Updated dependencies [95911be]
70
+ - Updated dependencies [5eb5a99]
71
+ - Updated dependencies [7e632c5]
72
+ - Updated dependencies [1e9fbfa]
73
+ - Updated dependencies [b2ae5aa]
74
+ - Updated dependencies [a7292b0]
75
+ - Updated dependencies [0dcb9f0]
76
+ - @mastra/core@0.10.0-alpha.1
77
+
78
+ ## 0.2.16-alpha.0
79
+
80
+ ### Patch Changes
81
+
82
+ - d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
83
+ - Updated dependencies [f53a6ac]
84
+ - Updated dependencies [eabdcd9]
85
+ - Updated dependencies [90be034]
86
+ - Updated dependencies [99f050a]
87
+ - Updated dependencies [d0ee3c6]
88
+ - Updated dependencies [23f258c]
89
+ - Updated dependencies [2672a05]
90
+ - @mastra/core@0.9.5-alpha.0
91
+
92
+ ## 0.2.15
93
+
94
+ ### Patch Changes
95
+
96
+ - c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
97
+ - Updated dependencies [396be50]
98
+ - Updated dependencies [ab80e7e]
99
+ - Updated dependencies [c3bd795]
100
+ - Updated dependencies [da082f8]
101
+ - Updated dependencies [a5810ce]
102
+ - Updated dependencies [3e9c131]
103
+ - Updated dependencies [3171b5b]
104
+ - Updated dependencies [973e5ac]
105
+ - Updated dependencies [daf942f]
106
+ - Updated dependencies [0b8b868]
107
+ - Updated dependencies [9e1eff5]
108
+ - Updated dependencies [6fa1ad1]
109
+ - Updated dependencies [c28d7a0]
110
+ - Updated dependencies [edf1e88]
111
+ - @mastra/core@0.9.4
112
+
113
+ ## 0.2.15-alpha.4
114
+
115
+ ### Patch Changes
116
+
117
+ - Updated dependencies [3e9c131]
118
+ - @mastra/core@0.9.4-alpha.4
119
+
120
+ ## 0.2.15-alpha.3
121
+
122
+ ### Patch Changes
123
+
124
+ - c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
125
+ - Updated dependencies [396be50]
126
+ - Updated dependencies [c3bd795]
127
+ - Updated dependencies [da082f8]
128
+ - Updated dependencies [a5810ce]
129
+ - @mastra/core@0.9.4-alpha.3
130
+
131
+ ## 0.2.15-alpha.2
132
+
133
+ ### Patch Changes
134
+
135
+ - Updated dependencies [3171b5b]
136
+ - Updated dependencies [973e5ac]
137
+ - Updated dependencies [9e1eff5]
138
+ - @mastra/core@0.9.4-alpha.2
139
+
140
+ ## 0.2.15-alpha.1
141
+
142
+ ### Patch Changes
143
+
144
+ - Updated dependencies [ab80e7e]
145
+ - Updated dependencies [6fa1ad1]
146
+ - Updated dependencies [c28d7a0]
147
+ - Updated dependencies [edf1e88]
148
+ - @mastra/core@0.9.4-alpha.1
149
+
150
+ ## 0.2.15-alpha.0
151
+
152
+ ### Patch Changes
153
+
154
+ - Updated dependencies [daf942f]
155
+ - Updated dependencies [0b8b868]
156
+ - @mastra/core@0.9.4-alpha.0
157
+
158
+ ## 0.2.14
4
159
 
5
160
  ### Patch Changes
6
161
 
7
162
  - 9cd1a46: [MASTRA-3338] update naming scheme for embedding index based on vector store rules and added duplicate index checks
163
+ - Updated dependencies [e450778]
164
+ - Updated dependencies [8902157]
165
+ - Updated dependencies [ca0dc88]
8
166
  - Updated dependencies [526c570]
167
+ - Updated dependencies [d7a6a33]
9
168
  - Updated dependencies [9cd1a46]
10
169
  - Updated dependencies [b5d2de0]
11
170
  - Updated dependencies [644f8ad]
12
171
  - Updated dependencies [70dbf51]
13
- - @mastra/core@0.0.0-vnext-inngest-20250508131921
172
+ - @mastra/core@0.9.3
173
+
174
+ ## 0.2.14-alpha.1
175
+
176
+ ### Patch Changes
177
+
178
+ - 9cd1a46: [MASTRA-3338] update naming scheme for embedding index based on vector store rules and added duplicate index checks
179
+ - Updated dependencies [e450778]
180
+ - Updated dependencies [8902157]
181
+ - Updated dependencies [ca0dc88]
182
+ - Updated dependencies [9cd1a46]
183
+ - Updated dependencies [70dbf51]
184
+ - @mastra/core@0.9.3-alpha.1
14
185
 
15
186
  ## 0.2.14-alpha.0
16
187
 
@@ -1,13 +1,14 @@
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';
6
- import type { ParamsToArgs } from '@mastra/core/vector';
7
9
  import type { QueryResult } from '@mastra/core/vector';
8
- import type { QueryVectorArgs } from '@mastra/core/vector';
9
10
  import type { QueryVectorParams } from '@mastra/core/vector';
10
- import type { UpsertVectorArgs } from '@mastra/core/vector';
11
+ import type { UpdateVectorParams } from '@mastra/core/vector';
11
12
  import type { UpsertVectorParams } from '@mastra/core/vector';
12
13
  import type { VectorFilter } from '@mastra/core/vector/filter';
13
14
 
@@ -31,14 +32,10 @@ export declare class ChromaFilterTranslator extends BaseFilterTranslator {
31
32
  private translateOperator;
32
33
  }
33
34
 
34
- declare type ChromaQueryArgs = [...QueryVectorArgs, VectorFilter?];
35
-
36
35
  declare interface ChromaQueryVectorParams extends QueryVectorParams {
37
36
  documentFilter?: VectorFilter;
38
37
  }
39
38
 
40
- declare type ChromaUpsertArgs = [...UpsertVectorArgs, string[]?];
41
-
42
39
  declare interface ChromaUpsertVectorParams extends UpsertVectorParams {
43
40
  documents?: string[];
44
41
  }
@@ -55,19 +52,39 @@ declare class ChromaVector extends MastraVector {
55
52
  });
56
53
  getCollection(indexName: string, throwIfNotExists?: boolean): Promise<any>;
57
54
  private validateVectorDimensions;
58
- upsert(...args: ParamsToArgs<ChromaUpsertVectorParams> | ChromaUpsertArgs): Promise<string[]>;
55
+ upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]>;
59
56
  private HnswSpaceMap;
60
- createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void>;
57
+ createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
61
58
  transformFilter(filter?: VectorFilter): VectorFilter;
62
- query(...args: ParamsToArgs<ChromaQueryVectorParams> | ChromaQueryArgs): Promise<QueryResult[]>;
59
+ query({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: ChromaQueryVectorParams): Promise<QueryResult[]>;
63
60
  listIndexes(): Promise<string[]>;
64
- describeIndex(indexName: string): Promise<IndexStats>;
65
- deleteIndex(indexName: string): Promise<void>;
66
- updateIndexById(indexName: string, id: string, update: {
67
- vector?: number[];
68
- metadata?: Record<string, any>;
69
- }): Promise<void>;
70
- deleteIndexById(indexName: string, id: string): Promise<void>;
61
+ /**
62
+ * Retrieves statistics about a vector index.
63
+ *
64
+ * @param {string} indexName - The name of the index to describe
65
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
66
+ */
67
+ describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
68
+ deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
69
+ /**
70
+ * Updates a vector by its ID with the provided vector and/or metadata.
71
+ * @param indexName - The name of the index containing the vector.
72
+ * @param id - The ID of the vector to update.
73
+ * @param update - An object containing the vector and/or metadata to update.
74
+ * @param update.vector - An optional array of numbers representing the new vector.
75
+ * @param update.metadata - An optional record containing the new metadata.
76
+ * @returns A promise that resolves when the update is complete.
77
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
78
+ */
79
+ updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
80
+ /**
81
+ * Deletes a vector by its ID.
82
+ * @param indexName - The name of the index containing the vector.
83
+ * @param id - The ID of the vector to delete.
84
+ * @returns A promise that resolves when the deletion is complete.
85
+ * @throws Will throw an error if the deletion operation fails.
86
+ */
87
+ deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
71
88
  }
72
89
  export { ChromaVector }
73
90
  export { ChromaVector as ChromaVector_alias_1 }
@@ -1,13 +1,14 @@
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';
6
- import type { ParamsToArgs } from '@mastra/core/vector';
7
9
  import type { QueryResult } from '@mastra/core/vector';
8
- import type { QueryVectorArgs } from '@mastra/core/vector';
9
10
  import type { QueryVectorParams } from '@mastra/core/vector';
10
- import type { UpsertVectorArgs } from '@mastra/core/vector';
11
+ import type { UpdateVectorParams } from '@mastra/core/vector';
11
12
  import type { UpsertVectorParams } from '@mastra/core/vector';
12
13
  import type { VectorFilter } from '@mastra/core/vector/filter';
13
14
 
@@ -31,14 +32,10 @@ export declare class ChromaFilterTranslator extends BaseFilterTranslator {
31
32
  private translateOperator;
32
33
  }
33
34
 
34
- declare type ChromaQueryArgs = [...QueryVectorArgs, VectorFilter?];
35
-
36
35
  declare interface ChromaQueryVectorParams extends QueryVectorParams {
37
36
  documentFilter?: VectorFilter;
38
37
  }
39
38
 
40
- declare type ChromaUpsertArgs = [...UpsertVectorArgs, string[]?];
41
-
42
39
  declare interface ChromaUpsertVectorParams extends UpsertVectorParams {
43
40
  documents?: string[];
44
41
  }
@@ -55,19 +52,39 @@ declare class ChromaVector extends MastraVector {
55
52
  });
56
53
  getCollection(indexName: string, throwIfNotExists?: boolean): Promise<any>;
57
54
  private validateVectorDimensions;
58
- upsert(...args: ParamsToArgs<ChromaUpsertVectorParams> | ChromaUpsertArgs): Promise<string[]>;
55
+ upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]>;
59
56
  private HnswSpaceMap;
60
- createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void>;
57
+ createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
61
58
  transformFilter(filter?: VectorFilter): VectorFilter;
62
- query(...args: ParamsToArgs<ChromaQueryVectorParams> | ChromaQueryArgs): Promise<QueryResult[]>;
59
+ query({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: ChromaQueryVectorParams): Promise<QueryResult[]>;
63
60
  listIndexes(): Promise<string[]>;
64
- describeIndex(indexName: string): Promise<IndexStats>;
65
- deleteIndex(indexName: string): Promise<void>;
66
- updateIndexById(indexName: string, id: string, update: {
67
- vector?: number[];
68
- metadata?: Record<string, any>;
69
- }): Promise<void>;
70
- deleteIndexById(indexName: string, id: string): Promise<void>;
61
+ /**
62
+ * Retrieves statistics about a vector index.
63
+ *
64
+ * @param {string} indexName - The name of the index to describe
65
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
66
+ */
67
+ describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
68
+ deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
69
+ /**
70
+ * Updates a vector by its ID with the provided vector and/or metadata.
71
+ * @param indexName - The name of the index containing the vector.
72
+ * @param id - The ID of the vector to update.
73
+ * @param update - An object containing the vector and/or metadata to update.
74
+ * @param update.vector - An optional array of numbers representing the new vector.
75
+ * @param update.metadata - An optional record containing the new metadata.
76
+ * @returns A promise that resolves when the update is complete.
77
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
78
+ */
79
+ updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
80
+ /**
81
+ * Deletes a vector by its ID.
82
+ * @param indexName - The name of the index containing the vector.
83
+ * @param id - The ID of the vector to delete.
84
+ * @returns A promise that resolves when the deletion is complete.
85
+ * @throws Will throw an error if the deletion operation fails.
86
+ */
87
+ deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
71
88
  }
72
89
  export { ChromaVector }
73
90
  export { ChromaVector as ChromaVector_alias_1 }
package/dist/index.cjs CHANGED
@@ -124,11 +124,9 @@ var ChromaVector = class extends vector.MastraVector {
124
124
  }
125
125
  }
126
126
  }
127
- async upsert(...args) {
128
- const params = this.normalizeArgs("upsert", args, ["documents"]);
129
- const { indexName, vectors, metadata, ids, documents } = params;
127
+ async upsert({ indexName, vectors, metadata, ids, documents }) {
130
128
  const collection = await this.getCollection(indexName);
131
- const stats = await this.describeIndex(indexName);
129
+ const stats = await this.describeIndex({ indexName });
132
130
  this.validateVectorDimensions(vectors, stats.dimension);
133
131
  const generatedIds = ids || vectors.map(() => crypto.randomUUID());
134
132
  const normalizedMetadata = metadata || vectors.map(() => ({}));
@@ -147,9 +145,7 @@ var ChromaVector = class extends vector.MastraVector {
147
145
  l2: "euclidean",
148
146
  ip: "dotproduct"
149
147
  };
150
- async createIndex(...args) {
151
- const params = this.normalizeArgs("createIndex", args);
152
- const { indexName, dimension, metric = "cosine" } = params;
148
+ async createIndex({ indexName, dimension, metric = "cosine" }) {
153
149
  if (!Number.isInteger(dimension) || dimension <= 0) {
154
150
  throw new Error("Dimension must be a positive integer");
155
151
  }
@@ -178,9 +174,14 @@ var ChromaVector = class extends vector.MastraVector {
178
174
  const translator = new ChromaFilterTranslator();
179
175
  return translator.translate(filter);
180
176
  }
181
- async query(...args) {
182
- const params = this.normalizeArgs("query", args, ["documentFilter"]);
183
- const { indexName, queryVector, topK = 10, filter, includeVector = false, documentFilter } = params;
177
+ async query({
178
+ indexName,
179
+ queryVector,
180
+ topK = 10,
181
+ filter,
182
+ includeVector = false,
183
+ documentFilter
184
+ }) {
184
185
  const collection = await this.getCollection(indexName, true);
185
186
  const defaultInclude = ["documents", "metadatas", "distances"];
186
187
  const translatedFilter = this.transformFilter(filter);
@@ -203,7 +204,13 @@ var ChromaVector = class extends vector.MastraVector {
203
204
  const collections = await this.client.listCollections();
204
205
  return collections.map((collection) => collection);
205
206
  }
206
- async describeIndex(indexName) {
207
+ /**
208
+ * Retrieves statistics about a vector index.
209
+ *
210
+ * @param {string} 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({ indexName }) {
207
214
  const collection = await this.getCollection(indexName);
208
215
  const count = await collection.count();
209
216
  const metadata = collection.metadata;
@@ -214,30 +221,53 @@ var ChromaVector = class extends vector.MastraVector {
214
221
  metric: this.HnswSpaceMap[hnswSpace]
215
222
  };
216
223
  }
217
- async deleteIndex(indexName) {
224
+ async deleteIndex({ indexName }) {
218
225
  await this.client.deleteCollection({ name: indexName });
219
226
  this.collections.delete(indexName);
220
227
  }
221
- async updateIndexById(indexName, id, update) {
222
- if (!update.vector && !update.metadata) {
223
- throw new Error("No updates provided");
224
- }
225
- const collection = await this.getCollection(indexName, true);
226
- const updateOptions = { ids: [id] };
227
- if (update?.vector) {
228
- updateOptions.embeddings = [update.vector];
229
- }
230
- if (update?.metadata) {
231
- updateOptions.metadatas = [update.metadata];
228
+ /**
229
+ * Updates a vector by its ID with the provided vector and/or metadata.
230
+ * @param indexName - The name of the index containing the vector.
231
+ * @param id - The ID of the vector to update.
232
+ * @param update - An object containing the vector and/or metadata to update.
233
+ * @param update.vector - An optional array of numbers representing the new vector.
234
+ * @param update.metadata - An optional record containing the new metadata.
235
+ * @returns A promise that resolves when the update is complete.
236
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
237
+ */
238
+ async updateVector({ indexName, id, update }) {
239
+ try {
240
+ if (!update.vector && !update.metadata) {
241
+ throw new Error("No updates provided");
242
+ }
243
+ const collection = await this.getCollection(indexName, true);
244
+ const updateOptions = { ids: [id] };
245
+ if (update?.vector) {
246
+ const stats = await this.describeIndex({ indexName });
247
+ this.validateVectorDimensions([update.vector], stats.dimension);
248
+ updateOptions.embeddings = [update.vector];
249
+ }
250
+ if (update?.metadata) {
251
+ updateOptions.metadatas = [update.metadata];
252
+ }
253
+ 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}`);
232
256
  }
233
- return await collection.update(updateOptions);
234
257
  }
235
- async deleteIndexById(indexName, id) {
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
+ async deleteVector({ indexName, id }) {
236
266
  try {
237
267
  const collection = await this.getCollection(indexName, true);
238
268
  await collection.delete({ ids: [id] });
239
269
  } catch (error) {
240
- throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
270
+ throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
241
271
  }
242
272
  }
243
273
  };
package/dist/index.js CHANGED
@@ -122,11 +122,9 @@ var ChromaVector = class extends MastraVector {
122
122
  }
123
123
  }
124
124
  }
125
- async upsert(...args) {
126
- const params = this.normalizeArgs("upsert", args, ["documents"]);
127
- const { indexName, vectors, metadata, ids, documents } = params;
125
+ async upsert({ indexName, vectors, metadata, ids, documents }) {
128
126
  const collection = await this.getCollection(indexName);
129
- const stats = await this.describeIndex(indexName);
127
+ const stats = await this.describeIndex({ indexName });
130
128
  this.validateVectorDimensions(vectors, stats.dimension);
131
129
  const generatedIds = ids || vectors.map(() => crypto.randomUUID());
132
130
  const normalizedMetadata = metadata || vectors.map(() => ({}));
@@ -145,9 +143,7 @@ var ChromaVector = class extends MastraVector {
145
143
  l2: "euclidean",
146
144
  ip: "dotproduct"
147
145
  };
148
- async createIndex(...args) {
149
- const params = this.normalizeArgs("createIndex", args);
150
- const { indexName, dimension, metric = "cosine" } = params;
146
+ async createIndex({ indexName, dimension, metric = "cosine" }) {
151
147
  if (!Number.isInteger(dimension) || dimension <= 0) {
152
148
  throw new Error("Dimension must be a positive integer");
153
149
  }
@@ -176,9 +172,14 @@ var ChromaVector = class extends MastraVector {
176
172
  const translator = new ChromaFilterTranslator();
177
173
  return translator.translate(filter);
178
174
  }
179
- async query(...args) {
180
- const params = this.normalizeArgs("query", args, ["documentFilter"]);
181
- const { indexName, queryVector, topK = 10, filter, includeVector = false, documentFilter } = params;
175
+ async query({
176
+ indexName,
177
+ queryVector,
178
+ topK = 10,
179
+ filter,
180
+ includeVector = false,
181
+ documentFilter
182
+ }) {
182
183
  const collection = await this.getCollection(indexName, true);
183
184
  const defaultInclude = ["documents", "metadatas", "distances"];
184
185
  const translatedFilter = this.transformFilter(filter);
@@ -201,7 +202,13 @@ var ChromaVector = class extends MastraVector {
201
202
  const collections = await this.client.listCollections();
202
203
  return collections.map((collection) => collection);
203
204
  }
204
- async describeIndex(indexName) {
205
+ /**
206
+ * Retrieves statistics about a vector index.
207
+ *
208
+ * @param {string} 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({ indexName }) {
205
212
  const collection = await this.getCollection(indexName);
206
213
  const count = await collection.count();
207
214
  const metadata = collection.metadata;
@@ -212,30 +219,53 @@ var ChromaVector = class extends MastraVector {
212
219
  metric: this.HnswSpaceMap[hnswSpace]
213
220
  };
214
221
  }
215
- async deleteIndex(indexName) {
222
+ async deleteIndex({ indexName }) {
216
223
  await this.client.deleteCollection({ name: indexName });
217
224
  this.collections.delete(indexName);
218
225
  }
219
- async updateIndexById(indexName, id, update) {
220
- if (!update.vector && !update.metadata) {
221
- throw new Error("No updates provided");
222
- }
223
- const collection = await this.getCollection(indexName, true);
224
- const updateOptions = { ids: [id] };
225
- if (update?.vector) {
226
- updateOptions.embeddings = [update.vector];
227
- }
228
- if (update?.metadata) {
229
- updateOptions.metadatas = [update.metadata];
226
+ /**
227
+ * Updates a vector by its ID with the provided vector and/or metadata.
228
+ * @param indexName - The name of the index containing the vector.
229
+ * @param id - The ID of the vector to update.
230
+ * @param update - An object containing the vector and/or metadata to update.
231
+ * @param update.vector - An optional array of numbers representing the new vector.
232
+ * @param update.metadata - An optional record containing the new metadata.
233
+ * @returns A promise that resolves when the update is complete.
234
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
235
+ */
236
+ async updateVector({ indexName, id, update }) {
237
+ try {
238
+ if (!update.vector && !update.metadata) {
239
+ throw new Error("No updates provided");
240
+ }
241
+ const collection = await this.getCollection(indexName, true);
242
+ const updateOptions = { ids: [id] };
243
+ if (update?.vector) {
244
+ const stats = await this.describeIndex({ indexName });
245
+ this.validateVectorDimensions([update.vector], stats.dimension);
246
+ updateOptions.embeddings = [update.vector];
247
+ }
248
+ if (update?.metadata) {
249
+ updateOptions.metadatas = [update.metadata];
250
+ }
251
+ return await collection.update(updateOptions);
252
+ } catch (error) {
253
+ throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
230
254
  }
231
- return await collection.update(updateOptions);
232
255
  }
233
- async deleteIndexById(indexName, id) {
256
+ /**
257
+ * Deletes a vector by its ID.
258
+ * @param indexName - The name of the index containing the vector.
259
+ * @param id - The ID of the vector to delete.
260
+ * @returns A promise that resolves when the deletion is complete.
261
+ * @throws Will throw an error if the deletion operation fails.
262
+ */
263
+ async deleteVector({ indexName, id }) {
234
264
  try {
235
265
  const collection = await this.getCollection(indexName, true);
236
266
  await collection.delete({ ids: [id] });
237
267
  } catch (error) {
238
- throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
268
+ throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
239
269
  }
240
270
  }
241
271
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/chroma",
3
- "version": "0.0.0-vnext-inngest-20250508131921",
3
+ "version": "0.0.0-vnextAgentNetwork-20250602134426",
4
4
  "description": "Chroma vector store provider for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,8 +20,7 @@
20
20
  },
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "chromadb": "^2.2.0",
24
- "@mastra/core": "0.0.0-vnext-inngest-20250508131921"
23
+ "chromadb": "^2.2.0"
25
24
  },
26
25
  "devDependencies": {
27
26
  "@microsoft/api-extractor": "^7.52.5",
@@ -30,7 +29,11 @@
30
29
  "tsup": "^8.4.0",
31
30
  "typescript": "^5.8.2",
32
31
  "vitest": "^3.1.2",
33
- "@internal/lint": "0.0.0-vnext-inngest-20250508131921"
32
+ "@internal/lint": "0.0.0-vnextAgentNetwork-20250602134426",
33
+ "@mastra/core": "0.0.0-vnextAgentNetwork-20250602134426"
34
+ },
35
+ "peerDependencies": {
36
+ "@mastra/core": "^0.10.0-alpha.0"
34
37
  },
35
38
  "scripts": {
36
39
  "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,
@@ -279,7 +281,7 @@ describe('ChromaVector Integration Tests', () => {
279
281
  });
280
282
 
281
283
  afterAll(async () => {
282
- await vectorDB.deleteIndex(testIndexName);
284
+ await vectorDB.deleteIndex({ indexName: testIndexName });
283
285
  });
284
286
 
285
287
  it('should handle non-existent index queries', async () => {
@@ -342,7 +344,7 @@ describe('ChromaVector Integration Tests', () => {
342
344
  infoSpy.mockRestore();
343
345
  warnSpy.mockRestore();
344
346
  // Cleanup
345
- await vectorDB.deleteIndex(duplicateIndexName);
347
+ await vectorDB.deleteIndex({ indexName: duplicateIndexName });
346
348
  }
347
349
  });
348
350
  });
@@ -519,7 +521,7 @@ describe('ChromaVector Integration Tests', () => {
519
521
  // Set up test vectors and metadata
520
522
  beforeAll(async () => {
521
523
  try {
522
- await vectorDB.deleteIndex(testIndexName2);
524
+ await vectorDB.deleteIndex({ indexName: testIndexName2 });
523
525
  } catch {
524
526
  // Ignore errors if index doesn't exist
525
527
  }
@@ -567,7 +569,7 @@ describe('ChromaVector Integration Tests', () => {
567
569
  afterAll(async () => {
568
570
  // Cleanup after tests
569
571
  try {
570
- await vectorDB.deleteIndex(testIndexName2);
572
+ await vectorDB.deleteIndex({ indexName: testIndexName2 });
571
573
  } catch {
572
574
  // Ignore cleanup errors
573
575
  }
@@ -1238,7 +1240,7 @@ describe('ChromaVector Integration Tests', () => {
1238
1240
 
1239
1241
  beforeAll(async () => {
1240
1242
  try {
1241
- await vectorDB.deleteIndex(testIndexName3);
1243
+ await vectorDB.deleteIndex({ indexName: testIndexName3 });
1242
1244
  } catch {
1243
1245
  // Ignore errors if index doesn't exist
1244
1246
  }
@@ -1272,7 +1274,7 @@ describe('ChromaVector Integration Tests', () => {
1272
1274
  afterAll(async () => {
1273
1275
  // Cleanup after tests
1274
1276
  try {
1275
- await vectorDB.deleteIndex(testIndexName3);
1277
+ await vectorDB.deleteIndex({ indexName: testIndexName3 });
1276
1278
  } catch {
1277
1279
  // Ignore cleanup errors
1278
1280
  }
@@ -1460,122 +1462,13 @@ describe('ChromaVector Integration Tests', () => {
1460
1462
  });
1461
1463
  });
1462
1464
  });
1463
- describe('Deprecation Warnings', () => {
1464
- const indexName = 'testdeprecationwarnings';
1465
-
1466
- const indexName2 = 'testdeprecationwarnings2';
1467
-
1468
- let warnSpy;
1469
-
1470
- beforeAll(async () => {
1471
- await vectorDB.createIndex({ indexName: indexName, dimension: 3 });
1472
- });
1473
-
1474
- afterAll(async () => {
1475
- try {
1476
- await vectorDB.deleteIndex(indexName);
1477
- } catch {
1478
- // Ignore errors if index doesn't exist
1479
- }
1480
- try {
1481
- await vectorDB.deleteIndex(indexName2);
1482
- } catch {
1483
- // Ignore errors if index doesn't exist
1484
- }
1485
- });
1486
-
1487
- beforeEach(async () => {
1488
- warnSpy = vi.spyOn(vectorDB['logger'], 'warn');
1489
- });
1490
-
1491
- afterEach(async () => {
1492
- warnSpy.mockRestore();
1493
- try {
1494
- await vectorDB.deleteIndex(indexName2);
1495
- } catch {
1496
- // Ignore errors if index doesn't exist
1497
- }
1498
- });
1499
-
1500
- it('should show deprecation warning when using individual args for createIndex', async () => {
1501
- await vectorDB.createIndex(indexName2, 3, 'cosine');
1502
-
1503
- expect(warnSpy).toHaveBeenCalledWith(
1504
- expect.stringContaining('Deprecation Warning: Passing individual arguments to createIndex() is deprecated'),
1505
- );
1506
- });
1507
-
1508
- it('should show deprecation warning when using individual args for upsert', async () => {
1509
- await vectorDB.upsert(indexName, [[1, 2, 3]], [{ test: 'data' }]);
1510
-
1511
- expect(warnSpy).toHaveBeenCalledWith(
1512
- expect.stringContaining('Deprecation Warning: Passing individual arguments to upsert() is deprecated'),
1513
- );
1514
- });
1515
-
1516
- it('should show deprecation warning when using individual args for query', async () => {
1517
- await vectorDB.query(indexName, [1, 2, 3], 5);
1518
-
1519
- expect(warnSpy).toHaveBeenCalledWith(
1520
- expect.stringContaining('Deprecation Warning: Passing individual arguments to query() is deprecated'),
1521
- );
1522
- });
1523
-
1524
- it('should not show deprecation warning when using object param for query', async () => {
1525
- await vectorDB.query({
1526
- indexName,
1527
- queryVector: [1, 2, 3],
1528
- topK: 5,
1529
- });
1530
-
1531
- expect(warnSpy).not.toHaveBeenCalled();
1532
- });
1533
-
1534
- it('should not show deprecation warning when using object param for createIndex', async () => {
1535
- await vectorDB.createIndex({
1536
- indexName: indexName2,
1537
- dimension: 3,
1538
- metric: 'cosine',
1539
- });
1540
-
1541
- expect(warnSpy).not.toHaveBeenCalled();
1542
- });
1543
-
1544
- it('should not show deprecation warning when using object param for upsert', async () => {
1545
- await vectorDB.upsert({
1546
- indexName,
1547
- vectors: [[1, 2, 3]],
1548
- metadata: [{ test: 'data' }],
1549
- });
1550
-
1551
- expect(warnSpy).not.toHaveBeenCalled();
1552
- });
1553
-
1554
- it('should maintain backward compatibility with individual args', async () => {
1555
- // Query
1556
- const queryResults = await vectorDB.query(indexName, [1, 2, 3], 5);
1557
- expect(Array.isArray(queryResults)).toBe(true);
1558
-
1559
- // CreateIndex
1560
- await expect(vectorDB.createIndex(indexName2, 3, 'cosine')).resolves.not.toThrow();
1561
-
1562
- // Upsert
1563
- const upsertResults = await vectorDB.upsert({
1564
- indexName,
1565
- vectors: [[1, 2, 3]],
1566
- metadata: [{ test: 'data' }],
1567
- });
1568
- expect(Array.isArray(upsertResults)).toBe(true);
1569
- expect(upsertResults).toHaveLength(1);
1570
- });
1571
- });
1572
1465
 
1573
1466
  describe('Performance and Concurrency', () => {
1574
1467
  const perfTestIndex = 'perf-test-index';
1575
1468
 
1576
1469
  beforeEach(async () => {
1577
1470
  try {
1578
- await vectorDB.deleteIndex(perfTestIndex);
1471
+ await vectorDB.deleteIndex({ indexName: perfTestIndex });
1579
1472
  } catch {
1580
1473
  // Ignore errors if index doesn't exist
1581
1474
  }
@@ -1584,7 +1477,7 @@ describe('ChromaVector Integration Tests', () => {
1584
1477
 
1585
1478
  afterEach(async () => {
1586
1479
  try {
1587
- await vectorDB.deleteIndex(perfTestIndex);
1480
+ await vectorDB.deleteIndex({ indexName: perfTestIndex });
1588
1481
  } catch {
1589
1482
  // Ignore cleanup errors
1590
1483
  }
@@ -1627,7 +1520,7 @@ describe('ChromaVector Integration Tests', () => {
1627
1520
  });
1628
1521
 
1629
1522
  // Verify all vectors were inserted
1630
- const stats = await vectorDB.describeIndex(perfTestIndex);
1523
+ const stats = await vectorDB.describeIndex({ indexName: perfTestIndex });
1631
1524
  expect(stats.count).toBe(batchSize);
1632
1525
 
1633
1526
  const results = await vectorDB.query({
@@ -5,9 +5,10 @@ import type {
5
5
  CreateIndexParams,
6
6
  UpsertVectorParams,
7
7
  QueryVectorParams,
8
- ParamsToArgs,
9
- QueryVectorArgs,
10
- UpsertVectorArgs,
8
+ DescribeIndexParams,
9
+ DeleteIndexParams,
10
+ DeleteVectorParams,
11
+ UpdateVectorParams,
11
12
  } from '@mastra/core/vector';
12
13
 
13
14
  import type { VectorFilter } from '@mastra/core/vector/filter';
@@ -19,14 +20,10 @@ interface ChromaUpsertVectorParams extends UpsertVectorParams {
19
20
  documents?: string[];
20
21
  }
21
22
 
22
- type ChromaUpsertArgs = [...UpsertVectorArgs, string[]?];
23
-
24
23
  interface ChromaQueryVectorParams extends QueryVectorParams {
25
24
  documentFilter?: VectorFilter;
26
25
  }
27
26
 
28
- type ChromaQueryArgs = [...QueryVectorArgs, VectorFilter?];
29
-
30
27
  export class ChromaVector extends MastraVector {
31
28
  private client: ChromaClient;
32
29
  private collections: Map<string, any>;
@@ -72,15 +69,11 @@ export class ChromaVector extends MastraVector {
72
69
  }
73
70
  }
74
71
 
75
- async upsert(...args: ParamsToArgs<ChromaUpsertVectorParams> | ChromaUpsertArgs): Promise<string[]> {
76
- const params = this.normalizeArgs<ChromaUpsertVectorParams, ChromaUpsertArgs>('upsert', args, ['documents']);
77
-
78
- const { indexName, vectors, metadata, ids, documents } = params;
79
-
72
+ async upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]> {
80
73
  const collection = await this.getCollection(indexName);
81
74
 
82
75
  // Get index stats to check dimension
83
- const stats = await this.describeIndex(indexName);
76
+ const stats = await this.describeIndex({ indexName });
84
77
 
85
78
  // Validate vector dimensions
86
79
  this.validateVectorDimensions(vectors, stats.dimension);
@@ -109,10 +102,7 @@ export class ChromaVector extends MastraVector {
109
102
  ip: 'dotproduct',
110
103
  };
111
104
 
112
- async createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void> {
113
- const params = this.normalizeArgs<CreateIndexParams>('createIndex', args);
114
- const { indexName, dimension, metric = 'cosine' } = params;
115
-
105
+ async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {
116
106
  if (!Number.isInteger(dimension) || dimension <= 0) {
117
107
  throw new Error('Dimension must be a positive integer');
118
108
  }
@@ -144,11 +134,14 @@ export class ChromaVector extends MastraVector {
144
134
  const translator = new ChromaFilterTranslator();
145
135
  return translator.translate(filter);
146
136
  }
147
- async query(...args: ParamsToArgs<ChromaQueryVectorParams> | ChromaQueryArgs): Promise<QueryResult[]> {
148
- const params = this.normalizeArgs<ChromaQueryVectorParams, ChromaQueryArgs>('query', args, ['documentFilter']);
149
-
150
- const { indexName, queryVector, topK = 10, filter, includeVector = false, documentFilter } = params;
151
-
137
+ async query({
138
+ indexName,
139
+ queryVector,
140
+ topK = 10,
141
+ filter,
142
+ includeVector = false,
143
+ documentFilter,
144
+ }: ChromaQueryVectorParams): Promise<QueryResult[]> {
152
145
  const collection = await this.getCollection(indexName, true);
153
146
 
154
147
  const defaultInclude = ['documents', 'metadatas', 'distances'];
@@ -177,7 +170,13 @@ export class ChromaVector extends MastraVector {
177
170
  return collections.map(collection => collection);
178
171
  }
179
172
 
180
- async describeIndex(indexName: string): Promise<IndexStats> {
173
+ /**
174
+ * Retrieves statistics about a vector index.
175
+ *
176
+ * @param {string} indexName - The name of the index to describe
177
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
178
+ */
179
+ async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {
181
180
  const collection = await this.getCollection(indexName);
182
181
  const count = await collection.count();
183
182
  const metadata = collection.metadata;
@@ -191,41 +190,60 @@ export class ChromaVector extends MastraVector {
191
190
  };
192
191
  }
193
192
 
194
- async deleteIndex(indexName: string): Promise<void> {
193
+ async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {
195
194
  await this.client.deleteCollection({ name: indexName });
196
195
  this.collections.delete(indexName);
197
196
  }
198
197
 
199
- async updateIndexById(
200
- indexName: string,
201
- id: string,
202
- update: { vector?: number[]; metadata?: Record<string, any> },
203
- ): Promise<void> {
204
- if (!update.vector && !update.metadata) {
205
- throw new Error('No updates provided');
206
- }
198
+ /**
199
+ * Updates a vector by its ID with the provided vector and/or metadata.
200
+ * @param indexName - The name of the index containing the vector.
201
+ * @param id - The ID of the vector to update.
202
+ * @param update - An object containing the vector and/or metadata to update.
203
+ * @param update.vector - An optional array of numbers representing the new vector.
204
+ * @param update.metadata - An optional record containing the new metadata.
205
+ * @returns A promise that resolves when the update is complete.
206
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
207
+ */
208
+ async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {
209
+ try {
210
+ if (!update.vector && !update.metadata) {
211
+ throw new Error('No updates provided');
212
+ }
207
213
 
208
- const collection: Collection = await this.getCollection(indexName, true);
214
+ const collection: Collection = await this.getCollection(indexName, true);
209
215
 
210
- const updateOptions: UpdateRecordsParams = { ids: [id] };
216
+ const updateOptions: UpdateRecordsParams = { ids: [id] };
211
217
 
212
- if (update?.vector) {
213
- updateOptions.embeddings = [update.vector];
214
- }
218
+ if (update?.vector) {
219
+ const stats = await this.describeIndex({ indexName });
220
+ this.validateVectorDimensions([update.vector], stats.dimension);
221
+ updateOptions.embeddings = [update.vector];
222
+ }
215
223
 
216
- if (update?.metadata) {
217
- updateOptions.metadatas = [update.metadata];
218
- }
224
+ if (update?.metadata) {
225
+ updateOptions.metadatas = [update.metadata];
226
+ }
219
227
 
220
- return await collection.update(updateOptions);
228
+ return await collection.update(updateOptions);
229
+ } catch (error: any) {
230
+ throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
231
+ }
221
232
  }
222
233
 
223
- async deleteIndexById(indexName: string, id: string): Promise<void> {
234
+ /**
235
+ * Deletes a vector by its ID.
236
+ * @param indexName - The name of the index containing the vector.
237
+ * @param id - The ID of the vector to delete.
238
+ * @returns A promise that resolves when the deletion is complete.
239
+ * @throws Will throw an error if the deletion operation fails.
240
+ */
241
+ async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {
224
242
  try {
225
243
  const collection: Collection = await this.getCollection(indexName, true);
226
244
  await collection.delete({ ids: [id] });
227
245
  } catch (error: any) {
228
- throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
246
+ throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
229
247
  }
230
248
  }
231
249
  }