@mastra/chroma 0.2.16-alpha.0 → 0.10.0
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +50 -0
- package/dist/_tsup-dts-rollup.d.cts +8 -42
- package/dist/_tsup-dts-rollup.d.ts +8 -42
- package/dist/index.cjs +15 -58
- package/dist/index.js +15 -58
- package/package.json +7 -4
- package/src/vector/index.test.ts +0 -109
- package/src/vector/index.ts +15 -78
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/chroma@0.
|
|
2
|
+
> @mastra/chroma@0.10.0-alpha.1 build /home/runner/work/mastra/mastra/stores/chroma
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 8245ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/chroma/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/chroma/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 8633ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m12.35 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 652ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m12.30 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 653ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @mastra/chroma
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 83da932: Move @mastra/core to peerdeps
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
|
|
12
|
+
- a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
|
|
13
|
+
- Updated dependencies [b3a3d63]
|
|
14
|
+
- Updated dependencies [344f453]
|
|
15
|
+
- Updated dependencies [0a3ae6d]
|
|
16
|
+
- Updated dependencies [95911be]
|
|
17
|
+
- Updated dependencies [f53a6ac]
|
|
18
|
+
- Updated dependencies [5eb5a99]
|
|
19
|
+
- Updated dependencies [7e632c5]
|
|
20
|
+
- Updated dependencies [1e9fbfa]
|
|
21
|
+
- Updated dependencies [eabdcd9]
|
|
22
|
+
- Updated dependencies [90be034]
|
|
23
|
+
- Updated dependencies [99f050a]
|
|
24
|
+
- Updated dependencies [d0ee3c6]
|
|
25
|
+
- Updated dependencies [b2ae5aa]
|
|
26
|
+
- Updated dependencies [23f258c]
|
|
27
|
+
- Updated dependencies [a7292b0]
|
|
28
|
+
- Updated dependencies [0dcb9f0]
|
|
29
|
+
- Updated dependencies [2672a05]
|
|
30
|
+
- @mastra/core@0.10.0
|
|
31
|
+
|
|
32
|
+
## 0.3.0-alpha.1
|
|
33
|
+
|
|
34
|
+
### Minor Changes
|
|
35
|
+
|
|
36
|
+
- 83da932: Move @mastra/core to peerdeps
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
|
|
41
|
+
- Updated dependencies [b3a3d63]
|
|
42
|
+
- Updated dependencies [344f453]
|
|
43
|
+
- Updated dependencies [0a3ae6d]
|
|
44
|
+
- Updated dependencies [95911be]
|
|
45
|
+
- Updated dependencies [5eb5a99]
|
|
46
|
+
- Updated dependencies [7e632c5]
|
|
47
|
+
- Updated dependencies [1e9fbfa]
|
|
48
|
+
- Updated dependencies [b2ae5aa]
|
|
49
|
+
- Updated dependencies [a7292b0]
|
|
50
|
+
- Updated dependencies [0dcb9f0]
|
|
51
|
+
- @mastra/core@0.10.0-alpha.1
|
|
52
|
+
|
|
3
53
|
## 0.2.16-alpha.0
|
|
4
54
|
|
|
5
55
|
### Patch Changes
|
|
@@ -6,12 +6,9 @@ import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
|
6
6
|
import type { IndexStats } from '@mastra/core/vector';
|
|
7
7
|
import { MastraVector } from '@mastra/core/vector';
|
|
8
8
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
9
|
-
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
10
9
|
import type { QueryResult } from '@mastra/core/vector';
|
|
11
|
-
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
12
10
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
13
11
|
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
14
|
-
import type { UpsertVectorArgs } from '@mastra/core/vector';
|
|
15
12
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
16
13
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
17
14
|
|
|
@@ -35,14 +32,10 @@ export declare class ChromaFilterTranslator extends BaseFilterTranslator {
|
|
|
35
32
|
private translateOperator;
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
declare type ChromaQueryArgs = [...QueryVectorArgs, VectorFilter?];
|
|
39
|
-
|
|
40
35
|
declare interface ChromaQueryVectorParams extends QueryVectorParams {
|
|
41
36
|
documentFilter?: VectorFilter;
|
|
42
37
|
}
|
|
43
38
|
|
|
44
|
-
declare type ChromaUpsertArgs = [...UpsertVectorArgs, string[]?];
|
|
45
|
-
|
|
46
39
|
declare interface ChromaUpsertVectorParams extends UpsertVectorParams {
|
|
47
40
|
documents?: string[];
|
|
48
41
|
}
|
|
@@ -59,24 +52,21 @@ declare class ChromaVector extends MastraVector {
|
|
|
59
52
|
});
|
|
60
53
|
getCollection(indexName: string, throwIfNotExists?: boolean): Promise<any>;
|
|
61
54
|
private validateVectorDimensions;
|
|
62
|
-
upsert(
|
|
55
|
+
upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]>;
|
|
63
56
|
private HnswSpaceMap;
|
|
64
|
-
createIndex(
|
|
57
|
+
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
65
58
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
66
|
-
query(
|
|
59
|
+
query({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: ChromaQueryVectorParams): Promise<QueryResult[]>;
|
|
67
60
|
listIndexes(): Promise<string[]>;
|
|
68
61
|
/**
|
|
69
62
|
* Retrieves statistics about a vector index.
|
|
70
63
|
*
|
|
71
|
-
* @param
|
|
72
|
-
* @param params.indexName - The name of the index to describe
|
|
64
|
+
* @param {string} indexName - The name of the index to describe
|
|
73
65
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
74
66
|
*/
|
|
75
|
-
describeIndex(
|
|
76
|
-
deleteIndex(
|
|
67
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
68
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
77
69
|
/**
|
|
78
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
79
|
-
*
|
|
80
70
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
81
71
|
* @param indexName - The name of the index containing the vector.
|
|
82
72
|
* @param id - The ID of the vector to update.
|
|
@@ -86,31 +76,7 @@ declare class ChromaVector extends MastraVector {
|
|
|
86
76
|
* @returns A promise that resolves when the update is complete.
|
|
87
77
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
88
78
|
*/
|
|
89
|
-
|
|
90
|
-
vector?: number[];
|
|
91
|
-
metadata?: Record<string, any>;
|
|
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
|
-
*/
|
|
113
|
-
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
79
|
+
updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
|
|
114
80
|
/**
|
|
115
81
|
* Deletes a vector by its ID.
|
|
116
82
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -118,7 +84,7 @@ declare class ChromaVector extends MastraVector {
|
|
|
118
84
|
* @returns A promise that resolves when the deletion is complete.
|
|
119
85
|
* @throws Will throw an error if the deletion operation fails.
|
|
120
86
|
*/
|
|
121
|
-
deleteVector(
|
|
87
|
+
deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
|
|
122
88
|
}
|
|
123
89
|
export { ChromaVector }
|
|
124
90
|
export { ChromaVector as ChromaVector_alias_1 }
|
|
@@ -6,12 +6,9 @@ import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
|
6
6
|
import type { IndexStats } from '@mastra/core/vector';
|
|
7
7
|
import { MastraVector } from '@mastra/core/vector';
|
|
8
8
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
9
|
-
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
10
9
|
import type { QueryResult } from '@mastra/core/vector';
|
|
11
|
-
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
12
10
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
13
11
|
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
14
|
-
import type { UpsertVectorArgs } from '@mastra/core/vector';
|
|
15
12
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
16
13
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
17
14
|
|
|
@@ -35,14 +32,10 @@ export declare class ChromaFilterTranslator extends BaseFilterTranslator {
|
|
|
35
32
|
private translateOperator;
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
declare type ChromaQueryArgs = [...QueryVectorArgs, VectorFilter?];
|
|
39
|
-
|
|
40
35
|
declare interface ChromaQueryVectorParams extends QueryVectorParams {
|
|
41
36
|
documentFilter?: VectorFilter;
|
|
42
37
|
}
|
|
43
38
|
|
|
44
|
-
declare type ChromaUpsertArgs = [...UpsertVectorArgs, string[]?];
|
|
45
|
-
|
|
46
39
|
declare interface ChromaUpsertVectorParams extends UpsertVectorParams {
|
|
47
40
|
documents?: string[];
|
|
48
41
|
}
|
|
@@ -59,24 +52,21 @@ declare class ChromaVector extends MastraVector {
|
|
|
59
52
|
});
|
|
60
53
|
getCollection(indexName: string, throwIfNotExists?: boolean): Promise<any>;
|
|
61
54
|
private validateVectorDimensions;
|
|
62
|
-
upsert(
|
|
55
|
+
upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]>;
|
|
63
56
|
private HnswSpaceMap;
|
|
64
|
-
createIndex(
|
|
57
|
+
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
65
58
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
66
|
-
query(
|
|
59
|
+
query({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: ChromaQueryVectorParams): Promise<QueryResult[]>;
|
|
67
60
|
listIndexes(): Promise<string[]>;
|
|
68
61
|
/**
|
|
69
62
|
* Retrieves statistics about a vector index.
|
|
70
63
|
*
|
|
71
|
-
* @param
|
|
72
|
-
* @param params.indexName - The name of the index to describe
|
|
64
|
+
* @param {string} indexName - The name of the index to describe
|
|
73
65
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
74
66
|
*/
|
|
75
|
-
describeIndex(
|
|
76
|
-
deleteIndex(
|
|
67
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
68
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
77
69
|
/**
|
|
78
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
79
|
-
*
|
|
80
70
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
81
71
|
* @param indexName - The name of the index containing the vector.
|
|
82
72
|
* @param id - The ID of the vector to update.
|
|
@@ -86,31 +76,7 @@ declare class ChromaVector extends MastraVector {
|
|
|
86
76
|
* @returns A promise that resolves when the update is complete.
|
|
87
77
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
88
78
|
*/
|
|
89
|
-
|
|
90
|
-
vector?: number[];
|
|
91
|
-
metadata?: Record<string, any>;
|
|
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
|
-
*/
|
|
113
|
-
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
79
|
+
updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
|
|
114
80
|
/**
|
|
115
81
|
* Deletes a vector by its ID.
|
|
116
82
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -118,7 +84,7 @@ declare class ChromaVector extends MastraVector {
|
|
|
118
84
|
* @returns A promise that resolves when the deletion is complete.
|
|
119
85
|
* @throws Will throw an error if the deletion operation fails.
|
|
120
86
|
*/
|
|
121
|
-
deleteVector(
|
|
87
|
+
deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
|
|
122
88
|
}
|
|
123
89
|
export { ChromaVector }
|
|
124
90
|
export { ChromaVector as ChromaVector_alias_1 }
|
package/dist/index.cjs
CHANGED
|
@@ -124,9 +124,7 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
async upsert(
|
|
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
129
|
const stats = await this.describeIndex({ indexName });
|
|
132
130
|
this.validateVectorDimensions(vectors, stats.dimension);
|
|
@@ -147,9 +145,7 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
147
145
|
l2: "euclidean",
|
|
148
146
|
ip: "dotproduct"
|
|
149
147
|
};
|
|
150
|
-
async createIndex(
|
|
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(
|
|
182
|
-
|
|
183
|
-
|
|
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);
|
|
@@ -206,13 +207,10 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
206
207
|
/**
|
|
207
208
|
* Retrieves statistics about a vector index.
|
|
208
209
|
*
|
|
209
|
-
* @param
|
|
210
|
-
* @param params.indexName - The name of the index to describe
|
|
210
|
+
* @param {string} indexName - The name of the index to describe
|
|
211
211
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
212
212
|
*/
|
|
213
|
-
async describeIndex(
|
|
214
|
-
const params = this.normalizeArgs("describeIndex", args);
|
|
215
|
-
const { indexName } = params;
|
|
213
|
+
async describeIndex({ indexName }) {
|
|
216
214
|
const collection = await this.getCollection(indexName);
|
|
217
215
|
const count = await collection.count();
|
|
218
216
|
const metadata = collection.metadata;
|
|
@@ -223,32 +221,10 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
223
221
|
metric: this.HnswSpaceMap[hnswSpace]
|
|
224
222
|
};
|
|
225
223
|
}
|
|
226
|
-
async deleteIndex(
|
|
227
|
-
const params = this.normalizeArgs("deleteIndex", args);
|
|
228
|
-
const { indexName } = params;
|
|
224
|
+
async deleteIndex({ indexName }) {
|
|
229
225
|
await this.client.deleteCollection({ name: indexName });
|
|
230
226
|
this.collections.delete(indexName);
|
|
231
227
|
}
|
|
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
|
-
*/
|
|
244
|
-
async updateIndexById(indexName, id, update) {
|
|
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
228
|
/**
|
|
253
229
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
254
230
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -259,9 +235,7 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
259
235
|
* @returns A promise that resolves when the update is complete.
|
|
260
236
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
261
237
|
*/
|
|
262
|
-
async updateVector(
|
|
263
|
-
const params = this.normalizeArgs("updateVector", args);
|
|
264
|
-
const { indexName, id, update } = params;
|
|
238
|
+
async updateVector({ indexName, id, update }) {
|
|
265
239
|
try {
|
|
266
240
|
if (!update.vector && !update.metadata) {
|
|
267
241
|
throw new Error("No updates provided");
|
|
@@ -281,21 +255,6 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
281
255
|
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
282
256
|
}
|
|
283
257
|
}
|
|
284
|
-
/**
|
|
285
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
286
|
-
*
|
|
287
|
-
* Deletes a vector by its ID.
|
|
288
|
-
* @param indexName - The name of the index containing the vector.
|
|
289
|
-
* @param id - The ID of the vector to delete.
|
|
290
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
291
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
292
|
-
*/
|
|
293
|
-
async deleteIndexById(indexName, id) {
|
|
294
|
-
this.logger.warn(
|
|
295
|
-
`Deprecation Warning: deleteIndexById() is deprecated. Please use deleteVector() instead. deleteIndexById() will be removed on May 20th.`
|
|
296
|
-
);
|
|
297
|
-
await this.deleteVector(indexName, id);
|
|
298
|
-
}
|
|
299
258
|
/**
|
|
300
259
|
* Deletes a vector by its ID.
|
|
301
260
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -303,9 +262,7 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
303
262
|
* @returns A promise that resolves when the deletion is complete.
|
|
304
263
|
* @throws Will throw an error if the deletion operation fails.
|
|
305
264
|
*/
|
|
306
|
-
async deleteVector(
|
|
307
|
-
const params = this.normalizeArgs("deleteVector", args);
|
|
308
|
-
const { indexName, id } = params;
|
|
265
|
+
async deleteVector({ indexName, id }) {
|
|
309
266
|
try {
|
|
310
267
|
const collection = await this.getCollection(indexName, true);
|
|
311
268
|
await collection.delete({ ids: [id] });
|
package/dist/index.js
CHANGED
|
@@ -122,9 +122,7 @@ var ChromaVector = class extends MastraVector {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
async upsert(
|
|
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
127
|
const stats = await this.describeIndex({ indexName });
|
|
130
128
|
this.validateVectorDimensions(vectors, stats.dimension);
|
|
@@ -145,9 +143,7 @@ var ChromaVector = class extends MastraVector {
|
|
|
145
143
|
l2: "euclidean",
|
|
146
144
|
ip: "dotproduct"
|
|
147
145
|
};
|
|
148
|
-
async createIndex(
|
|
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(
|
|
180
|
-
|
|
181
|
-
|
|
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);
|
|
@@ -204,13 +205,10 @@ var ChromaVector = class extends MastraVector {
|
|
|
204
205
|
/**
|
|
205
206
|
* Retrieves statistics about a vector index.
|
|
206
207
|
*
|
|
207
|
-
* @param
|
|
208
|
-
* @param params.indexName - The name of the index to describe
|
|
208
|
+
* @param {string} indexName - The name of the index to describe
|
|
209
209
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
210
210
|
*/
|
|
211
|
-
async describeIndex(
|
|
212
|
-
const params = this.normalizeArgs("describeIndex", args);
|
|
213
|
-
const { indexName } = params;
|
|
211
|
+
async describeIndex({ indexName }) {
|
|
214
212
|
const collection = await this.getCollection(indexName);
|
|
215
213
|
const count = await collection.count();
|
|
216
214
|
const metadata = collection.metadata;
|
|
@@ -221,32 +219,10 @@ var ChromaVector = class extends MastraVector {
|
|
|
221
219
|
metric: this.HnswSpaceMap[hnswSpace]
|
|
222
220
|
};
|
|
223
221
|
}
|
|
224
|
-
async deleteIndex(
|
|
225
|
-
const params = this.normalizeArgs("deleteIndex", args);
|
|
226
|
-
const { indexName } = params;
|
|
222
|
+
async deleteIndex({ indexName }) {
|
|
227
223
|
await this.client.deleteCollection({ name: indexName });
|
|
228
224
|
this.collections.delete(indexName);
|
|
229
225
|
}
|
|
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
|
-
*/
|
|
242
|
-
async updateIndexById(indexName, id, update) {
|
|
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
226
|
/**
|
|
251
227
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
252
228
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -257,9 +233,7 @@ var ChromaVector = class extends MastraVector {
|
|
|
257
233
|
* @returns A promise that resolves when the update is complete.
|
|
258
234
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
259
235
|
*/
|
|
260
|
-
async updateVector(
|
|
261
|
-
const params = this.normalizeArgs("updateVector", args);
|
|
262
|
-
const { indexName, id, update } = params;
|
|
236
|
+
async updateVector({ indexName, id, update }) {
|
|
263
237
|
try {
|
|
264
238
|
if (!update.vector && !update.metadata) {
|
|
265
239
|
throw new Error("No updates provided");
|
|
@@ -279,21 +253,6 @@ var ChromaVector = class extends MastraVector {
|
|
|
279
253
|
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
280
254
|
}
|
|
281
255
|
}
|
|
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
|
-
*/
|
|
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
256
|
/**
|
|
298
257
|
* Deletes a vector by its ID.
|
|
299
258
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -301,9 +260,7 @@ var ChromaVector = class extends MastraVector {
|
|
|
301
260
|
* @returns A promise that resolves when the deletion is complete.
|
|
302
261
|
* @throws Will throw an error if the deletion operation fails.
|
|
303
262
|
*/
|
|
304
|
-
async deleteVector(
|
|
305
|
-
const params = this.normalizeArgs("deleteVector", args);
|
|
306
|
-
const { indexName, id } = params;
|
|
263
|
+
async deleteVector({ indexName, id }) {
|
|
307
264
|
try {
|
|
308
265
|
const collection = await this.getCollection(indexName, true);
|
|
309
266
|
await collection.delete({ ids: [id] });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/chroma",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
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.9.5-alpha.0"
|
|
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.
|
|
32
|
+
"@internal/lint": "0.0.6",
|
|
33
|
+
"@mastra/core": "0.10.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@mastra/core": "^0.10.0"
|
|
34
37
|
},
|
|
35
38
|
"scripts": {
|
|
36
39
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -1462,115 +1462,6 @@ describe('ChromaVector Integration Tests', () => {
|
|
|
1462
1462
|
});
|
|
1463
1463
|
});
|
|
1464
1464
|
});
|
|
1465
|
-
describe('Deprecation Warnings', () => {
|
|
1466
|
-
const indexName = 'testdeprecationwarnings';
|
|
1467
|
-
|
|
1468
|
-
const indexName2 = 'testdeprecationwarnings2';
|
|
1469
|
-
|
|
1470
|
-
let warnSpy;
|
|
1471
|
-
|
|
1472
|
-
beforeAll(async () => {
|
|
1473
|
-
await vectorDB.createIndex({ indexName, dimension: 3 });
|
|
1474
|
-
});
|
|
1475
|
-
|
|
1476
|
-
afterAll(async () => {
|
|
1477
|
-
try {
|
|
1478
|
-
await vectorDB.deleteIndex({ indexName });
|
|
1479
|
-
} catch {
|
|
1480
|
-
// Ignore errors if index doesn't exist
|
|
1481
|
-
}
|
|
1482
|
-
try {
|
|
1483
|
-
await vectorDB.deleteIndex({ indexName: indexName2 });
|
|
1484
|
-
} catch {
|
|
1485
|
-
// Ignore errors if index doesn't exist
|
|
1486
|
-
}
|
|
1487
|
-
});
|
|
1488
|
-
|
|
1489
|
-
beforeEach(async () => {
|
|
1490
|
-
warnSpy = vi.spyOn(vectorDB['logger'], 'warn');
|
|
1491
|
-
});
|
|
1492
|
-
|
|
1493
|
-
afterEach(async () => {
|
|
1494
|
-
warnSpy.mockRestore();
|
|
1495
|
-
try {
|
|
1496
|
-
await vectorDB.deleteIndex({ indexName: indexName2 });
|
|
1497
|
-
} catch {
|
|
1498
|
-
// Ignore errors if index doesn't exist
|
|
1499
|
-
}
|
|
1500
|
-
});
|
|
1501
|
-
|
|
1502
|
-
it('should show deprecation warning when using individual args for createIndex', async () => {
|
|
1503
|
-
await vectorDB.createIndex(indexName2, 3, 'cosine');
|
|
1504
|
-
|
|
1505
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1506
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to createIndex() is deprecated'),
|
|
1507
|
-
);
|
|
1508
|
-
});
|
|
1509
|
-
|
|
1510
|
-
it('should show deprecation warning when using individual args for upsert', async () => {
|
|
1511
|
-
await vectorDB.upsert(indexName, [[1, 2, 3]], [{ test: 'data' }]);
|
|
1512
|
-
|
|
1513
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1514
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to upsert() is deprecated'),
|
|
1515
|
-
);
|
|
1516
|
-
});
|
|
1517
|
-
|
|
1518
|
-
it('should show deprecation warning when using individual args for query', async () => {
|
|
1519
|
-
await vectorDB.query(indexName, [1, 2, 3], 5);
|
|
1520
|
-
|
|
1521
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1522
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to query() is deprecated'),
|
|
1523
|
-
);
|
|
1524
|
-
});
|
|
1525
|
-
|
|
1526
|
-
it('should not show deprecation warning when using object param for query', async () => {
|
|
1527
|
-
await vectorDB.query({
|
|
1528
|
-
indexName,
|
|
1529
|
-
queryVector: [1, 2, 3],
|
|
1530
|
-
topK: 5,
|
|
1531
|
-
});
|
|
1532
|
-
|
|
1533
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1534
|
-
});
|
|
1535
|
-
|
|
1536
|
-
it('should not show deprecation warning when using object param for createIndex', async () => {
|
|
1537
|
-
await vectorDB.createIndex({
|
|
1538
|
-
indexName: indexName2,
|
|
1539
|
-
dimension: 3,
|
|
1540
|
-
metric: 'cosine',
|
|
1541
|
-
});
|
|
1542
|
-
|
|
1543
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1544
|
-
});
|
|
1545
|
-
|
|
1546
|
-
it('should not show deprecation warning when using object param for upsert', async () => {
|
|
1547
|
-
await vectorDB.upsert({
|
|
1548
|
-
indexName,
|
|
1549
|
-
vectors: [[1, 2, 3]],
|
|
1550
|
-
metadata: [{ test: 'data' }],
|
|
1551
|
-
});
|
|
1552
|
-
|
|
1553
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1554
|
-
});
|
|
1555
|
-
|
|
1556
|
-
it('should maintain backward compatibility with individual args', async () => {
|
|
1557
|
-
// Query
|
|
1558
|
-
const queryResults = await vectorDB.query(indexName, [1, 2, 3], 5);
|
|
1559
|
-
expect(Array.isArray(queryResults)).toBe(true);
|
|
1560
|
-
|
|
1561
|
-
// CreateIndex
|
|
1562
|
-
await expect(vectorDB.createIndex(indexName2, 3, 'cosine')).resolves.not.toThrow();
|
|
1563
|
-
|
|
1564
|
-
// Upsert
|
|
1565
|
-
const upsertResults = await vectorDB.upsert({
|
|
1566
|
-
indexName,
|
|
1567
|
-
vectors: [[1, 2, 3]],
|
|
1568
|
-
metadata: [{ test: 'data' }],
|
|
1569
|
-
});
|
|
1570
|
-
expect(Array.isArray(upsertResults)).toBe(true);
|
|
1571
|
-
expect(upsertResults).toHaveLength(1);
|
|
1572
|
-
});
|
|
1573
|
-
});
|
|
1574
1465
|
|
|
1575
1466
|
describe('Performance and Concurrency', () => {
|
|
1576
1467
|
const perfTestIndex = 'perf-test-index';
|
package/src/vector/index.ts
CHANGED
|
@@ -5,9 +5,6 @@ import type {
|
|
|
5
5
|
CreateIndexParams,
|
|
6
6
|
UpsertVectorParams,
|
|
7
7
|
QueryVectorParams,
|
|
8
|
-
ParamsToArgs,
|
|
9
|
-
QueryVectorArgs,
|
|
10
|
-
UpsertVectorArgs,
|
|
11
8
|
DescribeIndexParams,
|
|
12
9
|
DeleteIndexParams,
|
|
13
10
|
DeleteVectorParams,
|
|
@@ -23,14 +20,10 @@ interface ChromaUpsertVectorParams extends UpsertVectorParams {
|
|
|
23
20
|
documents?: string[];
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
type ChromaUpsertArgs = [...UpsertVectorArgs, string[]?];
|
|
27
|
-
|
|
28
23
|
interface ChromaQueryVectorParams extends QueryVectorParams {
|
|
29
24
|
documentFilter?: VectorFilter;
|
|
30
25
|
}
|
|
31
26
|
|
|
32
|
-
type ChromaQueryArgs = [...QueryVectorArgs, VectorFilter?];
|
|
33
|
-
|
|
34
27
|
export class ChromaVector extends MastraVector {
|
|
35
28
|
private client: ChromaClient;
|
|
36
29
|
private collections: Map<string, any>;
|
|
@@ -76,11 +69,7 @@ export class ChromaVector extends MastraVector {
|
|
|
76
69
|
}
|
|
77
70
|
}
|
|
78
71
|
|
|
79
|
-
async upsert(
|
|
80
|
-
const params = this.normalizeArgs<ChromaUpsertVectorParams, ChromaUpsertArgs>('upsert', args, ['documents']);
|
|
81
|
-
|
|
82
|
-
const { indexName, vectors, metadata, ids, documents } = params;
|
|
83
|
-
|
|
72
|
+
async upsert({ indexName, vectors, metadata, ids, documents }: ChromaUpsertVectorParams): Promise<string[]> {
|
|
84
73
|
const collection = await this.getCollection(indexName);
|
|
85
74
|
|
|
86
75
|
// Get index stats to check dimension
|
|
@@ -113,10 +102,7 @@ export class ChromaVector extends MastraVector {
|
|
|
113
102
|
ip: 'dotproduct',
|
|
114
103
|
};
|
|
115
104
|
|
|
116
|
-
async createIndex(
|
|
117
|
-
const params = this.normalizeArgs<CreateIndexParams>('createIndex', args);
|
|
118
|
-
const { indexName, dimension, metric = 'cosine' } = params;
|
|
119
|
-
|
|
105
|
+
async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {
|
|
120
106
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
121
107
|
throw new Error('Dimension must be a positive integer');
|
|
122
108
|
}
|
|
@@ -148,11 +134,14 @@ export class ChromaVector extends MastraVector {
|
|
|
148
134
|
const translator = new ChromaFilterTranslator();
|
|
149
135
|
return translator.translate(filter);
|
|
150
136
|
}
|
|
151
|
-
async query(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
137
|
+
async query({
|
|
138
|
+
indexName,
|
|
139
|
+
queryVector,
|
|
140
|
+
topK = 10,
|
|
141
|
+
filter,
|
|
142
|
+
includeVector = false,
|
|
143
|
+
documentFilter,
|
|
144
|
+
}: ChromaQueryVectorParams): Promise<QueryResult[]> {
|
|
156
145
|
const collection = await this.getCollection(indexName, true);
|
|
157
146
|
|
|
158
147
|
const defaultInclude = ['documents', 'metadatas', 'distances'];
|
|
@@ -184,14 +173,10 @@ export class ChromaVector extends MastraVector {
|
|
|
184
173
|
/**
|
|
185
174
|
* Retrieves statistics about a vector index.
|
|
186
175
|
*
|
|
187
|
-
* @param
|
|
188
|
-
* @param params.indexName - The name of the index to describe
|
|
176
|
+
* @param {string} indexName - The name of the index to describe
|
|
189
177
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
190
178
|
*/
|
|
191
|
-
async describeIndex(
|
|
192
|
-
const params = this.normalizeArgs<DescribeIndexParams>('describeIndex', args);
|
|
193
|
-
const { indexName } = params;
|
|
194
|
-
|
|
179
|
+
async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {
|
|
195
180
|
const collection = await this.getCollection(indexName);
|
|
196
181
|
const count = await collection.count();
|
|
197
182
|
const metadata = collection.metadata;
|
|
@@ -205,38 +190,11 @@ export class ChromaVector extends MastraVector {
|
|
|
205
190
|
};
|
|
206
191
|
}
|
|
207
192
|
|
|
208
|
-
async deleteIndex(
|
|
209
|
-
const params = this.normalizeArgs<DeleteIndexParams>('deleteIndex', args);
|
|
210
|
-
const { indexName } = params;
|
|
193
|
+
async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {
|
|
211
194
|
await this.client.deleteCollection({ name: indexName });
|
|
212
195
|
this.collections.delete(indexName);
|
|
213
196
|
}
|
|
214
197
|
|
|
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
|
-
*/
|
|
227
|
-
async updateIndexById(
|
|
228
|
-
indexName: string,
|
|
229
|
-
id: string,
|
|
230
|
-
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
231
|
-
): Promise<void> {
|
|
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
|
-
}
|
|
239
|
-
|
|
240
198
|
/**
|
|
241
199
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
242
200
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -247,9 +205,7 @@ export class ChromaVector extends MastraVector {
|
|
|
247
205
|
* @returns A promise that resolves when the update is complete.
|
|
248
206
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
249
207
|
*/
|
|
250
|
-
async updateVector(
|
|
251
|
-
const params = this.normalizeArgs<UpdateVectorParams>('updateVector', args);
|
|
252
|
-
const { indexName, id, update } = params;
|
|
208
|
+
async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {
|
|
253
209
|
try {
|
|
254
210
|
if (!update.vector && !update.metadata) {
|
|
255
211
|
throw new Error('No updates provided');
|
|
@@ -275,22 +231,6 @@ export class ChromaVector extends MastraVector {
|
|
|
275
231
|
}
|
|
276
232
|
}
|
|
277
233
|
|
|
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
|
-
*/
|
|
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
234
|
/**
|
|
295
235
|
* Deletes a vector by its ID.
|
|
296
236
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -298,10 +238,7 @@ export class ChromaVector extends MastraVector {
|
|
|
298
238
|
* @returns A promise that resolves when the deletion is complete.
|
|
299
239
|
* @throws Will throw an error if the deletion operation fails.
|
|
300
240
|
*/
|
|
301
|
-
async deleteVector(
|
|
302
|
-
const params = this.normalizeArgs<DeleteVectorParams>('deleteVector', args);
|
|
303
|
-
|
|
304
|
-
const { indexName, id } = params;
|
|
241
|
+
async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {
|
|
305
242
|
try {
|
|
306
243
|
const collection: Collection = await this.getCollection(indexName, true);
|
|
307
244
|
await collection.delete({ ids: [id] });
|