@mastra/astra 0.2.5 → 0.2.6-alpha.1

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.2.5-alpha.1 build /home/runner/work/mastra/mastra/stores/astra
2
+ > @mastra/astra@0.2.6-alpha.1 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
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.4.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 7826ms
9
+ TSC ⚡️ Build success in 6009ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
- CLI Cleaning output folder
13
- ESM Build start
14
- CJS Build start
15
12
  Analysis will use the bundled TypeScript version 5.8.2
16
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/astra/dist/_tsup-dts-rollup.d.ts
17
14
  Analysis will use the bundled TypeScript version 5.8.2
18
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/astra/dist/_tsup-dts-rollup.d.cts
19
- DTS ⚡️ Build success in 9392ms
20
- ESM dist/index.js 7.13 KB
21
- ESM ⚡️ Build success in 9751ms
22
- CJS dist/index.cjs 7.16 KB
23
- CJS ⚡️ Build success in 9742ms
16
+ DTS ⚡️ Build success in 9729ms
17
+ CLI Cleaning output folder
18
+ ESM Build start
19
+ CJS Build start
20
+ CJS dist/index.cjs 7.09 KB
21
+ CJS ⚡️ Build success in 598ms
22
+ ESM dist/index.js 7.06 KB
23
+ ESM ⚡️ Build success in 601ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @mastra/astra
2
2
 
3
+ ## 0.2.6-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [0b54522]
8
+ - Updated dependencies [1af25d5]
9
+ - Updated dependencies [27439ad]
10
+ - @mastra/core@0.7.0-alpha.1
11
+
12
+ ## 0.2.6-alpha.0
13
+
14
+ ### Patch Changes
15
+
16
+ - 15702ff: Updated upsert, updateIndexById, deleteIndexById for astra and updated tests for astra and vectorize
17
+ - Updated dependencies [b4fbc59]
18
+ - @mastra/core@0.6.5-alpha.0
19
+
3
20
  ## 0.2.5
4
21
 
5
22
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -101,8 +101,8 @@ var AstraVector = class extends vector.MastraVector {
101
101
  $vector: vector,
102
102
  metadata: metadata?.[i] || {}
103
103
  }));
104
- const result = await collection.insertMany(records);
105
- return result.insertedIds.map((id) => (id || "").toString());
104
+ await collection.insertMany(records);
105
+ return vectorIds;
106
106
  }
107
107
  transformFilter(filter) {
108
108
  const translator = new AstraFilterTranslator();
@@ -183,12 +183,12 @@ var AstraVector = class extends vector.MastraVector {
183
183
  if (update.metadata) {
184
184
  updateDoc.metadata = update.metadata;
185
185
  }
186
- await collection.findOneAndUpdate({ _id: id }, { $set: updateDoc });
186
+ await collection.findOneAndUpdate({ id }, { $set: updateDoc });
187
187
  }
188
188
  async deleteIndexById(indexName, id) {
189
189
  try {
190
190
  const collection = this.#db.collection(indexName);
191
- await collection.deleteOne({ _id: id });
191
+ await collection.deleteOne({ id });
192
192
  } catch (error) {
193
193
  throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
194
194
  }
package/dist/index.js CHANGED
@@ -99,8 +99,8 @@ var AstraVector = class extends MastraVector {
99
99
  $vector: vector,
100
100
  metadata: metadata?.[i] || {}
101
101
  }));
102
- const result = await collection.insertMany(records);
103
- return result.insertedIds.map((id) => (id || "").toString());
102
+ await collection.insertMany(records);
103
+ return vectorIds;
104
104
  }
105
105
  transformFilter(filter) {
106
106
  const translator = new AstraFilterTranslator();
@@ -181,12 +181,12 @@ var AstraVector = class extends MastraVector {
181
181
  if (update.metadata) {
182
182
  updateDoc.metadata = update.metadata;
183
183
  }
184
- await collection.findOneAndUpdate({ _id: id }, { $set: updateDoc });
184
+ await collection.findOneAndUpdate({ id }, { $set: updateDoc });
185
185
  }
186
186
  async deleteIndexById(indexName, id) {
187
187
  try {
188
188
  const collection = this.#db.collection(indexName);
189
- await collection.deleteOne({ _id: id });
189
+ await collection.deleteOne({ id });
190
190
  } catch (error) {
191
191
  throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
192
192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/astra",
3
- "version": "0.2.5",
3
+ "version": "0.2.6-alpha.1",
4
4
  "description": "Astra DB provider for Mastra - includes vector store capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,15 +20,15 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@datastax/astra-db-ts": "^1.5.0",
23
- "@mastra/core": "^0.6.4"
23
+ "@mastra/core": "^0.7.0-alpha.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@microsoft/api-extractor": "^7.52.1",
27
- "@types/node": "^22.13.10",
28
- "eslint": "^9.22.0",
27
+ "@types/node": "^20.17.27",
28
+ "eslint": "^9.23.0",
29
29
  "tsup": "^8.4.0",
30
30
  "typescript": "^5.8.2",
31
- "vitest": "^3.0.8",
31
+ "vitest": "^3.0.9",
32
32
  "@internal/lint": "0.0.1"
33
33
  },
34
34
  "scripts": {
@@ -28,8 +28,6 @@ describe('AstraVector Integration Tests', () => {
28
28
  const testIndexName = 'testvectors1733728136118'; // Unique collection name
29
29
  const testIndexName2 = 'testvectors1733728136119'; // Unique collection name
30
30
 
31
- console.log('testIndexName:', testIndexName);
32
-
33
31
  beforeAll(async () => {
34
32
  // Ensure required environment variables are set
35
33
  const token = process.env.ASTRA_DB_TOKEN;
@@ -1155,6 +1153,16 @@ describe('AstraVector Integration Tests', () => {
1155
1153
  });
1156
1154
 
1157
1155
  describe('Basic vector operations', () => {
1156
+ const indexName = 'testbasicvectoroperations';
1157
+
1158
+ beforeAll(async () => {
1159
+ await vectorDB.createIndex({ indexName, dimension: 4 });
1160
+ });
1161
+
1162
+ afterAll(async () => {
1163
+ await vectorDB.deleteIndex(indexName);
1164
+ });
1165
+
1158
1166
  const testVectors = [
1159
1167
  [1, 0, 0, 0],
1160
1168
  [0, 1, 0, 0],
@@ -1163,7 +1171,7 @@ describe('AstraVector Integration Tests', () => {
1163
1171
  ];
1164
1172
 
1165
1173
  it('should update the vector by id', async () => {
1166
- const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
1174
+ const ids = await vectorDB.upsert({ indexName, vectors: testVectors });
1167
1175
  expect(ids).toHaveLength(4);
1168
1176
 
1169
1177
  const idToBeUpdated = ids[0];
@@ -1177,23 +1185,28 @@ describe('AstraVector Integration Tests', () => {
1177
1185
  metadata: newMetaData,
1178
1186
  };
1179
1187
 
1180
- await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
1188
+ await vectorDB.updateIndexById(indexName, idToBeUpdated, update);
1189
+
1190
+ await new Promise(resolve => setTimeout(resolve, 2000));
1181
1191
 
1182
1192
  const results = await vectorDB.query({
1183
- indexName: testIndexName,
1193
+ indexName: indexName,
1184
1194
  queryVector: newVector,
1185
1195
  topK: 2,
1186
1196
  includeVector: true,
1187
1197
  });
1188
1198
 
1189
- expect(results[0]?.vector).toEqual(newVector);
1190
- expect(results[0]?.metadata).toEqual(newMetaData);
1199
+ expect(results).toHaveLength(2);
1200
+ const updatedResult = results.find(result => result.id === idToBeUpdated);
1201
+ expect(updatedResult).toBeDefined();
1202
+ expect(updatedResult?.id).toEqual(idToBeUpdated);
1203
+ expect(updatedResult?.vector).toEqual(newVector);
1204
+ expect(updatedResult?.metadata).toEqual(newMetaData);
1191
1205
  });
1192
1206
 
1193
1207
  it('should only update the metadata by id', async () => {
1194
- const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
1208
+ const ids = await vectorDB.upsert({ indexName, vectors: testVectors });
1195
1209
  expect(ids).toHaveLength(4);
1196
- await new Promise(resolve => setTimeout(resolve, 2000));
1197
1210
 
1198
1211
  const idToBeUpdated = ids[0];
1199
1212
  const newMetaData = {
@@ -1204,24 +1217,27 @@ describe('AstraVector Integration Tests', () => {
1204
1217
  metadata: newMetaData,
1205
1218
  };
1206
1219
 
1207
- await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
1220
+ await vectorDB.updateIndexById(indexName, idToBeUpdated, update);
1208
1221
  await new Promise(resolve => setTimeout(resolve, 2000));
1209
1222
 
1210
1223
  const results = await vectorDB.query({
1211
- indexName: testIndexName,
1224
+ indexName: indexName,
1212
1225
  queryVector: testVectors[0],
1213
1226
  topK: 2,
1214
1227
  includeVector: true,
1215
1228
  });
1216
1229
 
1217
- expect(results[0]?.vector).toEqual(testVectors[0]);
1218
- expect(results[0]?.metadata).toEqual(newMetaData);
1230
+ expect(results).toHaveLength(2);
1231
+ const updatedResult = results.find(result => result.id === idToBeUpdated);
1232
+ expect(updatedResult).toBeDefined();
1233
+ expect(updatedResult?.id).toEqual(idToBeUpdated);
1234
+ expect(updatedResult?.vector).toEqual(testVectors[0]);
1235
+ expect(updatedResult?.metadata).toEqual(newMetaData);
1219
1236
  });
1220
1237
 
1221
1238
  it('should only update vector embeddings by id', async () => {
1222
- const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
1239
+ const ids = await vectorDB.upsert({ indexName, vectors: testVectors });
1223
1240
  expect(ids).toHaveLength(4);
1224
- await new Promise(resolve => setTimeout(resolve, 2000));
1225
1241
 
1226
1242
  const idToBeUpdated = ids[0];
1227
1243
  const newVector = [1, 2, 3, 4];
@@ -1230,32 +1246,36 @@ describe('AstraVector Integration Tests', () => {
1230
1246
  vector: newVector,
1231
1247
  };
1232
1248
 
1233
- await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
1249
+ await vectorDB.updateIndexById(indexName, idToBeUpdated, update);
1234
1250
  await new Promise(resolve => setTimeout(resolve, 2000));
1235
1251
 
1236
1252
  const results = await vectorDB.query({
1237
- indexName: testIndexName,
1253
+ indexName: indexName,
1238
1254
  queryVector: newVector,
1239
1255
  topK: 2,
1240
1256
  includeVector: true,
1241
1257
  });
1242
1258
 
1243
- expect(results[0]?.vector).toEqual(newVector);
1259
+ expect(results).toHaveLength(2);
1260
+ const updatedResult = results.find(result => result.id === idToBeUpdated);
1261
+ expect(updatedResult).toBeDefined();
1262
+ expect(updatedResult?.id).toEqual(idToBeUpdated);
1263
+ expect(updatedResult?.vector).toEqual(newVector);
1244
1264
  });
1245
1265
 
1246
- it('should throw exception when no updates are given', () => {
1247
- expect(vectorDB.updateIndexById(testIndexName, 'id', {})).rejects.toThrow('No updates provided');
1266
+ it('should throw exception when no updates are given', async () => {
1267
+ await expect(vectorDB.updateIndexById(indexName, 'id', {})).rejects.toThrow('No updates provided');
1248
1268
  });
1249
1269
 
1250
1270
  it('should delete the vector by id', async () => {
1251
- const ids = await vectorDB.upsert({ indexName: testIndexName, vectors: testVectors });
1271
+ const ids = await vectorDB.upsert({ indexName, vectors: testVectors });
1252
1272
  expect(ids).toHaveLength(4);
1253
1273
 
1254
1274
  const idToBeDeleted = ids[0];
1255
- await vectorDB.deleteIndexById(testIndexName, idToBeDeleted);
1275
+ await vectorDB.deleteIndexById(indexName, idToBeDeleted);
1256
1276
 
1257
1277
  const results = await vectorDB.query({
1258
- indexName: testIndexName,
1278
+ indexName: indexName,
1259
1279
  queryVector: [1, 0, 0, 0],
1260
1280
  topK: 2,
1261
1281
  });
@@ -85,8 +85,8 @@ export class AstraVector extends MastraVector {
85
85
  metadata: metadata?.[i] || {},
86
86
  }));
87
87
 
88
- const result = await collection.insertMany(records);
89
- return result.insertedIds.map(id => (id || '').toString());
88
+ await collection.insertMany(records);
89
+ return vectorIds;
90
90
  }
91
91
 
92
92
  transformFilter(filter?: VectorFilter) {
@@ -189,13 +189,13 @@ export class AstraVector extends MastraVector {
189
189
  updateDoc.metadata = update.metadata;
190
190
  }
191
191
 
192
- await collection.findOneAndUpdate({ _id: id }, { $set: updateDoc });
192
+ await collection.findOneAndUpdate({ id }, { $set: updateDoc });
193
193
  }
194
194
 
195
195
  async deleteIndexById(indexName: string, id: string): Promise<void> {
196
196
  try {
197
197
  const collection = this.#db.collection(indexName);
198
- await collection.deleteOne({ _id: id });
198
+ await collection.deleteOne({ id });
199
199
  } catch (error: any) {
200
200
  throw new Error(`Failed to delete index by id: ${id} for index name: ${indexName}: ${error.message}`);
201
201
  }