@mastra/astra 0.2.15-alpha.2 → 0.2.15-alpha.4
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 +18 -0
- package/dist/_tsup-dts-rollup.d.cts +43 -0
- package/dist/_tsup-dts-rollup.d.ts +43 -0
- package/dist/index.cjs +68 -12
- package/dist/index.js +68 -12
- package/package.json +2 -2
- package/src/vector/index.test.ts +5 -5
- package/src/vector/index.ts +75 -13
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/astra@0.2.15-alpha.
|
|
2
|
+
> @mastra/astra@0.2.15-alpha.4 build /home/runner/work/mastra/mastra/stores/astra
|
|
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 6098ms
|
|
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/astra/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/astra/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 7222ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m13.23 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 319ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m13.28 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 396ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/astra
|
|
2
2
|
|
|
3
|
+
## 0.2.15-alpha.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [3e9c131]
|
|
8
|
+
- @mastra/core@0.9.4-alpha.4
|
|
9
|
+
|
|
10
|
+
## 0.2.15-alpha.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
|
|
15
|
+
- Updated dependencies [396be50]
|
|
16
|
+
- Updated dependencies [c3bd795]
|
|
17
|
+
- Updated dependencies [da082f8]
|
|
18
|
+
- Updated dependencies [a5810ce]
|
|
19
|
+
- @mastra/core@0.9.4-alpha.3
|
|
20
|
+
|
|
3
21
|
## 0.2.15-alpha.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -85,11 +85,54 @@ declare class AstraVector extends MastraVector {
|
|
|
85
85
|
* @returns {Promise<void>} A promise that resolves when the collection is deleted.
|
|
86
86
|
*/
|
|
87
87
|
deleteIndex(indexName: string): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
90
|
+
*
|
|
91
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
92
|
+
* @param indexName - The name of the index containing the vector.
|
|
93
|
+
* @param id - The ID of the vector to update.
|
|
94
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
95
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
96
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
97
|
+
* @returns A promise that resolves when the update is complete.
|
|
98
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
99
|
+
*/
|
|
88
100
|
updateIndexById(indexName: string, id: string, update: {
|
|
89
101
|
vector?: number[];
|
|
90
102
|
metadata?: Record<string, any>;
|
|
91
103
|
}): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
106
|
+
* @param indexName - The name of the index containing the vector.
|
|
107
|
+
* @param id - The ID of the vector to update.
|
|
108
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
109
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
110
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
111
|
+
* @returns A promise that resolves when the update is complete.
|
|
112
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
113
|
+
*/
|
|
114
|
+
updateVector(indexName: string, id: string, update: {
|
|
115
|
+
vector?: number[];
|
|
116
|
+
metadata?: Record<string, any>;
|
|
117
|
+
}): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
120
|
+
*
|
|
121
|
+
* Deletes a vector by its ID.
|
|
122
|
+
* @param indexName - The name of the index containing the vector.
|
|
123
|
+
* @param id - The ID of the vector to delete.
|
|
124
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
125
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
126
|
+
*/
|
|
92
127
|
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Deletes a vector by its ID.
|
|
130
|
+
* @param indexName - The name of the index containing the vector.
|
|
131
|
+
* @param id - The ID of the vector to delete.
|
|
132
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
133
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
134
|
+
*/
|
|
135
|
+
deleteVector(indexName: string, id: string): Promise<void>;
|
|
93
136
|
}
|
|
94
137
|
export { AstraVector }
|
|
95
138
|
export { AstraVector as AstraVector_alias_1 }
|
|
@@ -85,11 +85,54 @@ declare class AstraVector extends MastraVector {
|
|
|
85
85
|
* @returns {Promise<void>} A promise that resolves when the collection is deleted.
|
|
86
86
|
*/
|
|
87
87
|
deleteIndex(indexName: string): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
90
|
+
*
|
|
91
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
92
|
+
* @param indexName - The name of the index containing the vector.
|
|
93
|
+
* @param id - The ID of the vector to update.
|
|
94
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
95
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
96
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
97
|
+
* @returns A promise that resolves when the update is complete.
|
|
98
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
99
|
+
*/
|
|
88
100
|
updateIndexById(indexName: string, id: string, update: {
|
|
89
101
|
vector?: number[];
|
|
90
102
|
metadata?: Record<string, any>;
|
|
91
103
|
}): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
106
|
+
* @param indexName - The name of the index containing the vector.
|
|
107
|
+
* @param id - The ID of the vector to update.
|
|
108
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
109
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
110
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
111
|
+
* @returns A promise that resolves when the update is complete.
|
|
112
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
113
|
+
*/
|
|
114
|
+
updateVector(indexName: string, id: string, update: {
|
|
115
|
+
vector?: number[];
|
|
116
|
+
metadata?: Record<string, any>;
|
|
117
|
+
}): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
120
|
+
*
|
|
121
|
+
* Deletes a vector by its ID.
|
|
122
|
+
* @param indexName - The name of the index containing the vector.
|
|
123
|
+
* @param id - The ID of the vector to delete.
|
|
124
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
125
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
126
|
+
*/
|
|
92
127
|
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Deletes a vector by its ID.
|
|
130
|
+
* @param indexName - The name of the index containing the vector.
|
|
131
|
+
* @param id - The ID of the vector to delete.
|
|
132
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
133
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
134
|
+
*/
|
|
135
|
+
deleteVector(indexName: string, id: string): Promise<void>;
|
|
93
136
|
}
|
|
94
137
|
export { AstraVector }
|
|
95
138
|
export { AstraVector as AstraVector_alias_1 }
|
package/dist/index.cjs
CHANGED
|
@@ -171,26 +171,82 @@ var AstraVector = class extends vector.MastraVector {
|
|
|
171
171
|
const collection = this.#db.collection(indexName);
|
|
172
172
|
await collection.drop();
|
|
173
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
176
|
+
*
|
|
177
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
178
|
+
* @param indexName - The name of the index containing the vector.
|
|
179
|
+
* @param id - The ID of the vector to update.
|
|
180
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
181
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
182
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
183
|
+
* @returns A promise that resolves when the update is complete.
|
|
184
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
185
|
+
*/
|
|
174
186
|
async updateIndexById(indexName, id, update) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
187
|
+
this.logger.warn(
|
|
188
|
+
`Deprecation Warning: updateIndexById() is deprecated. Please use updateVector() instead. updateIndexById() will be removed on May 20th, 2025.`
|
|
189
|
+
);
|
|
190
|
+
await this.updateVector(indexName, id, update);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
194
|
+
* @param indexName - The name of the index containing the vector.
|
|
195
|
+
* @param id - The ID of the vector to update.
|
|
196
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
197
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
198
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
199
|
+
* @returns A promise that resolves when the update is complete.
|
|
200
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
201
|
+
*/
|
|
202
|
+
async updateVector(indexName, id, update) {
|
|
203
|
+
try {
|
|
204
|
+
if (!update.vector && !update.metadata) {
|
|
205
|
+
throw new Error("No updates provided");
|
|
206
|
+
}
|
|
207
|
+
const collection = this.#db.collection(indexName);
|
|
208
|
+
const updateDoc = {};
|
|
209
|
+
if (update.vector) {
|
|
210
|
+
updateDoc.$vector = update.vector;
|
|
211
|
+
}
|
|
212
|
+
if (update.metadata) {
|
|
213
|
+
updateDoc.metadata = update.metadata;
|
|
214
|
+
}
|
|
215
|
+
await collection.findOneAndUpdate({ id }, { $set: updateDoc });
|
|
216
|
+
} catch (error) {
|
|
217
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
185
218
|
}
|
|
186
|
-
await collection.findOneAndUpdate({ id }, { $set: updateDoc });
|
|
187
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
222
|
+
*
|
|
223
|
+
* Deletes a vector by its ID.
|
|
224
|
+
* @param indexName - The name of the index containing the vector.
|
|
225
|
+
* @param id - The ID of the vector to delete.
|
|
226
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
227
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
228
|
+
*/
|
|
188
229
|
async deleteIndexById(indexName, id) {
|
|
230
|
+
this.logger.warn(
|
|
231
|
+
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
232
|
+
Please use deleteVector() instead.
|
|
233
|
+
deleteIndexById() will be removed on May 20th, 2025.`
|
|
234
|
+
);
|
|
235
|
+
await this.deleteVector(indexName, id);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Deletes a vector by its ID.
|
|
239
|
+
* @param indexName - The name of the index containing the vector.
|
|
240
|
+
* @param id - The ID of the vector to delete.
|
|
241
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
242
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
243
|
+
*/
|
|
244
|
+
async deleteVector(indexName, id) {
|
|
189
245
|
try {
|
|
190
246
|
const collection = this.#db.collection(indexName);
|
|
191
247
|
await collection.deleteOne({ id });
|
|
192
248
|
} catch (error) {
|
|
193
|
-
throw new Error(`Failed to delete
|
|
249
|
+
throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
194
250
|
}
|
|
195
251
|
}
|
|
196
252
|
};
|
package/dist/index.js
CHANGED
|
@@ -169,26 +169,82 @@ var AstraVector = class extends MastraVector {
|
|
|
169
169
|
const collection = this.#db.collection(indexName);
|
|
170
170
|
await collection.drop();
|
|
171
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
174
|
+
*
|
|
175
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
176
|
+
* @param indexName - The name of the index containing the vector.
|
|
177
|
+
* @param id - The ID of the vector to update.
|
|
178
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
179
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
180
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
181
|
+
* @returns A promise that resolves when the update is complete.
|
|
182
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
183
|
+
*/
|
|
172
184
|
async updateIndexById(indexName, id, update) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
185
|
+
this.logger.warn(
|
|
186
|
+
`Deprecation Warning: updateIndexById() is deprecated. Please use updateVector() instead. updateIndexById() will be removed on May 20th, 2025.`
|
|
187
|
+
);
|
|
188
|
+
await this.updateVector(indexName, id, update);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
192
|
+
* @param indexName - The name of the index containing the vector.
|
|
193
|
+
* @param id - The ID of the vector to update.
|
|
194
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
195
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
196
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
197
|
+
* @returns A promise that resolves when the update is complete.
|
|
198
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
199
|
+
*/
|
|
200
|
+
async updateVector(indexName, id, update) {
|
|
201
|
+
try {
|
|
202
|
+
if (!update.vector && !update.metadata) {
|
|
203
|
+
throw new Error("No updates provided");
|
|
204
|
+
}
|
|
205
|
+
const collection = this.#db.collection(indexName);
|
|
206
|
+
const updateDoc = {};
|
|
207
|
+
if (update.vector) {
|
|
208
|
+
updateDoc.$vector = update.vector;
|
|
209
|
+
}
|
|
210
|
+
if (update.metadata) {
|
|
211
|
+
updateDoc.metadata = update.metadata;
|
|
212
|
+
}
|
|
213
|
+
await collection.findOneAndUpdate({ id }, { $set: updateDoc });
|
|
214
|
+
} catch (error) {
|
|
215
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
183
216
|
}
|
|
184
|
-
await collection.findOneAndUpdate({ id }, { $set: updateDoc });
|
|
185
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
220
|
+
*
|
|
221
|
+
* Deletes a vector by its ID.
|
|
222
|
+
* @param indexName - The name of the index containing the vector.
|
|
223
|
+
* @param id - The ID of the vector to delete.
|
|
224
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
225
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
226
|
+
*/
|
|
186
227
|
async deleteIndexById(indexName, id) {
|
|
228
|
+
this.logger.warn(
|
|
229
|
+
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
230
|
+
Please use deleteVector() instead.
|
|
231
|
+
deleteIndexById() will be removed on May 20th, 2025.`
|
|
232
|
+
);
|
|
233
|
+
await this.deleteVector(indexName, id);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Deletes a vector by its ID.
|
|
237
|
+
* @param indexName - The name of the index containing the vector.
|
|
238
|
+
* @param id - The ID of the vector to delete.
|
|
239
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
240
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
241
|
+
*/
|
|
242
|
+
async deleteVector(indexName, id) {
|
|
187
243
|
try {
|
|
188
244
|
const collection = this.#db.collection(indexName);
|
|
189
245
|
await collection.deleteOne({ id });
|
|
190
246
|
} catch (error) {
|
|
191
|
-
throw new Error(`Failed to delete
|
|
247
|
+
throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
192
248
|
}
|
|
193
249
|
}
|
|
194
250
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/astra",
|
|
3
|
-
"version": "0.2.15-alpha.
|
|
3
|
+
"version": "0.2.15-alpha.4",
|
|
4
4
|
"description": "Astra DB provider for Mastra - includes vector store capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@datastax/astra-db-ts": "^1.5.0",
|
|
24
|
-
"@mastra/core": "^0.9.4-alpha.
|
|
24
|
+
"@mastra/core": "^0.9.4-alpha.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@microsoft/api-extractor": "^7.52.5",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -1224,7 +1224,7 @@ describe.skip('AstraVector Integration Tests', () => {
|
|
|
1224
1224
|
metadata: newMetaData,
|
|
1225
1225
|
};
|
|
1226
1226
|
|
|
1227
|
-
await vectorDB.
|
|
1227
|
+
await vectorDB.updateVector(indexName, idToBeUpdated, update);
|
|
1228
1228
|
|
|
1229
1229
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
1230
1230
|
|
|
@@ -1256,7 +1256,7 @@ describe.skip('AstraVector Integration Tests', () => {
|
|
|
1256
1256
|
metadata: newMetaData,
|
|
1257
1257
|
};
|
|
1258
1258
|
|
|
1259
|
-
await vectorDB.
|
|
1259
|
+
await vectorDB.updateVector(indexName, idToBeUpdated, update);
|
|
1260
1260
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
1261
1261
|
|
|
1262
1262
|
const results = await vectorDB.query({
|
|
@@ -1285,7 +1285,7 @@ describe.skip('AstraVector Integration Tests', () => {
|
|
|
1285
1285
|
vector: newVector,
|
|
1286
1286
|
};
|
|
1287
1287
|
|
|
1288
|
-
await vectorDB.
|
|
1288
|
+
await vectorDB.updateVector(indexName, idToBeUpdated, update);
|
|
1289
1289
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
1290
1290
|
|
|
1291
1291
|
const results = await vectorDB.query({
|
|
@@ -1303,7 +1303,7 @@ describe.skip('AstraVector Integration Tests', () => {
|
|
|
1303
1303
|
});
|
|
1304
1304
|
|
|
1305
1305
|
it('should throw exception when no updates are given', async () => {
|
|
1306
|
-
await expect(vectorDB.
|
|
1306
|
+
await expect(vectorDB.updateVector(indexName, 'id', {})).rejects.toThrow('No updates provided');
|
|
1307
1307
|
});
|
|
1308
1308
|
|
|
1309
1309
|
it('should delete the vector by id', async () => {
|
|
@@ -1311,7 +1311,7 @@ describe.skip('AstraVector Integration Tests', () => {
|
|
|
1311
1311
|
expect(ids).toHaveLength(4);
|
|
1312
1312
|
|
|
1313
1313
|
const idToBeDeleted = ids[0];
|
|
1314
|
-
await vectorDB.
|
|
1314
|
+
await vectorDB.deleteVector(indexName, idToBeDeleted);
|
|
1315
1315
|
|
|
1316
1316
|
const results = await vectorDB.query({
|
|
1317
1317
|
indexName: indexName,
|
package/src/vector/index.ts
CHANGED
|
@@ -169,35 +169,97 @@ export class AstraVector extends MastraVector {
|
|
|
169
169
|
await collection.drop();
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
/**
|
|
173
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
174
|
+
*
|
|
175
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
176
|
+
* @param indexName - The name of the index containing the vector.
|
|
177
|
+
* @param id - The ID of the vector to update.
|
|
178
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
179
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
180
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
181
|
+
* @returns A promise that resolves when the update is complete.
|
|
182
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
183
|
+
*/
|
|
172
184
|
async updateIndexById(
|
|
173
185
|
indexName: string,
|
|
174
186
|
id: string,
|
|
175
187
|
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
176
188
|
): Promise<void> {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
189
|
+
this.logger.warn(
|
|
190
|
+
`Deprecation Warning: updateIndexById() is deprecated. Please use updateVector() instead. updateIndexById() will be removed on May 20th, 2025.`,
|
|
191
|
+
);
|
|
192
|
+
await this.updateVector(indexName, id, update);
|
|
193
|
+
}
|
|
180
194
|
|
|
181
|
-
|
|
182
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
197
|
+
* @param indexName - The name of the index containing the vector.
|
|
198
|
+
* @param id - The ID of the vector to update.
|
|
199
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
200
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
201
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
202
|
+
* @returns A promise that resolves when the update is complete.
|
|
203
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
204
|
+
*/
|
|
205
|
+
async updateVector(
|
|
206
|
+
indexName: string,
|
|
207
|
+
id: string,
|
|
208
|
+
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
209
|
+
): Promise<void> {
|
|
210
|
+
try {
|
|
211
|
+
if (!update.vector && !update.metadata) {
|
|
212
|
+
throw new Error('No updates provided');
|
|
213
|
+
}
|
|
183
214
|
|
|
184
|
-
|
|
185
|
-
updateDoc
|
|
186
|
-
}
|
|
215
|
+
const collection = this.#db.collection(indexName);
|
|
216
|
+
const updateDoc: Record<string, any> = {};
|
|
187
217
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
218
|
+
if (update.vector) {
|
|
219
|
+
updateDoc.$vector = update.vector;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (update.metadata) {
|
|
223
|
+
updateDoc.metadata = update.metadata;
|
|
224
|
+
}
|
|
191
225
|
|
|
192
|
-
|
|
226
|
+
await collection.findOneAndUpdate({ id }, { $set: updateDoc });
|
|
227
|
+
} catch (error: any) {
|
|
228
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
229
|
+
}
|
|
193
230
|
}
|
|
194
231
|
|
|
232
|
+
/**
|
|
233
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
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
|
+
*/
|
|
195
241
|
async deleteIndexById(indexName: string, id: string): Promise<void> {
|
|
242
|
+
this.logger.warn(
|
|
243
|
+
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
244
|
+
Please use deleteVector() instead.
|
|
245
|
+
deleteIndexById() will be removed on May 20th, 2025.`,
|
|
246
|
+
);
|
|
247
|
+
await this.deleteVector(indexName, id);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Deletes a vector by its ID.
|
|
252
|
+
* @param indexName - The name of the index containing the vector.
|
|
253
|
+
* @param id - The ID of the vector to delete.
|
|
254
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
255
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
256
|
+
*/
|
|
257
|
+
async deleteVector(indexName: string, id: string): Promise<void> {
|
|
196
258
|
try {
|
|
197
259
|
const collection = this.#db.collection(indexName);
|
|
198
260
|
await collection.deleteOne({ id });
|
|
199
261
|
} catch (error: any) {
|
|
200
|
-
throw new Error(`Failed to delete
|
|
262
|
+
throw new Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
201
263
|
}
|
|
202
264
|
}
|
|
203
265
|
}
|