@mastra/astra 0.1.0-alpha.28

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/CHANGELOG.md ADDED
@@ -0,0 +1,263 @@
1
+ # @mastra/astra
2
+
3
+ ## 0.1.0-alpha.28
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [5285356]
8
+ - @mastra/core@0.2.0-alpha.93
9
+
10
+ ## 0.1.0-alpha.27
11
+
12
+ ### Minor Changes
13
+
14
+ - c87eb4e: Move Astra package from `@mastra/vector-astra` to `@mastra/astra`.
15
+
16
+ - Move package to `stores/astra`
17
+ - Reorganize source files into `src/vector`
18
+ - Add deprecation notice to old package
19
+ - Update documentation and examples
20
+ - No breaking changes in functionality
21
+
22
+ ## 0.1.0-alpha.1
23
+
24
+ ### Major Changes
25
+
26
+ - Package renamed from @mastra/vector-astra to @mastra/astra
27
+ - Moved package to stores/ directory for better organization
28
+ - All functionality remains the same
29
+
30
+ ### Migration
31
+
32
+ To migrate from @mastra/vector-astra:
33
+
34
+ 1. Remove @mastra/vector-astra from dependencies
35
+ 2. Install @mastra/astra
36
+ 3. Update imports from '@mastra/vector-astra' to '@mastra/astra'
37
+
38
+ ### Previous History
39
+
40
+ This package was previously published as @mastra/vector-astra. Key changes from that history:
41
+
42
+ - Implemented unified filter API for vector stores
43
+ - Added support for cosine, euclidean, and dot product metrics
44
+ - Added metadata filtering support
45
+ - Added batch vector operations
46
+ - Improved collection management
47
+ - Updated operator validation and handling
48
+ - Various dependency updates and bug fixes
49
+
50
+ ## 0.1.0-alpha.26
51
+
52
+ ### Patch Changes
53
+
54
+ - Updated dependencies [4d4f6b6]
55
+ - @mastra/core@0.2.0-alpha.92
56
+
57
+ ## 0.1.0-alpha.25
58
+
59
+ ### Patch Changes
60
+
61
+ - a10b7a3: Implemented new filtering for vectorQueryTool and updated docs
62
+ - Updated dependencies [d7d465a]
63
+ - Updated dependencies [d7d465a]
64
+ - Updated dependencies [2017553]
65
+ - Updated dependencies [a10b7a3]
66
+ - Updated dependencies [16e5b04]
67
+ - @mastra/core@0.2.0-alpha.91
68
+
69
+ ## 0.1.0-alpha.24
70
+
71
+ ### Patch Changes
72
+
73
+ - Updated dependencies [8151f44]
74
+ - Updated dependencies [e897f1c]
75
+ - Updated dependencies [3700be1]
76
+ - @mastra/core@0.2.0-alpha.90
77
+
78
+ ## 0.1.0-alpha.23
79
+
80
+ ### Patch Changes
81
+
82
+ - Updated dependencies [27275c9]
83
+ - @mastra/core@0.2.0-alpha.89
84
+
85
+ ## 0.1.0-alpha.22
86
+
87
+ ### Patch Changes
88
+
89
+ - ccbc581: Updated operator validation and handling for all vector stores
90
+ - Updated dependencies [ccbc581]
91
+ - @mastra/core@0.2.0-alpha.88
92
+
93
+ ## 0.1.0-alpha.21
94
+
95
+ ### Patch Changes
96
+
97
+ - Updated dependencies [7365b6c]
98
+ - @mastra/core@0.2.0-alpha.87
99
+
100
+ ## 0.1.0-alpha.20
101
+
102
+ ### Minor Changes
103
+
104
+ - 5916f9d: Update deps from fixed to ^
105
+
106
+ ### Patch Changes
107
+
108
+ - 7f24c29: Add Chroma Filter translator and updated vector store tests
109
+ - Updated dependencies [6fa4bd2]
110
+ - Updated dependencies [e2e76de]
111
+ - Updated dependencies [7f24c29]
112
+ - Updated dependencies [67637ba]
113
+ - Updated dependencies [04f3171]
114
+ - @mastra/core@0.2.0-alpha.86
115
+
116
+ ## 0.0.1-alpha.19
117
+
118
+ ### Patch Changes
119
+
120
+ - Updated dependencies [e9d1b47]
121
+ - @mastra/core@0.2.0-alpha.85
122
+
123
+ ## 0.0.1-alpha.18
124
+
125
+ ### Patch Changes
126
+
127
+ - Updated dependencies [2f17a5f]
128
+ - Updated dependencies [cb290ee]
129
+ - Updated dependencies [b4d7416]
130
+ - Updated dependencies [38b7f66]
131
+ - @mastra/core@0.2.0-alpha.84
132
+
133
+ ## 0.0.1-alpha.17
134
+
135
+ ### Patch Changes
136
+
137
+ - 34048bb: Hook up Astra filter and added tests
138
+ - 78eec7c: Started implementation on Unified Filter API for several vector stores.
139
+ - 9625602: Use mastra core splitted bundles in other packages
140
+ - Updated dependencies [30322ce]
141
+ - Updated dependencies [78eec7c]
142
+ - Updated dependencies [9625602]
143
+ - Updated dependencies [8769a62]
144
+ - @mastra/core@0.2.0-alpha.83
145
+
146
+ ## 0.0.1-alpha.16
147
+
148
+ ### Patch Changes
149
+
150
+ - Updated dependencies [73d112c]
151
+ - @mastra/core@0.1.27-alpha.82
152
+
153
+ ## 0.0.1-alpha.15
154
+
155
+ ### Patch Changes
156
+
157
+ - Updated dependencies [9fb3039]
158
+ - @mastra/core@0.1.27-alpha.81
159
+
160
+ ## 0.0.1-alpha.14
161
+
162
+ ### Patch Changes
163
+
164
+ - b422ed3: Bundle vector provider packages with tsup
165
+
166
+ ## 0.0.1-alpha.13
167
+
168
+ ### Patch Changes
169
+
170
+ - Updated dependencies [327ece7]
171
+ - @mastra/core@0.1.27-alpha.80
172
+
173
+ ## 0.0.1-alpha.12
174
+
175
+ ### Patch Changes
176
+
177
+ - Updated dependencies [21fe536]
178
+ - @mastra/core@0.1.27-alpha.79
179
+
180
+ ## 0.0.1-alpha.11
181
+
182
+ ### Patch Changes
183
+
184
+ - Updated dependencies [685108a]
185
+ - Updated dependencies [685108a]
186
+ - @mastra/core@0.1.27-alpha.78
187
+
188
+ ## 0.0.1-alpha.10
189
+
190
+ ### Patch Changes
191
+
192
+ - Updated dependencies [8105fae]
193
+ - @mastra/core@0.1.27-alpha.77
194
+
195
+ ## 0.0.1-alpha.9
196
+
197
+ ### Patch Changes
198
+
199
+ - 7a469e7: Bump vectors
200
+
201
+ ## 0.0.1-alpha.8
202
+
203
+ ### Patch Changes
204
+
205
+ - Updated dependencies [ae7bf94]
206
+ - Updated dependencies [ae7bf94]
207
+ - @mastra/core@0.1.27-alpha.76
208
+
209
+ ## 0.0.1-alpha.7
210
+
211
+ ### Patch Changes
212
+
213
+ - Updated dependencies [23dcb23]
214
+ - @mastra/core@0.1.27-alpha.75
215
+
216
+ ## 0.0.1-alpha.6
217
+
218
+ ### Patch Changes
219
+
220
+ - Updated dependencies [7b87567]
221
+ - @mastra/core@0.1.27-alpha.74
222
+
223
+ ## 0.0.1-alpha.5
224
+
225
+ ### Patch Changes
226
+
227
+ - Updated dependencies [3427b95]
228
+ - @mastra/core@0.1.27-alpha.73
229
+
230
+ ## 0.0.1-alpha.4
231
+
232
+ ### Patch Changes
233
+
234
+ - Updated dependencies [e4d4ede]
235
+ - Updated dependencies [06b2c0a]
236
+ - @mastra/core@0.1.27-alpha.72
237
+
238
+ ## 0.0.1-alpha.3
239
+
240
+ ### Patch Changes
241
+
242
+ - Updated dependencies [d9c8dd0]
243
+ - @mastra/core@0.1.27-alpha.71
244
+
245
+ ## 0.0.1-alpha.2
246
+
247
+ ### Patch Changes
248
+
249
+ - bdaf834: publish packages
250
+
251
+ ## 0.0.1-alpha.1
252
+
253
+ ### Patch Changes
254
+
255
+ - Updated dependencies [dd6d87f]
256
+ - Updated dependencies [04434b6]
257
+ - @mastra/core@0.1.27-alpha.70
258
+
259
+ ## 0.0.1-alpha.0
260
+
261
+ ### Patch Changes
262
+
263
+ - 0d5a03d: Vector store modules
package/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ Elastic License 2.0 (ELv2)
2
+
3
+ **Acceptance**
4
+ By using the software, you agree to all of the terms and conditions below.
5
+
6
+ **Copyright License**
7
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
8
+
9
+ **Limitations**
10
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
11
+
12
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
13
+
14
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
15
+
16
+ **Patents**
17
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
18
+
19
+ **Notices**
20
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
21
+
22
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
23
+
24
+ **No Other Rights**
25
+ These terms do not imply any licenses other than those expressly granted in these terms.
26
+
27
+ **Termination**
28
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
29
+
30
+ **No Liability**
31
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
32
+
33
+ **Definitions**
34
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
35
+
36
+ _you_ refers to the individual or entity agreeing to these terms.
37
+
38
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
39
+
40
+ _your licenses_ are all the licenses granted to you for the software under these terms.
41
+
42
+ _use_ means anything you do with the software requiring one of your licenses.
43
+
44
+ _trademark_ means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # @mastra/astra
2
+
3
+ Vector store implementation for DataStax Astra DB, providing vector similarity search capabilities using Cassandra's vector search functionality.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/astra
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { AstraVector } from '@mastra/astra';
15
+
16
+ const vectorStore = new AstraVector({
17
+ token: 'your-astra-token',
18
+ endpoint: 'your-astra-endpoint',
19
+ keyspace: 'your-keyspace' // optional
20
+ });
21
+
22
+ // Create a new collection
23
+ await vectorStore.createIndex('my-collection', 1536, 'cosine');
24
+
25
+ // Add vectors
26
+ const vectors = [[0.1, 0.2, ...], [0.3, 0.4, ...]];
27
+ const metadata = [{ text: 'doc1' }, { text: 'doc2' }];
28
+ const ids = await vectorStore.upsert('my-collection', vectors, metadata);
29
+
30
+ // Query vectors
31
+ const results = await vectorStore.query(
32
+ 'my-collection',
33
+ [0.1, 0.2, ...],
34
+ 10, // topK
35
+ { text: { $eq: 'doc1' } }, // optional filter
36
+ false // includeVectors
37
+ );
38
+ ```
39
+
40
+ ## Configuration
41
+
42
+ The Astra DB vector store requires:
43
+
44
+ - `token`: Your Astra DB token
45
+ - `endpoint`: Your Astra DB endpoint
46
+ - `keyspace`: (Optional) The keyspace to use
47
+
48
+ ## Features
49
+
50
+ - Vector similarity search with cosine, euclidean, and dot product metrics
51
+ - Metadata filtering support
52
+ - Batch vector upsert operations
53
+ - Collection management (create, list, describe, delete)
54
+ - Optional vector inclusion in query results
55
+ - Automatic UUID generation for vectors
56
+ - Built on top of @datastax/astra-db-ts client
57
+
58
+ ## Methods
59
+
60
+ - `createIndex(indexName, dimension, metric?)`: Create a new collection
61
+ - `upsert(indexName, vectors, metadata?, ids?)`: Add or update vectors
62
+ - `query(indexName, queryVector, topK?, filter?, includeVector?)`: Search for similar vectors
63
+ - `listIndexes()`: List all collections
64
+ - `describeIndex(indexName)`: Get collection statistics
65
+ - `deleteIndex(indexName)`: Delete a collection
66
+
67
+ ## Related Links
68
+
69
+ - [Astra DB Vector Search Documentation](https://docs.datastax.com/en/astra-db/docs/vector-search.html)
70
+ - [Astra DB API Reference](https://docs.datastax.com/en/astra-db-serverless/api-reference/documents.html)
@@ -0,0 +1,59 @@
1
+ import { Filter } from '@mastra/core/filter';
2
+ import { MastraVector, QueryResult, IndexStats } from '@mastra/core/vector';
3
+
4
+ interface AstraDbOptions {
5
+ token: string;
6
+ endpoint: string;
7
+ keyspace?: string;
8
+ }
9
+ declare class AstraVector extends MastraVector {
10
+ #private;
11
+ constructor({ token, endpoint, keyspace }: AstraDbOptions);
12
+ /**
13
+ * Creates a new collection with the specified configuration.
14
+ *
15
+ * @param {string} indexName - The name of the collection to create.
16
+ * @param {number} dimension - The dimension of the vectors to be stored in the collection.
17
+ * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
18
+ * @returns {Promise<void>} A promise that resolves when the collection is created.
19
+ */
20
+ createIndex(indexName: string, dimension: number, metric?: 'cosine' | 'euclidean' | 'dotproduct'): Promise<void>;
21
+ /**
22
+ * Inserts or updates vectors in the specified collection.
23
+ *
24
+ * @param {string} indexName - The name of the collection to upsert into.
25
+ * @param {number[][]} vectors - An array of vectors to upsert.
26
+ * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.
27
+ * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
28
+ * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
29
+ */
30
+ upsert(indexName: string, vectors: number[][], metadata?: Record<string, any>[], ids?: string[]): Promise<string[]>;
31
+ transformFilter(filter?: Filter): Filter;
32
+ /**
33
+ * Queries the specified collection using a vector and optional filter.
34
+ *
35
+ * @param {string} indexName - The name of the collection to query.
36
+ * @param {number[]} queryVector - The vector to query with.
37
+ * @param {number} [topK] - The maximum number of results to return.
38
+ * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in Astra DB, see the filtering reference: https://docs.datastax.com/en/astra-db-serverless/api-reference/documents.html#operators
39
+ * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
40
+ * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
41
+ */
42
+ query(indexName: string, queryVector: number[], topK?: number, filter?: Filter, includeVector?: boolean): Promise<QueryResult[]>;
43
+ /**
44
+ * Lists all collections in the database.
45
+ *
46
+ * @returns {Promise<string[]>} A promise that resolves to an array of collection names.
47
+ */
48
+ listIndexes(): Promise<string[]>;
49
+ describeIndex(indexName: string): Promise<IndexStats>;
50
+ /**
51
+ * Deletes the specified collection.
52
+ *
53
+ * @param {string} indexName - The name of the collection to delete.
54
+ * @returns {Promise<void>} A promise that resolves when the collection is deleted.
55
+ */
56
+ deleteIndex(indexName: string): Promise<void>;
57
+ }
58
+
59
+ export { type AstraDbOptions, AstraVector };
package/dist/index.js ADDED
@@ -0,0 +1,177 @@
1
+ import { DataAPIClient, UUID } from '@datastax/astra-db-ts';
2
+ import { MastraVector } from '@mastra/core/vector';
3
+ import { BaseFilterTranslator } from '@mastra/core/filter';
4
+
5
+ var __typeError = (msg) => {
6
+ throw TypeError(msg);
7
+ };
8
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
9
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
10
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
11
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
12
+ var AstraFilterTranslator = class extends BaseFilterTranslator {
13
+ getSupportedOperators() {
14
+ return {
15
+ ...BaseFilterTranslator.DEFAULT_OPERATORS,
16
+ array: ["$all", "$in", "$nin"],
17
+ logical: ["$and", "$or", "$not"],
18
+ regex: [],
19
+ custom: ["$size"]
20
+ };
21
+ }
22
+ translate(filter) {
23
+ if (this.isEmpty(filter)) return filter;
24
+ this.validateFilter(filter);
25
+ return this.translateNode(filter);
26
+ }
27
+ translateNode(node) {
28
+ if (this.isRegex(node)) {
29
+ throw new Error("Regex is not supported in Astra DB");
30
+ }
31
+ if (this.isPrimitive(node) || Array.isArray(node)) {
32
+ return node;
33
+ }
34
+ const entries = Object.entries(node);
35
+ const translatedEntries = entries.map(([key, value]) => {
36
+ if (this.isOperator(key)) {
37
+ return [key, this.translateOperatorValue(key, value)];
38
+ }
39
+ return [key, this.translateNode(value)];
40
+ });
41
+ return Object.fromEntries(translatedEntries);
42
+ }
43
+ translateOperatorValue(operator, value) {
44
+ if (this.isBasicOperator(operator) || this.isNumericOperator(operator)) {
45
+ return this.normalizeComparisonValue(value);
46
+ }
47
+ if (this.isArrayOperator(operator) && Array.isArray(value)) {
48
+ return this.normalizeArrayValues(value);
49
+ }
50
+ return this.translateNode(value);
51
+ }
52
+ };
53
+
54
+ // src/vector/index.ts
55
+ var metricMap = {
56
+ cosine: "cosine",
57
+ euclidean: "euclidean",
58
+ dotproduct: "dot_product"
59
+ };
60
+ var _db;
61
+ var AstraVector = class extends MastraVector {
62
+ constructor({ token, endpoint, keyspace }) {
63
+ super();
64
+ __privateAdd(this, _db);
65
+ const client = new DataAPIClient(token);
66
+ __privateSet(this, _db, client.db(endpoint, { keyspace }));
67
+ }
68
+ /**
69
+ * Creates a new collection with the specified configuration.
70
+ *
71
+ * @param {string} indexName - The name of the collection to create.
72
+ * @param {number} dimension - The dimension of the vectors to be stored in the collection.
73
+ * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
74
+ * @returns {Promise<void>} A promise that resolves when the collection is created.
75
+ */
76
+ async createIndex(indexName, dimension, metric = "cosine") {
77
+ if (!Number.isInteger(dimension) || dimension <= 0) {
78
+ throw new Error("Dimension must be a positive integer");
79
+ }
80
+ await __privateGet(this, _db).createCollection(indexName, {
81
+ vector: {
82
+ dimension,
83
+ metric: metricMap[metric]
84
+ },
85
+ checkExists: false
86
+ });
87
+ }
88
+ /**
89
+ * Inserts or updates vectors in the specified collection.
90
+ *
91
+ * @param {string} indexName - The name of the collection to upsert into.
92
+ * @param {number[][]} vectors - An array of vectors to upsert.
93
+ * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.
94
+ * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
95
+ * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
96
+ */
97
+ async upsert(indexName, vectors, metadata, ids) {
98
+ const collection = __privateGet(this, _db).collection(indexName);
99
+ const vectorIds = ids || vectors.map(() => UUID.v7().toString());
100
+ const records = vectors.map((vector, i) => ({
101
+ id: vectorIds[i],
102
+ $vector: vector,
103
+ metadata: metadata?.[i] || {}
104
+ }));
105
+ const result = await collection.insertMany(records);
106
+ return result.insertedIds.map((id) => (id || "").toString());
107
+ }
108
+ transformFilter(filter) {
109
+ const astraFilter = new AstraFilterTranslator();
110
+ const translatedFilter = astraFilter.translate(filter ?? {});
111
+ return translatedFilter;
112
+ }
113
+ /**
114
+ * Queries the specified collection using a vector and optional filter.
115
+ *
116
+ * @param {string} indexName - The name of the collection to query.
117
+ * @param {number[]} queryVector - The vector to query with.
118
+ * @param {number} [topK] - The maximum number of results to return.
119
+ * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in Astra DB, see the filtering reference: https://docs.datastax.com/en/astra-db-serverless/api-reference/documents.html#operators
120
+ * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
121
+ * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
122
+ */
123
+ async query(indexName, queryVector, topK, filter, includeVector = false) {
124
+ const collection = __privateGet(this, _db).collection(indexName);
125
+ const translatedFilter = this.transformFilter(filter);
126
+ const cursor = collection.find(translatedFilter ?? {}, {
127
+ sort: { $vector: queryVector },
128
+ limit: topK,
129
+ includeSimilarity: true,
130
+ projection: {
131
+ $vector: includeVector ? true : false
132
+ }
133
+ });
134
+ const results = await cursor.toArray();
135
+ return results.map((result) => ({
136
+ id: result.id,
137
+ score: result.$similarity,
138
+ metadata: result.metadata,
139
+ ...includeVector && { vector: result.$vector }
140
+ }));
141
+ }
142
+ /**
143
+ * Lists all collections in the database.
144
+ *
145
+ * @returns {Promise<string[]>} A promise that resolves to an array of collection names.
146
+ */
147
+ listIndexes() {
148
+ return __privateGet(this, _db).listCollections({ nameOnly: true });
149
+ }
150
+ async describeIndex(indexName) {
151
+ const collection = __privateGet(this, _db).collection(indexName);
152
+ const optionsPromise = collection.options();
153
+ const countPromise = collection.countDocuments({}, 100);
154
+ const [options, count] = await Promise.all([optionsPromise, countPromise]);
155
+ console.log(options, count);
156
+ const keys = Object.keys(metricMap);
157
+ const metric = keys.find((key) => metricMap[key] === options.vector?.metric);
158
+ return {
159
+ dimension: options.vector?.dimension,
160
+ metric,
161
+ count
162
+ };
163
+ }
164
+ /**
165
+ * Deletes the specified collection.
166
+ *
167
+ * @param {string} indexName - The name of the collection to delete.
168
+ * @returns {Promise<void>} A promise that resolves when the collection is deleted.
169
+ */
170
+ async deleteIndex(indexName) {
171
+ const collection = __privateGet(this, _db).collection(indexName);
172
+ await collection.drop();
173
+ }
174
+ };
175
+ _db = new WeakMap();
176
+
177
+ export { AstraVector };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@mastra/astra",
3
+ "version": "0.1.0-alpha.28",
4
+ "description": "Astra DB provider for Mastra - includes vector store capabilities",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "dependencies": {
18
+ "@datastax/astra-db-ts": "^1.5.0",
19
+ "@mastra/core": "^0.2.0-alpha.93"
20
+ },
21
+ "devDependencies": {
22
+ "@tsconfig/recommended": "^1.0.7",
23
+ "@types/node": "^22.9.0",
24
+ "tsup": "^8.0.1",
25
+ "vitest": "^3.0.4"
26
+ },
27
+ "scripts": {
28
+ "build": "tsup-node src/index.ts --format esm --dts --clean --treeshake",
29
+ "dev": "tsup-node src/index.ts --format esm --dts --clean --treeshake --watch",
30
+ "test": "vitest run"
31
+ }
32
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './vector';