@mastra/astra 0.1.8-alpha.3 → 0.2.0-alpha.5
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 +32 -0
- package/dist/_tsup-dts-rollup.d.cts +5 -0
- package/dist/_tsup-dts-rollup.d.ts +5 -0
- package/dist/index.cjs +22 -0
- package/dist/index.js +22 -0
- package/package.json +2 -2
- package/src/vector/index.test.ts +111 -0
- package/src/vector/index.ts +32 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/astra@0.
|
|
2
|
+
> @mastra/astra@0.2.0-alpha.5 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
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.3.6
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 6994ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.7.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.7.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 9048ms
|
|
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[32m7.16 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 555ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m7.13 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 556ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @mastra/astra
|
|
2
2
|
|
|
3
|
+
## 0.2.0-alpha.5
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5bfb4b6: Added new operations implementations for new MastraVector interface methods in astra store
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [22643eb]
|
|
12
|
+
- Updated dependencies [6feb23f]
|
|
13
|
+
- Updated dependencies [f2d6727]
|
|
14
|
+
- Updated dependencies [301e4ee]
|
|
15
|
+
- Updated dependencies [dfbe4e9]
|
|
16
|
+
- Updated dependencies [9e81f35]
|
|
17
|
+
- Updated dependencies [caefaa2]
|
|
18
|
+
- Updated dependencies [c151ae6]
|
|
19
|
+
- Updated dependencies [52e0418]
|
|
20
|
+
- Updated dependencies [03236ec]
|
|
21
|
+
- Updated dependencies [3764e71]
|
|
22
|
+
- Updated dependencies [df982db]
|
|
23
|
+
- Updated dependencies [0461849]
|
|
24
|
+
- Updated dependencies [2259379]
|
|
25
|
+
- Updated dependencies [358f069]
|
|
26
|
+
- @mastra/core@0.5.0-alpha.5
|
|
27
|
+
|
|
28
|
+
## 0.1.8-alpha.4
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [d79aedf]
|
|
33
|
+
- @mastra/core@0.5.0-alpha.4
|
|
34
|
+
|
|
3
35
|
## 0.1.8-alpha.3
|
|
4
36
|
|
|
5
37
|
### 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.
|
|
3
|
+
"version": "0.2.0-alpha.5",
|
|
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.
|
|
23
|
+
"@mastra/core": "^0.5.0-alpha.5"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@microsoft/api-extractor": "^7.49.2",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -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
|
});
|
package/src/vector/index.ts
CHANGED
|
@@ -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
|
}
|