@mastra/vectorize 0.10.2 → 0.11.0-alpha.1

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.
@@ -1,19 +1,22 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
+ import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
2
3
  import Cloudflare from 'cloudflare';
3
4
  import type { CreateIndexParams } from '@mastra/core/vector';
4
5
  import type { DeleteIndexParams } from '@mastra/core/vector';
5
6
  import type { DeleteVectorParams } from '@mastra/core/vector';
6
7
  import type { DescribeIndexParams } from '@mastra/core/vector';
7
8
  import type { IndexStats } from '@mastra/core/vector';
9
+ import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
8
10
  import { MastraVector } from '@mastra/core/vector';
9
11
  import type { OperatorSupport } from '@mastra/core/vector/filter';
12
+ import type { OperatorValueMap } from '@mastra/core/vector/filter';
10
13
  import type { QueryResult } from '@mastra/core/vector';
11
14
  import type { QueryVectorParams } from '@mastra/core/vector';
12
15
  import type { UpdateVectorParams } from '@mastra/core/vector';
13
16
  import type { UpsertVectorParams } from '@mastra/core/vector';
14
17
  import type { VectorFilter } from '@mastra/core/vector/filter';
15
18
 
16
- declare class CloudflareVector extends MastraVector {
19
+ declare class CloudflareVector extends MastraVector<VectorizeVectorFilter> {
17
20
  client: Cloudflare;
18
21
  accountId: string;
19
22
  constructor({ accountId, apiToken }: {
@@ -22,9 +25,9 @@ declare class CloudflareVector extends MastraVector {
22
25
  });
23
26
  get indexSeparator(): string;
24
27
  upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
25
- transformFilter(filter?: VectorFilter): VectorFilter;
28
+ transformFilter(filter?: VectorizeVectorFilter): VectorizeVectorFilter;
26
29
  createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
27
- query({ indexName, queryVector, topK, filter, includeVector, }: QueryVectorParams): Promise<QueryResult[]>;
30
+ query({ indexName, queryVector, topK, filter, includeVector, }: VectorizeQueryParams): Promise<QueryResult[]>;
28
31
  listIndexes(): Promise<string[]>;
29
32
  /**
30
33
  * Retrieves statistics about a vector index.
@@ -68,10 +71,20 @@ declare const VECTORIZE_PROMPT = "When querying Vectorize, you can ONLY use the
68
71
  export { VECTORIZE_PROMPT }
69
72
  export { VECTORIZE_PROMPT as VECTORIZE_PROMPT_alias_1 }
70
73
 
71
- export declare class VectorizeFilterTranslator extends BaseFilterTranslator {
74
+ declare type VectorizeBlacklistedRootOperators = BlacklistedRootOperators | '$nor' | '$not' | '$and' | '$or';
75
+
76
+ export declare class VectorizeFilterTranslator extends BaseFilterTranslator<VectorizeVectorFilter> {
72
77
  protected getSupportedOperators(): OperatorSupport;
73
- translate(filter?: VectorFilter): VectorFilter;
78
+ translate(filter?: VectorizeVectorFilter): VectorizeVectorFilter;
74
79
  private translateNode;
75
80
  }
76
81
 
82
+ declare type VectorizeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not' | '$and' | '$or'>;
83
+
84
+ declare type VectorizeOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$exists' | '$elemMatch' | '$all'>;
85
+
86
+ declare type VectorizeQueryParams = QueryVectorParams<VectorizeVectorFilter>;
87
+
88
+ export declare type VectorizeVectorFilter = VectorFilter<keyof VectorizeOperatorValueMap, VectorizeOperatorValueMap, VectorizeLogicalOperatorValueMap, VectorizeBlacklistedRootOperators>;
89
+
77
90
  export { }
@@ -1,19 +1,22 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
+ import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
2
3
  import Cloudflare from 'cloudflare';
3
4
  import type { CreateIndexParams } from '@mastra/core/vector';
4
5
  import type { DeleteIndexParams } from '@mastra/core/vector';
5
6
  import type { DeleteVectorParams } from '@mastra/core/vector';
6
7
  import type { DescribeIndexParams } from '@mastra/core/vector';
7
8
  import type { IndexStats } from '@mastra/core/vector';
9
+ import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
8
10
  import { MastraVector } from '@mastra/core/vector';
9
11
  import type { OperatorSupport } from '@mastra/core/vector/filter';
12
+ import type { OperatorValueMap } from '@mastra/core/vector/filter';
10
13
  import type { QueryResult } from '@mastra/core/vector';
11
14
  import type { QueryVectorParams } from '@mastra/core/vector';
12
15
  import type { UpdateVectorParams } from '@mastra/core/vector';
13
16
  import type { UpsertVectorParams } from '@mastra/core/vector';
14
17
  import type { VectorFilter } from '@mastra/core/vector/filter';
15
18
 
16
- declare class CloudflareVector extends MastraVector {
19
+ declare class CloudflareVector extends MastraVector<VectorizeVectorFilter> {
17
20
  client: Cloudflare;
18
21
  accountId: string;
19
22
  constructor({ accountId, apiToken }: {
@@ -22,9 +25,9 @@ declare class CloudflareVector extends MastraVector {
22
25
  });
23
26
  get indexSeparator(): string;
24
27
  upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
25
- transformFilter(filter?: VectorFilter): VectorFilter;
28
+ transformFilter(filter?: VectorizeVectorFilter): VectorizeVectorFilter;
26
29
  createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
27
- query({ indexName, queryVector, topK, filter, includeVector, }: QueryVectorParams): Promise<QueryResult[]>;
30
+ query({ indexName, queryVector, topK, filter, includeVector, }: VectorizeQueryParams): Promise<QueryResult[]>;
28
31
  listIndexes(): Promise<string[]>;
29
32
  /**
30
33
  * Retrieves statistics about a vector index.
@@ -68,10 +71,20 @@ declare const VECTORIZE_PROMPT = "When querying Vectorize, you can ONLY use the
68
71
  export { VECTORIZE_PROMPT }
69
72
  export { VECTORIZE_PROMPT as VECTORIZE_PROMPT_alias_1 }
70
73
 
71
- export declare class VectorizeFilterTranslator extends BaseFilterTranslator {
74
+ declare type VectorizeBlacklistedRootOperators = BlacklistedRootOperators | '$nor' | '$not' | '$and' | '$or';
75
+
76
+ export declare class VectorizeFilterTranslator extends BaseFilterTranslator<VectorizeVectorFilter> {
72
77
  protected getSupportedOperators(): OperatorSupport;
73
- translate(filter?: VectorFilter): VectorFilter;
78
+ translate(filter?: VectorizeVectorFilter): VectorizeVectorFilter;
74
79
  private translateNode;
75
80
  }
76
81
 
82
+ declare type VectorizeLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor' | '$not' | '$and' | '$or'>;
83
+
84
+ declare type VectorizeOperatorValueMap = Omit<OperatorValueMap, '$regex' | '$options' | '$exists' | '$elemMatch' | '$all'>;
85
+
86
+ declare type VectorizeQueryParams = QueryVectorParams<VectorizeVectorFilter>;
87
+
88
+ export declare type VectorizeVectorFilter = VectorFilter<keyof VectorizeOperatorValueMap, VectorizeOperatorValueMap, VectorizeLogicalOperatorValueMap, VectorizeBlacklistedRootOperators>;
89
+
77
90
  export { }
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
- await this.client.vectorize.indexes.upsert(
90
- indexName,
91
- {
92
- account_id: this.accountId,
93
- body: ndjson
94
- },
95
- {
96
- __binaryRequest: true
97
- }
98
- );
99
- return generatedIds;
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
- const translatedFilter = this.transformFilter(filter) ?? {};
132
- const response = 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
- });
140
- return response?.matches?.map((match) => {
141
- return {
142
- id: match.id,
143
- metadata: match.metadata,
144
- score: match.score,
145
- vector: match.values
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
- const res = await this.client.vectorize.indexes.list({
151
- account_id: this.accountId
152
- });
153
- return res?.result?.map((index) => index.name) || [];
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
- const index = await this.client.vectorize.indexes.get(indexName, {
163
- account_id: this.accountId
164
- });
165
- const described = await this.client.vectorize.indexes.info(indexName, {
166
- account_id: this.accountId
167
- });
168
- return {
169
- dimension: described?.dimensions,
170
- // Since vector_count is not available in the response,
171
- // we might need a separate API call to get the count if needed
172
- count: described?.vectorCount || 0,
173
- metric: index?.config?.metric
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
- await this.client.vectorize.indexes.delete(indexName, {
178
- account_id: this.accountId
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
- await this.client.vectorize.indexes.metadataIndex.create(indexName, {
183
- account_id: this.accountId,
184
- propertyName,
185
- indexType
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
- await this.client.vectorize.indexes.metadataIndex.delete(indexName, {
190
- account_id: this.accountId,
191
- propertyName
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
- const res = await this.client.vectorize.indexes.metadataIndex.list(indexName, {
196
- account_id: this.accountId
197
- });
198
- return res?.metadataIndexes ?? [];
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 Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
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 Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
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
- await this.client.vectorize.indexes.upsert(
84
- indexName,
85
- {
86
- account_id: this.accountId,
87
- body: ndjson
88
- },
89
- {
90
- __binaryRequest: true
91
- }
92
- );
93
- return generatedIds;
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 error;
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
- const translatedFilter = this.transformFilter(filter) ?? {};
126
- const response = await this.client.vectorize.indexes.query(indexName, {
127
- account_id: this.accountId,
128
- vector: queryVector,
129
- returnValues: includeVector,
130
- returnMetadata: "all",
131
- topK,
132
- filter: translatedFilter
133
- });
134
- return response?.matches?.map((match) => {
135
- return {
136
- id: match.id,
137
- metadata: match.metadata,
138
- score: match.score,
139
- vector: match.values
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
- const res = await this.client.vectorize.indexes.list({
145
- account_id: this.accountId
146
- });
147
- return res?.result?.map((index) => index.name) || [];
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
- const index = await this.client.vectorize.indexes.get(indexName, {
157
- account_id: this.accountId
158
- });
159
- const described = await this.client.vectorize.indexes.info(indexName, {
160
- account_id: this.accountId
161
- });
162
- return {
163
- dimension: described?.dimensions,
164
- // Since vector_count is not available in the response,
165
- // we might need a separate API call to get the count if needed
166
- count: described?.vectorCount || 0,
167
- metric: index?.config?.metric
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
- await this.client.vectorize.indexes.delete(indexName, {
172
- account_id: this.accountId
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
- await this.client.vectorize.indexes.metadataIndex.create(indexName, {
177
- account_id: this.accountId,
178
- propertyName,
179
- indexType
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
- await this.client.vectorize.indexes.metadataIndex.delete(indexName, {
184
- account_id: this.accountId,
185
- propertyName
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
- const res = await this.client.vectorize.indexes.metadataIndex.list(indexName, {
190
- account_id: this.accountId
191
- });
192
- return res?.metadataIndexes ?? [];
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 Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
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 Error(`Failed to delete vector by id: ${id} for index name: ${indexName}: ${error.message}`);
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.2",
3
+ "version": "0.11.0-alpha.1",
4
4
  "description": "Cloudflare Vectorize store provider for Mastra",
5
5
  "type": "module",
6
6
  "files": [
@@ -27,17 +27,17 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "@microsoft/api-extractor": "^7.52.8",
30
- "@types/node": "^20.17.57",
30
+ "@types/node": "^20.19.0",
31
31
  "dotenv": "^16.5.0",
32
- "eslint": "^9.28.0",
32
+ "eslint": "^9.29.0",
33
33
  "tsup": "^8.5.0",
34
- "typescript": "^5.8.2",
35
- "vitest": "^3.2.2",
36
- "@internal/lint": "0.0.11",
37
- "@mastra/core": "0.10.4"
34
+ "typescript": "^5.8.3",
35
+ "vitest": "^3.2.3",
36
+ "@internal/lint": "0.0.13",
37
+ "@mastra/core": "0.10.7-alpha.3"
38
38
  },
39
39
  "peerDependencies": {
40
- "@mastra/core": ">=0.10.4-0 <0.11.0"
40
+ "@mastra/core": ">=0.10.7-0 <0.11.0-0"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",