@mastra/astra 0.1.8-alpha.3 → 0.2.0-alpha.10

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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/astra@0.1.8-alpha.3 build /home/runner/work/mastra/mastra/stores/astra
2
+ > @mastra/astra@0.2.0-alpha.10 build /home/runner/work/mastra/mastra/stores/astra
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.3.6
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 6291ms
9
+ TSC ⚡️ Build success in 6671ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.7.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/astra/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.7.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/astra/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 10897ms
16
+ DTS ⚡️ Build success in 9368ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 6.39 KB
21
- ESM ⚡️ Build success in 502ms
22
- CJS dist/index.cjs 6.43 KB
23
- CJS ⚡️ Build success in 503ms
20
+ ESM dist/index.js 7.13 KB
21
+ ESM ⚡️ Build success in 560ms
22
+ CJS dist/index.cjs 7.16 KB
23
+ CJS ⚡️ Build success in 560ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,75 @@
1
1
  # @mastra/astra
2
2
 
3
+ ## 0.2.0-alpha.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a910463]
8
+ - @mastra/core@0.5.0-alpha.10
9
+
10
+ ## 0.2.0-alpha.9
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [e9fbac5]
15
+ - Updated dependencies [1e8bcbc]
16
+ - Updated dependencies [aeb5e36]
17
+ - Updated dependencies [f2301de]
18
+ - @mastra/core@0.5.0-alpha.9
19
+
20
+ ## 0.2.0-alpha.8
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [506f1d5]
25
+ - @mastra/core@0.5.0-alpha.8
26
+
27
+ ## 0.2.0-alpha.7
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies [ee667a2]
32
+ - @mastra/core@0.5.0-alpha.7
33
+
34
+ ## 0.2.0-alpha.6
35
+
36
+ ### Patch Changes
37
+
38
+ - Updated dependencies [f6678e4]
39
+ - @mastra/core@0.5.0-alpha.6
40
+
41
+ ## 0.2.0-alpha.5
42
+
43
+ ### Minor Changes
44
+
45
+ - 5bfb4b6: Added new operations implementations for new MastraVector interface methods in astra store
46
+
47
+ ### Patch Changes
48
+
49
+ - Updated dependencies [22643eb]
50
+ - Updated dependencies [6feb23f]
51
+ - Updated dependencies [f2d6727]
52
+ - Updated dependencies [301e4ee]
53
+ - Updated dependencies [dfbe4e9]
54
+ - Updated dependencies [9e81f35]
55
+ - Updated dependencies [caefaa2]
56
+ - Updated dependencies [c151ae6]
57
+ - Updated dependencies [52e0418]
58
+ - Updated dependencies [03236ec]
59
+ - Updated dependencies [3764e71]
60
+ - Updated dependencies [df982db]
61
+ - Updated dependencies [0461849]
62
+ - Updated dependencies [2259379]
63
+ - Updated dependencies [358f069]
64
+ - @mastra/core@0.5.0-alpha.5
65
+
66
+ ## 0.1.8-alpha.4
67
+
68
+ ### Patch Changes
69
+
70
+ - Updated dependencies [d79aedf]
71
+ - @mastra/core@0.5.0-alpha.4
72
+
3
73
  ## 0.1.8-alpha.3
4
74
 
5
75
  ### Patch Changes
@@ -77,6 +77,11 @@ declare class AstraVector extends MastraVector {
77
77
  * @returns {Promise<void>} A promise that resolves when the collection is deleted.
78
78
  */
79
79
  deleteIndex(indexName: string): Promise<void>;
80
+ updateIndexById(indexName: string, id: string, update: {
81
+ vector?: number[];
82
+ metadata?: Record<string, any>;
83
+ }): Promise<void>;
84
+ deleteIndexById(indexName: string, id: string): Promise<void>;
80
85
  }
81
86
  export { AstraVector }
82
87
  export { AstraVector as AstraVector_alias_1 }
@@ -77,6 +77,11 @@ declare class AstraVector extends MastraVector {
77
77
  * @returns {Promise<void>} A promise that resolves when the collection is deleted.
78
78
  */
79
79
  deleteIndex(indexName: string): Promise<void>;
80
+ updateIndexById(indexName: string, id: string, update: {
81
+ vector?: number[];
82
+ metadata?: Record<string, any>;
83
+ }): Promise<void>;
84
+ deleteIndexById(indexName: string, id: string): Promise<void>;
80
85
  }
81
86
  export { AstraVector }
82
87
  export { AstraVector as AstraVector_alias_1 }
package/dist/index.cjs CHANGED
@@ -171,6 +171,28 @@ var AstraVector = class extends vector.MastraVector {
171
171
  const collection = this.#db.collection(indexName);
172
172
  await collection.drop();
173
173
  }
174
+ async updateIndexById(indexName, id, update) {
175
+ if (!update.vector && !update.metadata) {
176
+ throw new Error("No updates provided");
177
+ }
178
+ const collection = this.#db.collection(indexName);
179
+ const updateDoc = {};
180
+ if (update.vector) {
181
+ updateDoc.$vector = update.vector;
182
+ }
183
+ if (update.metadata) {
184
+ updateDoc.metadata = update.metadata;
185
+ }
186
+ await collection.findOneAndUpdate({ _id: id }, { $set: updateDoc });
187
+ }
188
+ async deleteIndexById(indexName, id) {
189
+ try {
190
+ const collection = this.#db.collection(indexName);
191
+ await collection.deleteOne({ _id: id });
192
+ } catch (error) {
193
+ throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
194
+ }
195
+ }
174
196
  };
175
197
 
176
198
  exports.AstraVector = AstraVector;
package/dist/index.js CHANGED
@@ -169,6 +169,28 @@ var AstraVector = class extends MastraVector {
169
169
  const collection = this.#db.collection(indexName);
170
170
  await collection.drop();
171
171
  }
172
+ async updateIndexById(indexName, id, update) {
173
+ if (!update.vector && !update.metadata) {
174
+ throw new Error("No updates provided");
175
+ }
176
+ const collection = this.#db.collection(indexName);
177
+ const updateDoc = {};
178
+ if (update.vector) {
179
+ updateDoc.$vector = update.vector;
180
+ }
181
+ if (update.metadata) {
182
+ updateDoc.metadata = update.metadata;
183
+ }
184
+ await collection.findOneAndUpdate({ _id: id }, { $set: updateDoc });
185
+ }
186
+ async deleteIndexById(indexName, id) {
187
+ try {
188
+ const collection = this.#db.collection(indexName);
189
+ await collection.deleteOne({ _id: id });
190
+ } catch (error) {
191
+ throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
192
+ }
193
+ }
172
194
  };
173
195
 
174
196
  export { AstraVector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/astra",
3
- "version": "0.1.8-alpha.3",
3
+ "version": "0.2.0-alpha.10",
4
4
  "description": "Astra DB provider for Mastra - includes vector store capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@datastax/astra-db-ts": "^1.5.0",
23
- "@mastra/core": "^0.5.0-alpha.3"
23
+ "@mastra/core": "^0.5.0-alpha.10"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@microsoft/api-extractor": "^7.49.2",
@@ -1153,4 +1153,115 @@ describe('AstraVector Integration Tests', () => {
1153
1153
  expect(upsertResults).toHaveLength(1);
1154
1154
  });
1155
1155
  });
1156
+
1157
+ describe('Basic vector operations', () => {
1158
+ const testVectors = [
1159
+ [1, 0, 0, 0],
1160
+ [0, 1, 0, 0],
1161
+ [0, 0, 1, 0],
1162
+ [0, 0, 0, 1],
1163
+ ];
1164
+
1165
+ it('should update the vector by id', async () => {
1166
+ const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
1167
+ expect(ids).toHaveLength(4);
1168
+
1169
+ const idToBeUpdated = ids[0];
1170
+ const newVector = [1, 2, 3, 4];
1171
+ const newMetaData = {
1172
+ test: 'updates',
1173
+ };
1174
+
1175
+ const update = {
1176
+ vector: newVector,
1177
+ metadata: newMetaData,
1178
+ };
1179
+
1180
+ await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
1181
+
1182
+ const results = await vectorDB.query({
1183
+ indexName: testIndexName,
1184
+ queryVector: newVector,
1185
+ topK: 2,
1186
+ includeVector: true,
1187
+ });
1188
+
1189
+ expect(results[0]?.vector).toEqual(newVector);
1190
+ expect(results[0]?.metadata).toEqual(newMetaData);
1191
+ });
1192
+
1193
+ it('should only update the metadata by id', async () => {
1194
+ const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
1195
+ expect(ids).toHaveLength(4);
1196
+ await new Promise(resolve => setTimeout(resolve, 2000));
1197
+
1198
+ const idToBeUpdated = ids[0];
1199
+ const newMetaData = {
1200
+ test: 'updates',
1201
+ };
1202
+
1203
+ const update = {
1204
+ metadata: newMetaData,
1205
+ };
1206
+
1207
+ await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
1208
+ await new Promise(resolve => setTimeout(resolve, 2000));
1209
+
1210
+ const results = await vectorDB.query({
1211
+ indexName: testIndexName,
1212
+ queryVector: testVectors[0],
1213
+ topK: 2,
1214
+ includeVector: true,
1215
+ });
1216
+
1217
+ expect(results[0]?.vector).toEqual(testVectors[0]);
1218
+ expect(results[0]?.metadata).toEqual(newMetaData);
1219
+ });
1220
+
1221
+ it('should only update vector embeddings by id', async () => {
1222
+ const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
1223
+ expect(ids).toHaveLength(4);
1224
+ await new Promise(resolve => setTimeout(resolve, 2000));
1225
+
1226
+ const idToBeUpdated = ids[0];
1227
+ const newVector = [1, 2, 3, 4];
1228
+
1229
+ const update = {
1230
+ vector: newVector,
1231
+ };
1232
+
1233
+ await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
1234
+ await new Promise(resolve => setTimeout(resolve, 2000));
1235
+
1236
+ const results = await vectorDB.query({
1237
+ indexName: testIndexName,
1238
+ queryVector: newVector,
1239
+ topK: 2,
1240
+ includeVector: true,
1241
+ });
1242
+
1243
+ expect(results[0]?.vector).toEqual(newVector);
1244
+ });
1245
+
1246
+ it('should throw exception when no updates are given', () => {
1247
+ expect(vectorDB.updateIndexById(testIndexName, 'id', {})).rejects.toThrow('No updates provided');
1248
+ });
1249
+
1250
+ it('should delete the vector by id', async () => {
1251
+ const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
1252
+ expect(ids).toHaveLength(4);
1253
+
1254
+ const idToBeDeleted = ids[0];
1255
+ await vectorDB.deleteIndexById(testIndexName, idToBeDeleted);
1256
+
1257
+ const results = await vectorDB.query({
1258
+ indexName: testIndexName,
1259
+ queryVector: [1, 0, 0, 0],
1260
+ topK: 2,
1261
+ });
1262
+
1263
+ expect(results).toHaveLength(2);
1264
+ expect(results.map(res => res.id)).not.toContain(idToBeDeleted);
1265
+ });
1266
+ });
1156
1267
  });
@@ -168,4 +168,36 @@ export class AstraVector extends MastraVector {
168
168
  const collection = this.#db.collection(indexName);
169
169
  await collection.drop();
170
170
  }
171
+
172
+ async updateIndexById(
173
+ indexName: string,
174
+ id: string,
175
+ update: { vector?: number[]; metadata?: Record<string, any> },
176
+ ): Promise<void> {
177
+ if (!update.vector && !update.metadata) {
178
+ throw new Error('No updates provided');
179
+ }
180
+
181
+ const collection = this.#db.collection(indexName);
182
+ const updateDoc: Record<string, any> = {};
183
+
184
+ if (update.vector) {
185
+ updateDoc.$vector = update.vector;
186
+ }
187
+
188
+ if (update.metadata) {
189
+ updateDoc.metadata = update.metadata;
190
+ }
191
+
192
+ await collection.findOneAndUpdate({ _id: id }, { $set: updateDoc });
193
+ }
194
+
195
+ async deleteIndexById(indexName: string, id: string): Promise<void> {
196
+ try {
197
+ const collection = this.#db.collection(indexName);
198
+ await collection.deleteOne({ _id: id });
199
+ } catch (error: any) {
200
+ throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
201
+ }
202
+ }
171
203
  }