@mastra/vectorize 0.1.0-alpha.29

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,262 @@
1
+ # @mastra/vectorize
2
+
3
+ ## 0.1.0-alpha.29
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [5285356]
8
+ - @mastra/core@0.2.0-alpha.93
9
+
10
+ ## 0.1.0-alpha.28
11
+
12
+ ### Minor Changes
13
+
14
+ - 91c81f5: Move @mastra/vector-vectorize to @mastra/vectorize
15
+
16
+ BREAKING CHANGE: The package @mastra/vector-vectorize has been moved to @mastra/vectorize. The old package is now deprecated and will display a warning message. Please update your imports from '@mastra/vector-vectorize' to '@mastra/vectorize'.
17
+
18
+ ## 0.1.0-alpha.28
19
+
20
+ ### Major Changes
21
+
22
+ - Package renamed from @mastra/vector-vectorize to @mastra/vectorize
23
+ - Moved package from vector-stores directory to stores directory
24
+ - Restructured source files under src/vector/
25
+
26
+ ## Previous Changes (as @mastra/vector-vectorize)
27
+
28
+ ### 0.1.0-alpha.21 - 0.1.0-alpha.27
29
+
30
+ - Implemented new filtering for vectorQueryTool
31
+ - Updated operator validation and handling
32
+ - Added Filter Translator to Vectorize
33
+ - Started implementation of Unified Filter API
34
+ - Updated dependencies to use ^ version ranges
35
+ - Multiple dependency updates and improvements
36
+
37
+ ### 0.0.1-alpha.1 - 0.0.1-alpha.20
38
+
39
+ - Initial implementation of vector store modules
40
+ - Added basic filtering capabilities
41
+ - Implemented bundle optimization with tsup
42
+ - Various bug fixes and improvements
43
+
44
+ ## 0.1.0-alpha.27
45
+
46
+ ### Patch Changes
47
+
48
+ - Updated dependencies [4d4f6b6]
49
+ - @mastra/core@0.2.0-alpha.92
50
+
51
+ ## 0.1.0-alpha.26
52
+
53
+ ### Patch Changes
54
+
55
+ - a10b7a3: Implemented new filtering for vectorQueryTool and updated docs
56
+ - Updated dependencies [d7d465a]
57
+ - Updated dependencies [d7d465a]
58
+ - Updated dependencies [2017553]
59
+ - Updated dependencies [a10b7a3]
60
+ - Updated dependencies [16e5b04]
61
+ - @mastra/core@0.2.0-alpha.91
62
+
63
+ ## 0.1.0-alpha.25
64
+
65
+ ### Patch Changes
66
+
67
+ - Updated dependencies [8151f44]
68
+ - Updated dependencies [e897f1c]
69
+ - Updated dependencies [3700be1]
70
+ - @mastra/core@0.2.0-alpha.90
71
+
72
+ ## 0.1.0-alpha.24
73
+
74
+ ### Patch Changes
75
+
76
+ - Updated dependencies [27275c9]
77
+ - @mastra/core@0.2.0-alpha.89
78
+
79
+ ## 0.1.0-alpha.23
80
+
81
+ ### Patch Changes
82
+
83
+ - ccbc581: Updated operator validation and handling for all vector stores
84
+ - Updated dependencies [ccbc581]
85
+ - @mastra/core@0.2.0-alpha.88
86
+
87
+ ## 0.1.0-alpha.22
88
+
89
+ ### Patch Changes
90
+
91
+ - Updated dependencies [7365b6c]
92
+ - @mastra/core@0.2.0-alpha.87
93
+
94
+ ## 0.1.0-alpha.21
95
+
96
+ ### Minor Changes
97
+
98
+ - 5916f9d: Update deps from fixed to ^
99
+
100
+ ### Patch Changes
101
+
102
+ - 7f24c29: Add Chroma Filter translator and updated vector store tests
103
+ - Updated dependencies [6fa4bd2]
104
+ - Updated dependencies [e2e76de]
105
+ - Updated dependencies [7f24c29]
106
+ - Updated dependencies [67637ba]
107
+ - Updated dependencies [04f3171]
108
+ - @mastra/core@0.2.0-alpha.86
109
+
110
+ ## 0.0.1-alpha.20
111
+
112
+ ### Patch Changes
113
+
114
+ - Updated dependencies [e9d1b47]
115
+ - @mastra/core@0.2.0-alpha.85
116
+
117
+ ## 0.0.1-alpha.19
118
+
119
+ ### Patch Changes
120
+
121
+ - Updated dependencies [2f17a5f]
122
+ - Updated dependencies [cb290ee]
123
+ - Updated dependencies [b4d7416]
124
+ - Updated dependencies [38b7f66]
125
+ - @mastra/core@0.2.0-alpha.84
126
+
127
+ ## 0.0.1-alpha.18
128
+
129
+ ### Patch Changes
130
+
131
+ - bd8b0db: Added Filter Translator to Vectorize
132
+
133
+ ## 0.0.1-alpha.17
134
+
135
+ ### Patch Changes
136
+
137
+ - 78eec7c: Started implementation on Unified Filter API for several vector stores.
138
+ - 9625602: Use mastra core splitted bundles in other packages
139
+ - Updated dependencies [30322ce]
140
+ - Updated dependencies [78eec7c]
141
+ - Updated dependencies [9625602]
142
+ - Updated dependencies [8769a62]
143
+ - @mastra/core@0.2.0-alpha.83
144
+
145
+ ## 0.0.1-alpha.16
146
+
147
+ ### Patch Changes
148
+
149
+ - Updated dependencies [73d112c]
150
+ - @mastra/core@0.1.27-alpha.82
151
+
152
+ ## 0.0.1-alpha.15
153
+
154
+ ### Patch Changes
155
+
156
+ - Updated dependencies [9fb3039]
157
+ - @mastra/core@0.1.27-alpha.81
158
+
159
+ ## 0.0.1-alpha.14
160
+
161
+ ### Patch Changes
162
+
163
+ - b422ed3: Bundle vector provider packages with tsup
164
+
165
+ ## 0.0.1-alpha.13
166
+
167
+ ### Patch Changes
168
+
169
+ - Updated dependencies [327ece7]
170
+ - @mastra/core@0.1.27-alpha.80
171
+
172
+ ## 0.0.1-alpha.12
173
+
174
+ ### Patch Changes
175
+
176
+ - Updated dependencies [21fe536]
177
+ - @mastra/core@0.1.27-alpha.79
178
+
179
+ ## 0.0.1-alpha.11
180
+
181
+ ### Patch Changes
182
+
183
+ - Updated dependencies [685108a]
184
+ - Updated dependencies [685108a]
185
+ - @mastra/core@0.1.27-alpha.78
186
+
187
+ ## 0.0.1-alpha.10
188
+
189
+ ### Patch Changes
190
+
191
+ - Updated dependencies [8105fae]
192
+ - @mastra/core@0.1.27-alpha.77
193
+
194
+ ## 0.0.1-alpha.9
195
+
196
+ ### Patch Changes
197
+
198
+ - 7a469e7: Bump vectors
199
+
200
+ ## 0.0.1-alpha.8
201
+
202
+ ### Patch Changes
203
+
204
+ - Updated dependencies [ae7bf94]
205
+ - Updated dependencies [ae7bf94]
206
+ - @mastra/core@0.1.27-alpha.76
207
+
208
+ ## 0.0.1-alpha.7
209
+
210
+ ### Patch Changes
211
+
212
+ - Updated dependencies [23dcb23]
213
+ - @mastra/core@0.1.27-alpha.75
214
+
215
+ ## 0.0.1-alpha.6
216
+
217
+ ### Patch Changes
218
+
219
+ - Updated dependencies [7b87567]
220
+ - @mastra/core@0.1.27-alpha.74
221
+
222
+ ## 0.0.1-alpha.5
223
+
224
+ ### Patch Changes
225
+
226
+ - Updated dependencies [3427b95]
227
+ - @mastra/core@0.1.27-alpha.73
228
+
229
+ ## 0.0.1-alpha.4
230
+
231
+ ### Patch Changes
232
+
233
+ - Updated dependencies [e4d4ede]
234
+ - Updated dependencies [06b2c0a]
235
+ - @mastra/core@0.1.27-alpha.72
236
+
237
+ ## 0.0.1-alpha.3
238
+
239
+ ### Patch Changes
240
+
241
+ - Updated dependencies [d9c8dd0]
242
+ - @mastra/core@0.1.27-alpha.71
243
+
244
+ ## 0.0.1-alpha.2
245
+
246
+ ### Patch Changes
247
+
248
+ - bdaf834: publish packages
249
+
250
+ ## 0.0.1-alpha.1
251
+
252
+ ### Patch Changes
253
+
254
+ - Updated dependencies [dd6d87f]
255
+ - Updated dependencies [04434b6]
256
+ - @mastra/core@0.1.27-alpha.70
257
+
258
+ ## 0.0.1-alpha.0
259
+
260
+ ### Patch Changes
261
+
262
+ - 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,39 @@
1
+ # @mastra/vectorize
2
+
3
+ Vector store implementation for Vectorize, a managed vector database service optimized for AI applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/vectorize
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { VectorizeStore } from '@mastra/vectorize';
15
+
16
+ const vectorStore = new VectorizeStore({
17
+ // configuration options
18
+ });
19
+ ```
20
+
21
+ ## Configuration
22
+
23
+ The Vectorize vector store requires the following configuration:
24
+
25
+ - `VECTORIZE_API_KEY`: Your Vectorize API key
26
+ - `VECTORIZE_INDEX_NAME`: Name of the index to use
27
+ - `VECTORIZE_PROJECT_ID`: Your Vectorize project ID
28
+
29
+ ## Features
30
+
31
+ - Purpose-built for AI and ML workloads
32
+ - High-performance vector similarity search
33
+ - Automatic index optimization
34
+ - Scalable architecture
35
+ - Real-time updates and queries
36
+
37
+ ## Related Links
38
+
39
+ - [Vectorize Documentation](https://www.vectorize.com/docs)
@@ -0,0 +1,28 @@
1
+ import { Filter } from '@mastra/core/filter';
2
+ import { MastraVector, QueryResult } from '@mastra/core/vector';
3
+ import Cloudflare from 'cloudflare';
4
+
5
+ declare class CloudflareVector extends MastraVector {
6
+ client: Cloudflare;
7
+ accountId: string;
8
+ constructor({ accountId, apiToken }: {
9
+ accountId: string;
10
+ apiToken: string;
11
+ });
12
+ upsert(indexName: string, vectors: number[][], metadata?: Record<string, any>[], ids?: string[]): Promise<string[]>;
13
+ transformFilter(filter?: Filter): Filter | undefined;
14
+ createIndex(indexName: string, dimension: number, metric?: 'cosine' | 'euclidean' | 'dotproduct'): Promise<void>;
15
+ query(indexName: string, queryVector: number[], topK?: number, filter?: Filter, includeVector?: boolean): Promise<QueryResult[]>;
16
+ listIndexes(): Promise<string[]>;
17
+ describeIndex(indexName: string): Promise<{
18
+ dimension: number;
19
+ count: number;
20
+ metric: "cosine" | "euclidean" | "dotproduct";
21
+ }>;
22
+ deleteIndex(indexName: string): Promise<void>;
23
+ createMetadataIndex(indexName: string, propertyName: string, indexType: 'string' | 'number' | 'boolean'): Promise<void>;
24
+ deleteMetadataIndex(indexName: string, propertyName: string): Promise<void>;
25
+ listMetadataIndexes(indexName: string): Promise<Cloudflare.Vectorize.Indexes.MetadataIndex.MetadataIndexListResponse.MetadataIndex[]>;
26
+ }
27
+
28
+ export { CloudflareVector };
package/dist/index.js ADDED
@@ -0,0 +1,163 @@
1
+ import { MastraVector } from '@mastra/core/vector';
2
+ import Cloudflare from 'cloudflare';
3
+ import { BaseFilterTranslator } from '@mastra/core/filter';
4
+
5
+ // src/vector/index.ts
6
+ var VectorizeFilterTranslator = class extends BaseFilterTranslator {
7
+ getSupportedOperators() {
8
+ return {
9
+ ...BaseFilterTranslator.DEFAULT_OPERATORS,
10
+ logical: [],
11
+ array: ["$in", "$nin"],
12
+ element: [],
13
+ regex: [],
14
+ custom: []
15
+ };
16
+ }
17
+ translate(filter) {
18
+ if (this.isEmpty(filter)) return filter;
19
+ this.validateFilter(filter);
20
+ return this.translateNode(filter);
21
+ }
22
+ translateNode(node, currentPath = "") {
23
+ if (this.isRegex(node)) {
24
+ throw new Error("Regex is not supported in Vectorize");
25
+ }
26
+ if (this.isPrimitive(node)) return { $eq: this.normalizeComparisonValue(node) };
27
+ if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };
28
+ const entries = Object.entries(node);
29
+ const firstEntry = entries[0];
30
+ if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {
31
+ const [operator, value] = firstEntry;
32
+ return { [operator]: this.normalizeComparisonValue(value) };
33
+ }
34
+ const result = {};
35
+ for (const [key, value] of entries) {
36
+ const newPath = currentPath ? `${currentPath}.${key}` : key;
37
+ if (this.isOperator(key)) {
38
+ result[key] = this.normalizeComparisonValue(value);
39
+ continue;
40
+ }
41
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
42
+ if (Object.keys(value).length === 0) {
43
+ result[newPath] = this.translateNode(value);
44
+ continue;
45
+ }
46
+ const hasOperators = Object.keys(value).some((k) => this.isOperator(k));
47
+ if (hasOperators) {
48
+ result[newPath] = this.translateNode(value);
49
+ } else {
50
+ Object.assign(result, this.translateNode(value, newPath));
51
+ }
52
+ } else {
53
+ result[newPath] = this.translateNode(value);
54
+ }
55
+ }
56
+ return result;
57
+ }
58
+ };
59
+
60
+ // src/vector/index.ts
61
+ var CloudflareVector = class extends MastraVector {
62
+ constructor({ accountId, apiToken }) {
63
+ super();
64
+ this.accountId = accountId;
65
+ this.client = new Cloudflare({
66
+ apiKey: apiToken
67
+ });
68
+ }
69
+ async upsert(indexName, vectors, metadata, ids) {
70
+ const generatedIds = ids || vectors.map(() => crypto.randomUUID());
71
+ const ndjson = vectors.map((vector, index) => ({
72
+ id: generatedIds[index],
73
+ values: vector,
74
+ metadata: metadata?.[index]
75
+ })).map((record) => JSON.stringify(record)).join("\n");
76
+ await this.client.vectorize.indexes.upsert(indexName, {
77
+ account_id: this.accountId,
78
+ body: ndjson
79
+ });
80
+ return generatedIds;
81
+ }
82
+ transformFilter(filter) {
83
+ const translator = new VectorizeFilterTranslator();
84
+ const translatedFilter = translator.translate(filter);
85
+ return translatedFilter;
86
+ }
87
+ async createIndex(indexName, dimension, metric = "cosine") {
88
+ await this.client.vectorize.indexes.create({
89
+ account_id: this.accountId,
90
+ config: {
91
+ dimensions: dimension,
92
+ metric: metric === "dotproduct" ? "dot-product" : metric
93
+ },
94
+ name: indexName
95
+ });
96
+ }
97
+ async query(indexName, queryVector, topK = 10, filter, includeVector = false) {
98
+ const translatedFilter = this.transformFilter(filter);
99
+ const response = await this.client.vectorize.indexes.query(indexName, {
100
+ account_id: this.accountId,
101
+ vector: queryVector,
102
+ returnValues: includeVector,
103
+ returnMetadata: "all",
104
+ topK,
105
+ filter: translatedFilter
106
+ });
107
+ return response?.matches?.map((match) => {
108
+ return {
109
+ id: match.id,
110
+ metadata: match.metadata,
111
+ score: match.score,
112
+ vector: match.values
113
+ };
114
+ }) || [];
115
+ }
116
+ async listIndexes() {
117
+ const res = await this.client.vectorize.indexes.list({
118
+ account_id: this.accountId
119
+ });
120
+ return res?.result?.map((index) => index.name) || [];
121
+ }
122
+ async describeIndex(indexName) {
123
+ const index = await this.client.vectorize.indexes.get(indexName, {
124
+ account_id: this.accountId
125
+ });
126
+ const described = await this.client.vectorize.indexes.info(indexName, {
127
+ account_id: this.accountId
128
+ });
129
+ return {
130
+ dimension: described?.dimensions,
131
+ // Since vector_count is not available in the response,
132
+ // we might need a separate API call to get the count if needed
133
+ count: described?.vectorCount || 0,
134
+ metric: index?.config?.metric
135
+ };
136
+ }
137
+ async deleteIndex(indexName) {
138
+ await this.client.vectorize.indexes.delete(indexName, {
139
+ account_id: this.accountId
140
+ });
141
+ }
142
+ async createMetadataIndex(indexName, propertyName, indexType) {
143
+ await this.client.vectorize.indexes.metadataIndex.create(indexName, {
144
+ account_id: this.accountId,
145
+ propertyName,
146
+ indexType
147
+ });
148
+ }
149
+ async deleteMetadataIndex(indexName, propertyName) {
150
+ await this.client.vectorize.indexes.metadataIndex.delete(indexName, {
151
+ account_id: this.accountId,
152
+ propertyName
153
+ });
154
+ }
155
+ async listMetadataIndexes(indexName) {
156
+ const res = await this.client.vectorize.indexes.metadataIndex.list(indexName, {
157
+ account_id: this.accountId
158
+ });
159
+ return res?.metadataIndexes ?? [];
160
+ }
161
+ };
162
+
163
+ export { CloudflareVector };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@mastra/vectorize",
3
+ "version": "0.1.0-alpha.29",
4
+ "description": "Cloudflare Vectorize store provider for Mastra",
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
+ "cloudflare": "^4.0.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.5"
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';