@mastra/vectorize 0.10.2-alpha.1 → 0.10.3-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/dist/index.cjs +198 -72
- package/dist/index.js +193 -67
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var error = require('@mastra/core/error');
|
|
3
4
|
var vector = require('@mastra/core/vector');
|
|
4
5
|
var Cloudflare = require('cloudflare');
|
|
5
6
|
var filter = require('@mastra/core/vector/filter');
|
|
@@ -86,17 +87,29 @@ var CloudflareVector = class extends vector.MastraVector {
|
|
|
86
87
|
metadata: metadata?.[index]
|
|
87
88
|
})
|
|
88
89
|
).join("\n");
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
90
|
+
try {
|
|
91
|
+
await this.client.vectorize.indexes.upsert(
|
|
92
|
+
indexName,
|
|
93
|
+
{
|
|
94
|
+
account_id: this.accountId,
|
|
95
|
+
body: ndjson
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
__binaryRequest: true
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
return generatedIds;
|
|
102
|
+
} catch (error$1) {
|
|
103
|
+
throw new error.MastraError(
|
|
104
|
+
{
|
|
105
|
+
id: "STORAGE_VECTORIZE_VECTOR_UPSERT_FAILED",
|
|
106
|
+
domain: error.ErrorDomain.STORAGE,
|
|
107
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
108
|
+
details: { indexName, vectorCount: vectors?.length }
|
|
109
|
+
},
|
|
110
|
+
error$1
|
|
111
|
+
);
|
|
112
|
+
}
|
|
100
113
|
}
|
|
101
114
|
transformFilter(filter) {
|
|
102
115
|
const translator = new VectorizeFilterTranslator();
|
|
@@ -112,13 +125,21 @@ var CloudflareVector = class extends vector.MastraVector {
|
|
|
112
125
|
},
|
|
113
126
|
name: indexName
|
|
114
127
|
});
|
|
115
|
-
} catch (error) {
|
|
116
|
-
const message = error?.errors?.[0]?.message || error?.message;
|
|
117
|
-
if (error.status === 409 || typeof message === "string" && (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("duplicate"))) {
|
|
128
|
+
} catch (error$1) {
|
|
129
|
+
const message = error$1?.errors?.[0]?.message || error$1?.message;
|
|
130
|
+
if (error$1.status === 409 || typeof message === "string" && (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("duplicate"))) {
|
|
118
131
|
await this.validateExistingIndex(indexName, dimension, metric);
|
|
119
132
|
return;
|
|
120
133
|
}
|
|
121
|
-
throw error
|
|
134
|
+
throw new error.MastraError(
|
|
135
|
+
{
|
|
136
|
+
id: "STORAGE_VECTORIZE_VECTOR_CREATE_INDEX_FAILED",
|
|
137
|
+
domain: error.ErrorDomain.STORAGE,
|
|
138
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
139
|
+
details: { indexName, dimension, metric }
|
|
140
|
+
},
|
|
141
|
+
error$1
|
|
142
|
+
);
|
|
122
143
|
}
|
|
123
144
|
}
|
|
124
145
|
async query({
|
|
@@ -128,29 +149,52 @@ var CloudflareVector = class extends vector.MastraVector {
|
|
|
128
149
|
filter,
|
|
129
150
|
includeVector = false
|
|
130
151
|
}) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
try {
|
|
153
|
+
const translatedFilter = this.transformFilter(filter) ?? {};
|
|
154
|
+
const response = await this.client.vectorize.indexes.query(indexName, {
|
|
155
|
+
account_id: this.accountId,
|
|
156
|
+
vector: queryVector,
|
|
157
|
+
returnValues: includeVector,
|
|
158
|
+
returnMetadata: "all",
|
|
159
|
+
topK,
|
|
160
|
+
filter: translatedFilter
|
|
161
|
+
});
|
|
162
|
+
return response?.matches?.map((match) => {
|
|
163
|
+
return {
|
|
164
|
+
id: match.id,
|
|
165
|
+
metadata: match.metadata,
|
|
166
|
+
score: match.score,
|
|
167
|
+
vector: match.values
|
|
168
|
+
};
|
|
169
|
+
}) || [];
|
|
170
|
+
} catch (error$1) {
|
|
171
|
+
throw new error.MastraError(
|
|
172
|
+
{
|
|
173
|
+
id: "STORAGE_VECTORIZE_VECTOR_QUERY_FAILED",
|
|
174
|
+
domain: error.ErrorDomain.STORAGE,
|
|
175
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
176
|
+
details: { indexName, topK }
|
|
177
|
+
},
|
|
178
|
+
error$1
|
|
179
|
+
);
|
|
180
|
+
}
|
|
148
181
|
}
|
|
149
182
|
async listIndexes() {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
183
|
+
try {
|
|
184
|
+
const res = await this.client.vectorize.indexes.list({
|
|
185
|
+
account_id: this.accountId
|
|
186
|
+
});
|
|
187
|
+
return res?.result?.map((index) => index.name) || [];
|
|
188
|
+
} catch (error$1) {
|
|
189
|
+
throw new error.MastraError(
|
|
190
|
+
{
|
|
191
|
+
id: "STORAGE_VECTORIZE_VECTOR_LIST_INDEXES_FAILED",
|
|
192
|
+
domain: error.ErrorDomain.STORAGE,
|
|
193
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
194
|
+
},
|
|
195
|
+
error$1
|
|
196
|
+
);
|
|
197
|
+
}
|
|
154
198
|
}
|
|
155
199
|
/**
|
|
156
200
|
* Retrieves statistics about a vector index.
|
|
@@ -159,43 +203,103 @@ var CloudflareVector = class extends vector.MastraVector {
|
|
|
159
203
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
160
204
|
*/
|
|
161
205
|
async describeIndex({ indexName }) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
206
|
+
try {
|
|
207
|
+
const index = await this.client.vectorize.indexes.get(indexName, {
|
|
208
|
+
account_id: this.accountId
|
|
209
|
+
});
|
|
210
|
+
const described = await this.client.vectorize.indexes.info(indexName, {
|
|
211
|
+
account_id: this.accountId
|
|
212
|
+
});
|
|
213
|
+
return {
|
|
214
|
+
dimension: described?.dimensions,
|
|
215
|
+
// Since vector_count is not available in the response,
|
|
216
|
+
// we might need a separate API call to get the count if needed
|
|
217
|
+
count: described?.vectorCount || 0,
|
|
218
|
+
metric: index?.config?.metric
|
|
219
|
+
};
|
|
220
|
+
} catch (error$1) {
|
|
221
|
+
throw new error.MastraError(
|
|
222
|
+
{
|
|
223
|
+
id: "STORAGE_VECTORIZE_VECTOR_DESCRIBE_INDEX_FAILED",
|
|
224
|
+
domain: error.ErrorDomain.STORAGE,
|
|
225
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
226
|
+
details: { indexName }
|
|
227
|
+
},
|
|
228
|
+
error$1
|
|
229
|
+
);
|
|
230
|
+
}
|
|
175
231
|
}
|
|
176
232
|
async deleteIndex({ indexName }) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
233
|
+
try {
|
|
234
|
+
await this.client.vectorize.indexes.delete(indexName, {
|
|
235
|
+
account_id: this.accountId
|
|
236
|
+
});
|
|
237
|
+
} catch (error$1) {
|
|
238
|
+
throw new error.MastraError(
|
|
239
|
+
{
|
|
240
|
+
id: "STORAGE_VECTORIZE_VECTOR_DELETE_INDEX_FAILED",
|
|
241
|
+
domain: error.ErrorDomain.STORAGE,
|
|
242
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
243
|
+
details: { indexName }
|
|
244
|
+
},
|
|
245
|
+
error$1
|
|
246
|
+
);
|
|
247
|
+
}
|
|
180
248
|
}
|
|
181
249
|
async createMetadataIndex(indexName, propertyName, indexType) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
250
|
+
try {
|
|
251
|
+
await this.client.vectorize.indexes.metadataIndex.create(indexName, {
|
|
252
|
+
account_id: this.accountId,
|
|
253
|
+
propertyName,
|
|
254
|
+
indexType
|
|
255
|
+
});
|
|
256
|
+
} catch (error$1) {
|
|
257
|
+
throw new error.MastraError(
|
|
258
|
+
{
|
|
259
|
+
id: "STORAGE_VECTORIZE_VECTOR_CREATE_METADATA_INDEX_FAILED",
|
|
260
|
+
domain: error.ErrorDomain.STORAGE,
|
|
261
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
262
|
+
details: { indexName, propertyName, indexType }
|
|
263
|
+
},
|
|
264
|
+
error$1
|
|
265
|
+
);
|
|
266
|
+
}
|
|
187
267
|
}
|
|
188
268
|
async deleteMetadataIndex(indexName, propertyName) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
269
|
+
try {
|
|
270
|
+
await this.client.vectorize.indexes.metadataIndex.delete(indexName, {
|
|
271
|
+
account_id: this.accountId,
|
|
272
|
+
propertyName
|
|
273
|
+
});
|
|
274
|
+
} catch (error$1) {
|
|
275
|
+
throw new error.MastraError(
|
|
276
|
+
{
|
|
277
|
+
id: "STORAGE_VECTORIZE_VECTOR_DELETE_METADATA_INDEX_FAILED",
|
|
278
|
+
domain: error.ErrorDomain.STORAGE,
|
|
279
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
280
|
+
details: { indexName, propertyName }
|
|
281
|
+
},
|
|
282
|
+
error$1
|
|
283
|
+
);
|
|
284
|
+
}
|
|
193
285
|
}
|
|
194
286
|
async listMetadataIndexes(indexName) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
287
|
+
try {
|
|
288
|
+
const res = await this.client.vectorize.indexes.metadataIndex.list(indexName, {
|
|
289
|
+
account_id: this.accountId
|
|
290
|
+
});
|
|
291
|
+
return res?.metadataIndexes ?? [];
|
|
292
|
+
} catch (error$1) {
|
|
293
|
+
throw new error.MastraError(
|
|
294
|
+
{
|
|
295
|
+
id: "STORAGE_VECTORIZE_VECTOR_LIST_METADATA_INDEXES_FAILED",
|
|
296
|
+
domain: error.ErrorDomain.STORAGE,
|
|
297
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
298
|
+
details: { indexName }
|
|
299
|
+
},
|
|
300
|
+
error$1
|
|
301
|
+
);
|
|
302
|
+
}
|
|
199
303
|
}
|
|
200
304
|
/**
|
|
201
305
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
@@ -208,10 +312,16 @@ var CloudflareVector = class extends vector.MastraVector {
|
|
|
208
312
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
209
313
|
*/
|
|
210
314
|
async updateVector({ indexName, id, update }) {
|
|
315
|
+
if (!update.vector && !update.metadata) {
|
|
316
|
+
throw new error.MastraError({
|
|
317
|
+
id: "STORAGE_VECTORIZE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
318
|
+
domain: error.ErrorDomain.STORAGE,
|
|
319
|
+
category: error.ErrorCategory.USER,
|
|
320
|
+
text: "No update data provided",
|
|
321
|
+
details: { indexName, id }
|
|
322
|
+
});
|
|
323
|
+
}
|
|
211
324
|
try {
|
|
212
|
-
if (!update.vector && !update.metadata) {
|
|
213
|
-
throw new Error("No update data provided");
|
|
214
|
-
}
|
|
215
325
|
const updatePayload = {
|
|
216
326
|
};
|
|
217
327
|
if (update.vector) {
|
|
@@ -221,8 +331,16 @@ var CloudflareVector = class extends vector.MastraVector {
|
|
|
221
331
|
updatePayload.metadata = [update.metadata];
|
|
222
332
|
}
|
|
223
333
|
await this.upsert({ indexName, vectors: updatePayload.vectors, metadata: updatePayload.metadata });
|
|
224
|
-
} catch (error) {
|
|
225
|
-
throw new
|
|
334
|
+
} catch (error$1) {
|
|
335
|
+
throw new error.MastraError(
|
|
336
|
+
{
|
|
337
|
+
id: "STORAGE_VECTORIZE_VECTOR_UPDATE_VECTOR_FAILED",
|
|
338
|
+
domain: error.ErrorDomain.STORAGE,
|
|
339
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
340
|
+
details: { indexName, id }
|
|
341
|
+
},
|
|
342
|
+
error$1
|
|
343
|
+
);
|
|
226
344
|
}
|
|
227
345
|
}
|
|
228
346
|
/**
|
|
@@ -238,8 +356,16 @@ var CloudflareVector = class extends vector.MastraVector {
|
|
|
238
356
|
ids: [id],
|
|
239
357
|
account_id: this.accountId
|
|
240
358
|
});
|
|
241
|
-
} catch (error) {
|
|
242
|
-
throw new
|
|
359
|
+
} catch (error$1) {
|
|
360
|
+
throw new error.MastraError(
|
|
361
|
+
{
|
|
362
|
+
id: "STORAGE_VECTORIZE_VECTOR_DELETE_VECTOR_FAILED",
|
|
363
|
+
domain: error.ErrorDomain.STORAGE,
|
|
364
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
365
|
+
details: { indexName, id }
|
|
366
|
+
},
|
|
367
|
+
error$1
|
|
368
|
+
);
|
|
243
369
|
}
|
|
244
370
|
}
|
|
245
371
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
1
2
|
import { MastraVector } from '@mastra/core/vector';
|
|
2
3
|
import Cloudflare from 'cloudflare';
|
|
3
4
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
@@ -80,17 +81,29 @@ var CloudflareVector = class extends MastraVector {
|
|
|
80
81
|
metadata: metadata?.[index]
|
|
81
82
|
})
|
|
82
83
|
).join("\n");
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
try {
|
|
85
|
+
await this.client.vectorize.indexes.upsert(
|
|
86
|
+
indexName,
|
|
87
|
+
{
|
|
88
|
+
account_id: this.accountId,
|
|
89
|
+
body: ndjson
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
__binaryRequest: true
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
return generatedIds;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
throw new MastraError(
|
|
98
|
+
{
|
|
99
|
+
id: "STORAGE_VECTORIZE_VECTOR_UPSERT_FAILED",
|
|
100
|
+
domain: ErrorDomain.STORAGE,
|
|
101
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
102
|
+
details: { indexName, vectorCount: vectors?.length }
|
|
103
|
+
},
|
|
104
|
+
error
|
|
105
|
+
);
|
|
106
|
+
}
|
|
94
107
|
}
|
|
95
108
|
transformFilter(filter) {
|
|
96
109
|
const translator = new VectorizeFilterTranslator();
|
|
@@ -112,7 +125,15 @@ var CloudflareVector = class extends MastraVector {
|
|
|
112
125
|
await this.validateExistingIndex(indexName, dimension, metric);
|
|
113
126
|
return;
|
|
114
127
|
}
|
|
115
|
-
throw
|
|
128
|
+
throw new MastraError(
|
|
129
|
+
{
|
|
130
|
+
id: "STORAGE_VECTORIZE_VECTOR_CREATE_INDEX_FAILED",
|
|
131
|
+
domain: ErrorDomain.STORAGE,
|
|
132
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
133
|
+
details: { indexName, dimension, metric }
|
|
134
|
+
},
|
|
135
|
+
error
|
|
136
|
+
);
|
|
116
137
|
}
|
|
117
138
|
}
|
|
118
139
|
async query({
|
|
@@ -122,29 +143,52 @@ var CloudflareVector = class extends MastraVector {
|
|
|
122
143
|
filter,
|
|
123
144
|
includeVector = false
|
|
124
145
|
}) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
146
|
+
try {
|
|
147
|
+
const translatedFilter = this.transformFilter(filter) ?? {};
|
|
148
|
+
const response = await this.client.vectorize.indexes.query(indexName, {
|
|
149
|
+
account_id: this.accountId,
|
|
150
|
+
vector: queryVector,
|
|
151
|
+
returnValues: includeVector,
|
|
152
|
+
returnMetadata: "all",
|
|
153
|
+
topK,
|
|
154
|
+
filter: translatedFilter
|
|
155
|
+
});
|
|
156
|
+
return response?.matches?.map((match) => {
|
|
157
|
+
return {
|
|
158
|
+
id: match.id,
|
|
159
|
+
metadata: match.metadata,
|
|
160
|
+
score: match.score,
|
|
161
|
+
vector: match.values
|
|
162
|
+
};
|
|
163
|
+
}) || [];
|
|
164
|
+
} catch (error) {
|
|
165
|
+
throw new MastraError(
|
|
166
|
+
{
|
|
167
|
+
id: "STORAGE_VECTORIZE_VECTOR_QUERY_FAILED",
|
|
168
|
+
domain: ErrorDomain.STORAGE,
|
|
169
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
170
|
+
details: { indexName, topK }
|
|
171
|
+
},
|
|
172
|
+
error
|
|
173
|
+
);
|
|
174
|
+
}
|
|
142
175
|
}
|
|
143
176
|
async listIndexes() {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
177
|
+
try {
|
|
178
|
+
const res = await this.client.vectorize.indexes.list({
|
|
179
|
+
account_id: this.accountId
|
|
180
|
+
});
|
|
181
|
+
return res?.result?.map((index) => index.name) || [];
|
|
182
|
+
} catch (error) {
|
|
183
|
+
throw new MastraError(
|
|
184
|
+
{
|
|
185
|
+
id: "STORAGE_VECTORIZE_VECTOR_LIST_INDEXES_FAILED",
|
|
186
|
+
domain: ErrorDomain.STORAGE,
|
|
187
|
+
category: ErrorCategory.THIRD_PARTY
|
|
188
|
+
},
|
|
189
|
+
error
|
|
190
|
+
);
|
|
191
|
+
}
|
|
148
192
|
}
|
|
149
193
|
/**
|
|
150
194
|
* Retrieves statistics about a vector index.
|
|
@@ -153,43 +197,103 @@ var CloudflareVector = class extends MastraVector {
|
|
|
153
197
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
154
198
|
*/
|
|
155
199
|
async describeIndex({ indexName }) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
200
|
+
try {
|
|
201
|
+
const index = await this.client.vectorize.indexes.get(indexName, {
|
|
202
|
+
account_id: this.accountId
|
|
203
|
+
});
|
|
204
|
+
const described = await this.client.vectorize.indexes.info(indexName, {
|
|
205
|
+
account_id: this.accountId
|
|
206
|
+
});
|
|
207
|
+
return {
|
|
208
|
+
dimension: described?.dimensions,
|
|
209
|
+
// Since vector_count is not available in the response,
|
|
210
|
+
// we might need a separate API call to get the count if needed
|
|
211
|
+
count: described?.vectorCount || 0,
|
|
212
|
+
metric: index?.config?.metric
|
|
213
|
+
};
|
|
214
|
+
} catch (error) {
|
|
215
|
+
throw new MastraError(
|
|
216
|
+
{
|
|
217
|
+
id: "STORAGE_VECTORIZE_VECTOR_DESCRIBE_INDEX_FAILED",
|
|
218
|
+
domain: ErrorDomain.STORAGE,
|
|
219
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
220
|
+
details: { indexName }
|
|
221
|
+
},
|
|
222
|
+
error
|
|
223
|
+
);
|
|
224
|
+
}
|
|
169
225
|
}
|
|
170
226
|
async deleteIndex({ indexName }) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
227
|
+
try {
|
|
228
|
+
await this.client.vectorize.indexes.delete(indexName, {
|
|
229
|
+
account_id: this.accountId
|
|
230
|
+
});
|
|
231
|
+
} catch (error) {
|
|
232
|
+
throw new MastraError(
|
|
233
|
+
{
|
|
234
|
+
id: "STORAGE_VECTORIZE_VECTOR_DELETE_INDEX_FAILED",
|
|
235
|
+
domain: ErrorDomain.STORAGE,
|
|
236
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
237
|
+
details: { indexName }
|
|
238
|
+
},
|
|
239
|
+
error
|
|
240
|
+
);
|
|
241
|
+
}
|
|
174
242
|
}
|
|
175
243
|
async createMetadataIndex(indexName, propertyName, indexType) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
244
|
+
try {
|
|
245
|
+
await this.client.vectorize.indexes.metadataIndex.create(indexName, {
|
|
246
|
+
account_id: this.accountId,
|
|
247
|
+
propertyName,
|
|
248
|
+
indexType
|
|
249
|
+
});
|
|
250
|
+
} catch (error) {
|
|
251
|
+
throw new MastraError(
|
|
252
|
+
{
|
|
253
|
+
id: "STORAGE_VECTORIZE_VECTOR_CREATE_METADATA_INDEX_FAILED",
|
|
254
|
+
domain: ErrorDomain.STORAGE,
|
|
255
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
256
|
+
details: { indexName, propertyName, indexType }
|
|
257
|
+
},
|
|
258
|
+
error
|
|
259
|
+
);
|
|
260
|
+
}
|
|
181
261
|
}
|
|
182
262
|
async deleteMetadataIndex(indexName, propertyName) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
263
|
+
try {
|
|
264
|
+
await this.client.vectorize.indexes.metadataIndex.delete(indexName, {
|
|
265
|
+
account_id: this.accountId,
|
|
266
|
+
propertyName
|
|
267
|
+
});
|
|
268
|
+
} catch (error) {
|
|
269
|
+
throw new MastraError(
|
|
270
|
+
{
|
|
271
|
+
id: "STORAGE_VECTORIZE_VECTOR_DELETE_METADATA_INDEX_FAILED",
|
|
272
|
+
domain: ErrorDomain.STORAGE,
|
|
273
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
274
|
+
details: { indexName, propertyName }
|
|
275
|
+
},
|
|
276
|
+
error
|
|
277
|
+
);
|
|
278
|
+
}
|
|
187
279
|
}
|
|
188
280
|
async listMetadataIndexes(indexName) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
281
|
+
try {
|
|
282
|
+
const res = await this.client.vectorize.indexes.metadataIndex.list(indexName, {
|
|
283
|
+
account_id: this.accountId
|
|
284
|
+
});
|
|
285
|
+
return res?.metadataIndexes ?? [];
|
|
286
|
+
} catch (error) {
|
|
287
|
+
throw new MastraError(
|
|
288
|
+
{
|
|
289
|
+
id: "STORAGE_VECTORIZE_VECTOR_LIST_METADATA_INDEXES_FAILED",
|
|
290
|
+
domain: ErrorDomain.STORAGE,
|
|
291
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
292
|
+
details: { indexName }
|
|
293
|
+
},
|
|
294
|
+
error
|
|
295
|
+
);
|
|
296
|
+
}
|
|
193
297
|
}
|
|
194
298
|
/**
|
|
195
299
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
@@ -202,10 +306,16 @@ var CloudflareVector = class extends MastraVector {
|
|
|
202
306
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
203
307
|
*/
|
|
204
308
|
async updateVector({ indexName, id, update }) {
|
|
309
|
+
if (!update.vector && !update.metadata) {
|
|
310
|
+
throw new MastraError({
|
|
311
|
+
id: "STORAGE_VECTORIZE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
312
|
+
domain: ErrorDomain.STORAGE,
|
|
313
|
+
category: ErrorCategory.USER,
|
|
314
|
+
text: "No update data provided",
|
|
315
|
+
details: { indexName, id }
|
|
316
|
+
});
|
|
317
|
+
}
|
|
205
318
|
try {
|
|
206
|
-
if (!update.vector && !update.metadata) {
|
|
207
|
-
throw new Error("No update data provided");
|
|
208
|
-
}
|
|
209
319
|
const updatePayload = {
|
|
210
320
|
};
|
|
211
321
|
if (update.vector) {
|
|
@@ -216,7 +326,15 @@ var CloudflareVector = class extends MastraVector {
|
|
|
216
326
|
}
|
|
217
327
|
await this.upsert({ indexName, vectors: updatePayload.vectors, metadata: updatePayload.metadata });
|
|
218
328
|
} catch (error) {
|
|
219
|
-
throw new
|
|
329
|
+
throw new MastraError(
|
|
330
|
+
{
|
|
331
|
+
id: "STORAGE_VECTORIZE_VECTOR_UPDATE_VECTOR_FAILED",
|
|
332
|
+
domain: ErrorDomain.STORAGE,
|
|
333
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
334
|
+
details: { indexName, id }
|
|
335
|
+
},
|
|
336
|
+
error
|
|
337
|
+
);
|
|
220
338
|
}
|
|
221
339
|
}
|
|
222
340
|
/**
|
|
@@ -233,7 +351,15 @@ var CloudflareVector = class extends MastraVector {
|
|
|
233
351
|
account_id: this.accountId
|
|
234
352
|
});
|
|
235
353
|
} catch (error) {
|
|
236
|
-
throw new
|
|
354
|
+
throw new MastraError(
|
|
355
|
+
{
|
|
356
|
+
id: "STORAGE_VECTORIZE_VECTOR_DELETE_VECTOR_FAILED",
|
|
357
|
+
domain: ErrorDomain.STORAGE,
|
|
358
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
359
|
+
details: { indexName, id }
|
|
360
|
+
},
|
|
361
|
+
error
|
|
362
|
+
);
|
|
237
363
|
}
|
|
238
364
|
}
|
|
239
365
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/vectorize",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3-alpha.0",
|
|
4
4
|
"description": "Cloudflare Vectorize store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@microsoft/api-extractor": "^7.52.8",
|
|
30
|
-
"@types/node": "^20.
|
|
30
|
+
"@types/node": "^20.19.0",
|
|
31
31
|
"dotenv": "^16.5.0",
|
|
32
32
|
"eslint": "^9.28.0",
|
|
33
33
|
"tsup": "^8.5.0",
|
|
34
|
-
"typescript": "^5.8.
|
|
35
|
-
"vitest": "^3.2.
|
|
36
|
-
"@internal/lint": "0.0.
|
|
37
|
-
"@mastra/core": "0.10.
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"vitest": "^3.2.3",
|
|
36
|
+
"@internal/lint": "0.0.13",
|
|
37
|
+
"@mastra/core": "0.10.7-alpha.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@mastra/core": ">=0.10.4-0 <0.11.0"
|