@mastra/astra 0.2.5 → 0.2.6-alpha.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 +8 -0
- package/dist/index.cjs +4 -4
- package/dist/index.js +4 -4
- package/package.json +2 -2
- package/src/vector/index.test.ts +43 -23
- package/src/vector/index.ts +4 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/astra@0.2.
|
|
2
|
+
> @mastra/astra@0.2.6-alpha.0 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 5677ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
[34mCLI[39m Cleaning output folder
|
|
@@ -16,8 +16,8 @@ Analysis will use the bundled TypeScript version 5.8.2
|
|
|
16
16
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/astra/dist/_tsup-dts-rollup.d.ts[39m
|
|
17
17
|
Analysis will use the bundled TypeScript version 5.8.2
|
|
18
18
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/astra/dist/_tsup-dts-rollup.d.cts[39m
|
|
19
|
-
[32mDTS[39m ⚡️ Build success in
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
19
|
+
[32mDTS[39m ⚡️ Build success in 7633ms
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m7.09 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 8059ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m7.06 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 8059ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @mastra/astra
|
|
2
2
|
|
|
3
|
+
## 0.2.6-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 15702ff: Updated upsert, updateIndexById, deleteIndexById for astra and updated tests for astra and vectorize
|
|
8
|
+
- Updated dependencies [b4fbc59]
|
|
9
|
+
- @mastra/core@0.6.5-alpha.0
|
|
10
|
+
|
|
3
11
|
## 0.2.5
|
|
4
12
|
|
|
5
13
|
### 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
|
-
|
|
105
|
-
return
|
|
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({
|
|
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({
|
|
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
|
-
|
|
103
|
-
return
|
|
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({
|
|
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({
|
|
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.
|
|
3
|
+
"version": "0.2.6-alpha.0",
|
|
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.6.
|
|
23
|
+
"@mastra/core": "^0.6.5-alpha.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@microsoft/api-extractor": "^7.52.1",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -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
|
|
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(
|
|
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:
|
|
1193
|
+
indexName: indexName,
|
|
1184
1194
|
queryVector: newVector,
|
|
1185
1195
|
topK: 2,
|
|
1186
1196
|
includeVector: true,
|
|
1187
1197
|
});
|
|
1188
1198
|
|
|
1189
|
-
expect(results
|
|
1190
|
-
|
|
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
|
|
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(
|
|
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:
|
|
1224
|
+
indexName: indexName,
|
|
1212
1225
|
queryVector: testVectors[0],
|
|
1213
1226
|
topK: 2,
|
|
1214
1227
|
includeVector: true,
|
|
1215
1228
|
});
|
|
1216
1229
|
|
|
1217
|
-
expect(results
|
|
1218
|
-
|
|
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
|
|
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(
|
|
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:
|
|
1253
|
+
indexName: indexName,
|
|
1238
1254
|
queryVector: newVector,
|
|
1239
1255
|
topK: 2,
|
|
1240
1256
|
includeVector: true,
|
|
1241
1257
|
});
|
|
1242
1258
|
|
|
1243
|
-
expect(results
|
|
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(
|
|
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
|
|
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(
|
|
1275
|
+
await vectorDB.deleteIndexById(indexName, idToBeDeleted);
|
|
1256
1276
|
|
|
1257
1277
|
const results = await vectorDB.query({
|
|
1258
|
-
indexName:
|
|
1278
|
+
indexName: indexName,
|
|
1259
1279
|
queryVector: [1, 0, 0, 0],
|
|
1260
1280
|
topK: 2,
|
|
1261
1281
|
});
|
package/src/vector/index.ts
CHANGED
|
@@ -85,8 +85,8 @@ export class AstraVector extends MastraVector {
|
|
|
85
85
|
metadata: metadata?.[i] || {},
|
|
86
86
|
}));
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
return
|
|
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({
|
|
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({
|
|
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
|
}
|