@mastra/vectorize 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016

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.js CHANGED
@@ -1,371 +1,356 @@
1
- import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
2
- import { MastraVector } from '@mastra/core/vector';
3
- import Cloudflare from 'cloudflare';
4
- import { BaseFilterTranslator } from '@mastra/core/vector/filter';
5
-
6
- // src/vector/index.ts
1
+ import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
2
+ import { createVectorErrorId } from "@mastra/core/storage";
3
+ import { MastraVector } from "@mastra/core/vector";
4
+ import Cloudflare from "cloudflare";
5
+ import { BaseFilterTranslator } from "@mastra/core/vector/filter";
6
+ //#region src/vector/filter.ts
7
7
  var VectorizeFilterTranslator = class extends BaseFilterTranslator {
8
- getSupportedOperators() {
9
- return {
10
- ...BaseFilterTranslator.DEFAULT_OPERATORS,
11
- logical: [],
12
- array: ["$in", "$nin"],
13
- element: [],
14
- regex: [],
15
- custom: []
16
- };
17
- }
18
- translate(filter) {
19
- if (this.isEmpty(filter)) return filter;
20
- this.validateFilter(filter);
21
- return this.translateNode(filter);
22
- }
23
- translateNode(node, currentPath = "") {
24
- if (this.isRegex(node)) {
25
- throw new Error("Regex is not supported in Vectorize");
26
- }
27
- if (this.isPrimitive(node)) return { $eq: this.normalizeComparisonValue(node) };
28
- if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };
29
- const entries = Object.entries(node);
30
- const firstEntry = entries[0];
31
- if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {
32
- const [operator, value] = firstEntry;
33
- return { [operator]: this.normalizeComparisonValue(value) };
34
- }
35
- const result = {};
36
- for (const [key, value] of entries) {
37
- const newPath = currentPath ? `${currentPath}.${key}` : key;
38
- if (this.isOperator(key)) {
39
- result[key] = this.normalizeComparisonValue(value);
40
- continue;
41
- }
42
- if (typeof value === "object" && value !== null && !Array.isArray(value)) {
43
- if (Object.keys(value).length === 0) {
44
- result[newPath] = this.translateNode(value);
45
- continue;
46
- }
47
- const hasOperators = Object.keys(value).some((k) => this.isOperator(k));
48
- if (hasOperators) {
49
- result[newPath] = this.translateNode(value);
50
- } else {
51
- Object.assign(result, this.translateNode(value, newPath));
52
- }
53
- } else {
54
- result[newPath] = this.translateNode(value);
55
- }
56
- }
57
- return result;
58
- }
8
+ getSupportedOperators() {
9
+ return {
10
+ ...BaseFilterTranslator.DEFAULT_OPERATORS,
11
+ logical: [],
12
+ array: ["$in", "$nin"],
13
+ element: [],
14
+ regex: [],
15
+ custom: []
16
+ };
17
+ }
18
+ translate(filter) {
19
+ if (this.isEmpty(filter)) return filter;
20
+ this.validateFilter(filter);
21
+ return this.translateNode(filter);
22
+ }
23
+ translateNode(node, currentPath = "") {
24
+ if (this.isRegex(node)) throw new Error("Regex is not supported in Vectorize");
25
+ if (this.isPrimitive(node)) return { $eq: this.normalizeComparisonValue(node) };
26
+ if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };
27
+ const entries = Object.entries(node);
28
+ const firstEntry = entries[0];
29
+ if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {
30
+ const [operator, value] = firstEntry;
31
+ return { [operator]: this.normalizeComparisonValue(value) };
32
+ }
33
+ const result = {};
34
+ for (const [key, value] of entries) {
35
+ const newPath = currentPath ? `${currentPath}.${key}` : key;
36
+ if (this.isOperator(key)) {
37
+ result[key] = this.normalizeComparisonValue(value);
38
+ continue;
39
+ }
40
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
41
+ if (Object.keys(value).length === 0) {
42
+ result[newPath] = this.translateNode(value);
43
+ continue;
44
+ }
45
+ if (Object.keys(value).some((k) => this.isOperator(k))) result[newPath] = this.translateNode(value);
46
+ else Object.assign(result, this.translateNode(value, newPath));
47
+ } else result[newPath] = this.translateNode(value);
48
+ }
49
+ return result;
50
+ }
59
51
  };
60
-
61
- // src/vector/index.ts
52
+ //#endregion
53
+ //#region src/vector/index.ts
62
54
  var CloudflareVector = class extends MastraVector {
63
- client;
64
- accountId;
65
- constructor({ accountId, apiToken }) {
66
- super();
67
- this.accountId = accountId;
68
- this.client = new Cloudflare({
69
- apiToken
70
- });
71
- }
72
- get indexSeparator() {
73
- return "-";
74
- }
75
- async upsert({ indexName, vectors, metadata, ids }) {
76
- const generatedIds = ids || vectors.map(() => crypto.randomUUID());
77
- const ndjson = vectors.map(
78
- (vector, index) => JSON.stringify({
79
- id: generatedIds[index],
80
- values: vector,
81
- metadata: metadata?.[index]
82
- })
83
- ).join("\n");
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
- }
107
- }
108
- transformFilter(filter) {
109
- const translator = new VectorizeFilterTranslator();
110
- return translator.translate(filter);
111
- }
112
- async createIndex({ indexName, dimension, metric = "cosine" }) {
113
- try {
114
- await this.client.vectorize.indexes.create({
115
- account_id: this.accountId,
116
- config: {
117
- dimensions: dimension,
118
- metric: metric === "dotproduct" ? "dot-product" : metric
119
- },
120
- name: indexName
121
- });
122
- } catch (error) {
123
- const message = error?.errors?.[0]?.message || error?.message;
124
- if (error.status === 409 || typeof message === "string" && (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("duplicate"))) {
125
- await this.validateExistingIndex(indexName, dimension, metric);
126
- return;
127
- }
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
- );
137
- }
138
- }
139
- async query({
140
- indexName,
141
- queryVector,
142
- topK = 10,
143
- filter,
144
- includeVector = false
145
- }) {
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
- }
175
- }
176
- async listIndexes() {
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
- }
192
- }
193
- /**
194
- * Retrieves statistics about a vector index.
195
- *
196
- * @param {string} indexName - The name of the index to describe
197
- * @returns A promise that resolves to the index statistics including dimension, count and metric
198
- */
199
- async describeIndex({ indexName }) {
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
- }
225
- }
226
- async deleteIndex({ indexName }) {
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
- }
242
- }
243
- async createMetadataIndex(indexName, propertyName, indexType) {
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
- }
261
- }
262
- async deleteMetadataIndex(indexName, propertyName) {
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
- }
279
- }
280
- async listMetadataIndexes(indexName) {
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
- }
297
- }
298
- /**
299
- * Updates a vector by its ID with the provided vector and/or metadata.
300
- * @param indexName - The name of the index containing the vector.
301
- * @param id - The ID of the vector to update.
302
- * @param update - An object containing the vector and/or metadata to update.
303
- * @param update.vector - An optional array of numbers representing the new vector.
304
- * @param update.metadata - An optional record containing the new metadata.
305
- * @returns A promise that resolves when the update is complete.
306
- * @throws Will throw an error if no updates are provided or if the update operation fails.
307
- */
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
- }
318
- try {
319
- const updatePayload = {
320
- };
321
- if (update.vector) {
322
- updatePayload.vectors = [update.vector];
323
- }
324
- if (update.metadata) {
325
- updatePayload.metadata = [update.metadata];
326
- }
327
- await this.upsert({ indexName, vectors: updatePayload.vectors, metadata: updatePayload.metadata });
328
- } catch (error) {
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
- );
338
- }
339
- }
340
- /**
341
- * Deletes a vector by its ID.
342
- * @param indexName - The name of the index containing the vector.
343
- * @param id - The ID of the vector to delete.
344
- * @returns A promise that resolves when the deletion is complete.
345
- * @throws Will throw an error if the deletion operation fails.
346
- */
347
- async deleteVector({ indexName, id }) {
348
- try {
349
- await this.client.vectorize.indexes.deleteByIds(indexName, {
350
- ids: [id],
351
- account_id: this.accountId
352
- });
353
- } catch (error) {
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
- );
363
- }
364
- }
55
+ client;
56
+ accountId;
57
+ constructor({ accountId, apiToken, id }) {
58
+ super({ id });
59
+ this.accountId = accountId;
60
+ this.client = new Cloudflare({ apiToken });
61
+ }
62
+ get indexSeparator() {
63
+ return "-";
64
+ }
65
+ async upsert({ indexName, vectors, metadata, ids }) {
66
+ const generatedIds = ids || vectors.map(() => crypto.randomUUID());
67
+ const ndjson = vectors.map((vector, index) => JSON.stringify({
68
+ id: generatedIds[index],
69
+ values: vector,
70
+ metadata: metadata?.[index]
71
+ })).join("\n");
72
+ try {
73
+ const body = new File([ndjson], `${indexName}.ndjson`, { type: "application/x-ndjson" });
74
+ await this.client.vectorize.indexes.upsert(indexName, {
75
+ account_id: this.accountId,
76
+ body
77
+ });
78
+ return generatedIds;
79
+ } catch (error) {
80
+ throw new MastraError({
81
+ id: createVectorErrorId("VECTORIZE", "UPSERT", "FAILED"),
82
+ domain: ErrorDomain.STORAGE,
83
+ category: ErrorCategory.THIRD_PARTY,
84
+ details: {
85
+ indexName,
86
+ vectorCount: vectors?.length
87
+ }
88
+ }, error);
89
+ }
90
+ }
91
+ transformFilter(filter) {
92
+ return new VectorizeFilterTranslator().translate(filter);
93
+ }
94
+ async createIndex({ indexName, dimension, metric = "cosine" }) {
95
+ try {
96
+ await this.client.vectorize.indexes.create({
97
+ account_id: this.accountId,
98
+ config: {
99
+ dimensions: dimension,
100
+ metric: metric === "dotproduct" ? "dot-product" : metric
101
+ },
102
+ name: indexName
103
+ });
104
+ } catch (error) {
105
+ const message = error?.errors?.[0]?.message || error?.message;
106
+ if (error.status === 409 || typeof message === "string" && (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("duplicate"))) {
107
+ await this.validateExistingIndex(indexName, dimension, metric);
108
+ return;
109
+ }
110
+ throw new MastraError({
111
+ id: createVectorErrorId("VECTORIZE", "CREATE_INDEX", "FAILED"),
112
+ domain: ErrorDomain.STORAGE,
113
+ category: ErrorCategory.THIRD_PARTY,
114
+ details: {
115
+ indexName,
116
+ dimension,
117
+ metric
118
+ }
119
+ }, error);
120
+ }
121
+ }
122
+ async query({ indexName, queryVector, topK = 10, filter, includeVector = false }) {
123
+ if (!queryVector) throw new MastraError({
124
+ id: createVectorErrorId("VECTORIZE", "QUERY", "MISSING_VECTOR"),
125
+ text: "queryVector is required for Vectorize queries. Metadata-only queries are not supported by this vector store.",
126
+ domain: ErrorDomain.STORAGE,
127
+ category: ErrorCategory.USER,
128
+ details: { indexName }
129
+ });
130
+ try {
131
+ const translatedFilter = this.transformFilter(filter) ?? {};
132
+ return (await this.client.vectorize.indexes.query(indexName, {
133
+ account_id: this.accountId,
134
+ vector: queryVector,
135
+ returnValues: includeVector,
136
+ returnMetadata: "all",
137
+ topK,
138
+ filter: translatedFilter
139
+ }))?.matches?.map((match) => {
140
+ return {
141
+ id: match.id,
142
+ metadata: match.metadata,
143
+ score: match.score,
144
+ vector: match.values
145
+ };
146
+ }) || [];
147
+ } catch (error) {
148
+ throw new MastraError({
149
+ id: createVectorErrorId("VECTORIZE", "QUERY", "FAILED"),
150
+ domain: ErrorDomain.STORAGE,
151
+ category: ErrorCategory.THIRD_PARTY,
152
+ details: {
153
+ indexName,
154
+ topK
155
+ }
156
+ }, error);
157
+ }
158
+ }
159
+ async listIndexes() {
160
+ try {
161
+ return (await this.client.vectorize.indexes.list({ account_id: this.accountId }))?.result?.map((index) => index.name) || [];
162
+ } catch (error) {
163
+ throw new MastraError({
164
+ id: createVectorErrorId("VECTORIZE", "LIST_INDEXES", "FAILED"),
165
+ domain: ErrorDomain.STORAGE,
166
+ category: ErrorCategory.THIRD_PARTY
167
+ }, error);
168
+ }
169
+ }
170
+ /**
171
+ * Retrieves statistics about a vector index.
172
+ *
173
+ * @param {string} indexName - The name of the index to describe
174
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
175
+ */
176
+ async describeIndex({ indexName }) {
177
+ try {
178
+ const index = await this.client.vectorize.indexes.get(indexName, { account_id: this.accountId });
179
+ const described = await this.client.vectorize.indexes.info(indexName, { account_id: this.accountId });
180
+ return {
181
+ dimension: described?.dimensions,
182
+ count: described?.vectorCount || 0,
183
+ metric: index?.config?.metric
184
+ };
185
+ } catch (error) {
186
+ throw new MastraError({
187
+ id: createVectorErrorId("VECTORIZE", "DESCRIBE_INDEX", "FAILED"),
188
+ domain: ErrorDomain.STORAGE,
189
+ category: ErrorCategory.THIRD_PARTY,
190
+ details: { indexName }
191
+ }, error);
192
+ }
193
+ }
194
+ async deleteIndex({ indexName }) {
195
+ try {
196
+ await this.client.vectorize.indexes.delete(indexName, { account_id: this.accountId });
197
+ } catch (error) {
198
+ throw new MastraError({
199
+ id: createVectorErrorId("VECTORIZE", "DELETE_INDEX", "FAILED"),
200
+ domain: ErrorDomain.STORAGE,
201
+ category: ErrorCategory.THIRD_PARTY,
202
+ details: { indexName }
203
+ }, error);
204
+ }
205
+ }
206
+ async createMetadataIndex(indexName, propertyName, indexType) {
207
+ try {
208
+ await this.client.vectorize.indexes.metadataIndex.create(indexName, {
209
+ account_id: this.accountId,
210
+ propertyName,
211
+ indexType
212
+ });
213
+ } catch (error) {
214
+ throw new MastraError({
215
+ id: createVectorErrorId("VECTORIZE", "CREATE_METADATA_INDEX", "FAILED"),
216
+ domain: ErrorDomain.STORAGE,
217
+ category: ErrorCategory.THIRD_PARTY,
218
+ details: {
219
+ indexName,
220
+ propertyName,
221
+ indexType
222
+ }
223
+ }, error);
224
+ }
225
+ }
226
+ async deleteMetadataIndex(indexName, propertyName) {
227
+ try {
228
+ await this.client.vectorize.indexes.metadataIndex.delete(indexName, {
229
+ account_id: this.accountId,
230
+ propertyName
231
+ });
232
+ } catch (error) {
233
+ throw new MastraError({
234
+ id: createVectorErrorId("VECTORIZE", "DELETE_METADATA_INDEX", "FAILED"),
235
+ domain: ErrorDomain.STORAGE,
236
+ category: ErrorCategory.THIRD_PARTY,
237
+ details: {
238
+ indexName,
239
+ propertyName
240
+ }
241
+ }, error);
242
+ }
243
+ }
244
+ async listMetadataIndexes(indexName) {
245
+ try {
246
+ return (await this.client.vectorize.indexes.metadataIndex.list(indexName, { account_id: this.accountId }))?.metadataIndexes ?? [];
247
+ } catch (error) {
248
+ throw new MastraError({
249
+ id: createVectorErrorId("VECTORIZE", "LIST_METADATA_INDEXES", "FAILED"),
250
+ domain: ErrorDomain.STORAGE,
251
+ category: ErrorCategory.THIRD_PARTY,
252
+ details: { indexName }
253
+ }, error);
254
+ }
255
+ }
256
+ /**
257
+ * Updates a vector by its ID with the provided vector and/or metadata.
258
+ * @param indexName - The name of the index containing the vector.
259
+ * @param id - The ID of the vector to update.
260
+ * @param update - An object containing the vector and/or metadata to update.
261
+ * @param update.vector - An optional array of numbers representing the new vector.
262
+ * @param update.metadata - An optional record containing the new metadata.
263
+ * @returns A promise that resolves when the update is complete.
264
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
265
+ */
266
+ async updateVector({ indexName, id, update }) {
267
+ if (!id) throw new MastraError({
268
+ id: createVectorErrorId("VECTORIZE", "UPDATE_VECTOR", "INVALID_ARGS"),
269
+ domain: ErrorDomain.STORAGE,
270
+ category: ErrorCategory.USER,
271
+ text: "id is required for Vectorize updateVector",
272
+ details: { indexName }
273
+ });
274
+ if (!update.vector && !update.metadata) throw new MastraError({
275
+ id: createVectorErrorId("VECTORIZE", "UPDATE_VECTOR", "NO_PAYLOAD"),
276
+ domain: ErrorDomain.STORAGE,
277
+ category: ErrorCategory.USER,
278
+ text: "No update data provided",
279
+ details: {
280
+ indexName,
281
+ id
282
+ }
283
+ });
284
+ try {
285
+ const updatePayload = {
286
+ ids: [id],
287
+ account_id: this.accountId
288
+ };
289
+ if (update.vector) updatePayload.vectors = [update.vector];
290
+ if (update.metadata) updatePayload.metadata = [update.metadata];
291
+ await this.upsert({
292
+ indexName,
293
+ vectors: updatePayload.vectors,
294
+ metadata: updatePayload.metadata
295
+ });
296
+ } catch (error) {
297
+ throw new MastraError({
298
+ id: createVectorErrorId("VECTORIZE", "UPDATE_VECTOR", "FAILED"),
299
+ domain: ErrorDomain.STORAGE,
300
+ category: ErrorCategory.THIRD_PARTY,
301
+ details: {
302
+ indexName,
303
+ ...id && { id }
304
+ }
305
+ }, error);
306
+ }
307
+ }
308
+ /**
309
+ * Deletes a vector by its ID.
310
+ * @param indexName - The name of the index containing the vector.
311
+ * @param id - The ID of the vector to delete.
312
+ * @returns A promise that resolves when the deletion is complete.
313
+ * @throws Will throw an error if the deletion operation fails.
314
+ */
315
+ async deleteVector({ indexName, id }) {
316
+ try {
317
+ await this.client.vectorize.indexes.deleteByIds(indexName, {
318
+ ids: [id],
319
+ account_id: this.accountId
320
+ });
321
+ } catch (error) {
322
+ throw new MastraError({
323
+ id: createVectorErrorId("VECTORIZE", "DELETE_VECTOR", "FAILED"),
324
+ domain: ErrorDomain.STORAGE,
325
+ category: ErrorCategory.THIRD_PARTY,
326
+ details: {
327
+ indexName,
328
+ ...id && { id }
329
+ }
330
+ }, error);
331
+ }
332
+ }
333
+ async deleteVectors({ indexName, filter, ids }) {
334
+ throw new MastraError({
335
+ id: createVectorErrorId("VECTORIZE", "DELETE_VECTORS", "NOT_SUPPORTED"),
336
+ text: "deleteVectors is not yet implemented for Vectorize vector store",
337
+ domain: ErrorDomain.STORAGE,
338
+ category: ErrorCategory.SYSTEM,
339
+ details: {
340
+ indexName,
341
+ ...filter && { filter: JSON.stringify(filter) },
342
+ ...ids && { idsCount: ids.length }
343
+ }
344
+ });
345
+ }
365
346
  };
366
-
367
- // src/vector/prompt.ts
368
- var VECTORIZE_PROMPT = `When querying Vectorize, you can ONLY use the operators listed below. Any other operators will be rejected.
347
+ //#endregion
348
+ //#region src/vector/prompt.ts
349
+ /**
350
+ * Vector store specific prompt that details supported operators and examples.
351
+ * This prompt helps users construct valid filters for Vectorize.
352
+ */
353
+ const VECTORIZE_PROMPT = `When querying Vectorize, you can ONLY use the operators listed below. Any other operators will be rejected.
369
354
  Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
370
355
  If a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.
371
356
 
@@ -441,7 +426,7 @@ Example Complex Query:
441
426
  ]}
442
427
  ]
443
428
  }`;
444
-
429
+ //#endregion
445
430
  export { CloudflareVector, VECTORIZE_PROMPT };
446
- //# sourceMappingURL=index.js.map
431
+
447
432
  //# sourceMappingURL=index.js.map