@mastra/turbopuffer 0.10.3-alpha.0 → 0.10.4-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 +162 -51
- package/dist/index.js +155 -44
- package/package.json +3 -3
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 turbopuffer = require('@turbopuffer/turbopuffer');
|
|
5
6
|
var filter = require('@mastra/core/vector/filter');
|
|
@@ -188,28 +189,40 @@ var TurbopufferVector = class extends vector.MastraVector {
|
|
|
188
189
|
}
|
|
189
190
|
async createIndex({ indexName, dimension, metric }) {
|
|
190
191
|
metric = metric ?? "cosine";
|
|
191
|
-
if (this.createIndexCache.has(indexName)) {
|
|
192
|
-
const expected = this.createIndexCache.get(indexName);
|
|
193
|
-
if (dimension !== expected.dimension || metric !== expected.metric) {
|
|
194
|
-
throw new Error(
|
|
195
|
-
`createIndex() called more than once with inconsistent inputs. Index ${indexName} expected dimensions=${expected.dimension} and metric=${expected.metric} but got dimensions=${dimension} and metric=${metric}`
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
if (dimension <= 0) {
|
|
201
|
-
throw new Error("Dimension must be a positive integer");
|
|
202
|
-
}
|
|
203
192
|
let distanceMetric = "cosine_distance";
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
193
|
+
try {
|
|
194
|
+
if (this.createIndexCache.has(indexName)) {
|
|
195
|
+
const expected = this.createIndexCache.get(indexName);
|
|
196
|
+
if (dimension !== expected.dimension || metric !== expected.metric) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
`createIndex() called more than once with inconsistent inputs. Index ${indexName} expected dimensions=${expected.dimension} and metric=${expected.metric} but got dimensions=${dimension} and metric=${metric}`
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (dimension <= 0) {
|
|
204
|
+
throw new Error("Dimension must be a positive integer");
|
|
205
|
+
}
|
|
206
|
+
switch (metric) {
|
|
207
|
+
case "cosine":
|
|
208
|
+
distanceMetric = "cosine_distance";
|
|
209
|
+
break;
|
|
210
|
+
case "euclidean":
|
|
211
|
+
distanceMetric = "euclidean_squared";
|
|
212
|
+
break;
|
|
213
|
+
case "dotproduct":
|
|
214
|
+
throw new Error("dotproduct is not supported in Turbopuffer");
|
|
215
|
+
}
|
|
216
|
+
} catch (error$1) {
|
|
217
|
+
throw new error.MastraError(
|
|
218
|
+
{
|
|
219
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_CREATE_INDEX_INVALID_ARGS",
|
|
220
|
+
domain: error.ErrorDomain.STORAGE,
|
|
221
|
+
category: error.ErrorCategory.USER,
|
|
222
|
+
details: { indexName, dimension, metric }
|
|
223
|
+
},
|
|
224
|
+
error$1
|
|
225
|
+
);
|
|
213
226
|
}
|
|
214
227
|
this.createIndexCache.set(indexName, {
|
|
215
228
|
indexName,
|
|
@@ -219,15 +232,29 @@ var TurbopufferVector = class extends vector.MastraVector {
|
|
|
219
232
|
});
|
|
220
233
|
}
|
|
221
234
|
async upsert({ indexName, vectors, metadata, ids }) {
|
|
235
|
+
let index;
|
|
236
|
+
let createIndex;
|
|
222
237
|
try {
|
|
223
238
|
if (vectors.length === 0) {
|
|
224
239
|
throw new Error("upsert() called with empty vectors");
|
|
225
240
|
}
|
|
226
|
-
|
|
227
|
-
|
|
241
|
+
index = this.client.namespace(indexName);
|
|
242
|
+
createIndex = this.createIndexCache.get(indexName);
|
|
228
243
|
if (!createIndex) {
|
|
229
244
|
throw new Error(`createIndex() not called for this index`);
|
|
230
245
|
}
|
|
246
|
+
} catch (error$1) {
|
|
247
|
+
throw new error.MastraError(
|
|
248
|
+
{
|
|
249
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_UPSERT_INVALID_ARGS",
|
|
250
|
+
domain: error.ErrorDomain.STORAGE,
|
|
251
|
+
category: error.ErrorCategory.USER,
|
|
252
|
+
details: { indexName }
|
|
253
|
+
},
|
|
254
|
+
error$1
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
231
258
|
const distanceMetric = createIndex.tpufDistanceMetric;
|
|
232
259
|
const vectorIds = ids || vectors.map(() => crypto.randomUUID());
|
|
233
260
|
const records = vectors.map((vector, i) => ({
|
|
@@ -254,22 +281,43 @@ var TurbopufferVector = class extends vector.MastraVector {
|
|
|
254
281
|
await index.upsert(upsertOptions);
|
|
255
282
|
}
|
|
256
283
|
return vectorIds;
|
|
257
|
-
} catch (error) {
|
|
258
|
-
throw new
|
|
284
|
+
} catch (error$1) {
|
|
285
|
+
throw new error.MastraError(
|
|
286
|
+
{
|
|
287
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_UPSERT_FAILED",
|
|
288
|
+
domain: error.ErrorDomain.STORAGE,
|
|
289
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
290
|
+
details: { indexName }
|
|
291
|
+
},
|
|
292
|
+
error$1
|
|
293
|
+
);
|
|
259
294
|
}
|
|
260
295
|
}
|
|
261
296
|
async query({ indexName, queryVector, topK, filter, includeVector }) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
297
|
+
let createIndex;
|
|
298
|
+
try {
|
|
299
|
+
const schemaConfig = this.opts.schemaConfigForIndex?.(indexName);
|
|
300
|
+
if (schemaConfig) {
|
|
301
|
+
if (queryVector.length !== schemaConfig.dimensions) {
|
|
302
|
+
throw new Error(
|
|
303
|
+
`Turbopuffer index ${indexName} was configured with dimensions=${schemaConfig.dimensions} but attempting to query with queryVector.length=${queryVector.length}`
|
|
304
|
+
);
|
|
305
|
+
}
|
|
268
306
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
307
|
+
createIndex = this.createIndexCache.get(indexName);
|
|
308
|
+
if (!createIndex) {
|
|
309
|
+
throw new Error(`createIndex() not called for this index`);
|
|
310
|
+
}
|
|
311
|
+
} catch (error$1) {
|
|
312
|
+
throw new error.MastraError(
|
|
313
|
+
{
|
|
314
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_QUERY_INVALID_ARGS",
|
|
315
|
+
domain: error.ErrorDomain.STORAGE,
|
|
316
|
+
category: error.ErrorCategory.USER,
|
|
317
|
+
details: { indexName }
|
|
318
|
+
},
|
|
319
|
+
error$1
|
|
320
|
+
);
|
|
273
321
|
}
|
|
274
322
|
const distanceMetric = createIndex.tpufDistanceMetric;
|
|
275
323
|
try {
|
|
@@ -291,16 +339,31 @@ var TurbopufferVector = class extends vector.MastraVector {
|
|
|
291
339
|
metadata: item.attributes || {},
|
|
292
340
|
...includeVector && item.vector ? { vector: item.vector } : {}
|
|
293
341
|
}));
|
|
294
|
-
} catch (error) {
|
|
295
|
-
throw new
|
|
342
|
+
} catch (error$1) {
|
|
343
|
+
throw new error.MastraError(
|
|
344
|
+
{
|
|
345
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_QUERY_FAILED",
|
|
346
|
+
domain: error.ErrorDomain.STORAGE,
|
|
347
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
348
|
+
details: { indexName }
|
|
349
|
+
},
|
|
350
|
+
error$1
|
|
351
|
+
);
|
|
296
352
|
}
|
|
297
353
|
}
|
|
298
354
|
async listIndexes() {
|
|
299
355
|
try {
|
|
300
356
|
const namespacesResult = await this.client.namespaces({});
|
|
301
357
|
return namespacesResult.namespaces.map((namespace) => namespace.id);
|
|
302
|
-
} catch (error) {
|
|
303
|
-
throw new
|
|
358
|
+
} catch (error$1) {
|
|
359
|
+
throw new error.MastraError(
|
|
360
|
+
{
|
|
361
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_LIST_INDEXES_FAILED",
|
|
362
|
+
domain: error.ErrorDomain.STORAGE,
|
|
363
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
364
|
+
},
|
|
365
|
+
error$1
|
|
366
|
+
);
|
|
304
367
|
}
|
|
305
368
|
}
|
|
306
369
|
/**
|
|
@@ -324,8 +387,16 @@ var TurbopufferVector = class extends vector.MastraVector {
|
|
|
324
387
|
count,
|
|
325
388
|
metric: createIndex.metric
|
|
326
389
|
};
|
|
327
|
-
} catch (error) {
|
|
328
|
-
throw new
|
|
390
|
+
} catch (error$1) {
|
|
391
|
+
throw new error.MastraError(
|
|
392
|
+
{
|
|
393
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_DESCRIBE_INDEX_FAILED",
|
|
394
|
+
domain: error.ErrorDomain.STORAGE,
|
|
395
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
396
|
+
details: { indexName }
|
|
397
|
+
},
|
|
398
|
+
error$1
|
|
399
|
+
);
|
|
329
400
|
}
|
|
330
401
|
}
|
|
331
402
|
async deleteIndex({ indexName }) {
|
|
@@ -333,8 +404,16 @@ var TurbopufferVector = class extends vector.MastraVector {
|
|
|
333
404
|
const namespace = this.client.namespace(indexName);
|
|
334
405
|
await namespace.deleteAll();
|
|
335
406
|
this.createIndexCache.delete(indexName);
|
|
336
|
-
} catch (error) {
|
|
337
|
-
throw new
|
|
407
|
+
} catch (error$1) {
|
|
408
|
+
throw new error.MastraError(
|
|
409
|
+
{
|
|
410
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_DELETE_INDEX_FAILED",
|
|
411
|
+
domain: error.ErrorDomain.STORAGE,
|
|
412
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
413
|
+
details: { indexName }
|
|
414
|
+
},
|
|
415
|
+
error$1
|
|
416
|
+
);
|
|
338
417
|
}
|
|
339
418
|
}
|
|
340
419
|
/**
|
|
@@ -348,22 +427,46 @@ var TurbopufferVector = class extends vector.MastraVector {
|
|
|
348
427
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
349
428
|
*/
|
|
350
429
|
async updateVector({ indexName, id, update }) {
|
|
430
|
+
let namespace;
|
|
431
|
+
let createIndex;
|
|
432
|
+
let distanceMetric;
|
|
433
|
+
let record;
|
|
351
434
|
try {
|
|
352
|
-
|
|
353
|
-
|
|
435
|
+
namespace = this.client.namespace(indexName);
|
|
436
|
+
createIndex = this.createIndexCache.get(indexName);
|
|
354
437
|
if (!createIndex) {
|
|
355
438
|
throw new Error(`createIndex() not called for this index`);
|
|
356
439
|
}
|
|
357
|
-
|
|
358
|
-
|
|
440
|
+
distanceMetric = createIndex.tpufDistanceMetric;
|
|
441
|
+
record = { id };
|
|
359
442
|
if (update.vector) record.vector = update.vector;
|
|
360
443
|
if (update.metadata) record.attributes = update.metadata;
|
|
444
|
+
} catch (error$1) {
|
|
445
|
+
throw new error.MastraError(
|
|
446
|
+
{
|
|
447
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
448
|
+
domain: error.ErrorDomain.STORAGE,
|
|
449
|
+
category: error.ErrorCategory.USER,
|
|
450
|
+
details: { indexName }
|
|
451
|
+
},
|
|
452
|
+
error$1
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
try {
|
|
361
456
|
await namespace.upsert({
|
|
362
457
|
vectors: [record],
|
|
363
458
|
distance_metric: distanceMetric
|
|
364
459
|
});
|
|
365
|
-
} catch (error) {
|
|
366
|
-
throw new
|
|
460
|
+
} catch (error$1) {
|
|
461
|
+
throw new error.MastraError(
|
|
462
|
+
{
|
|
463
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_UPDATE_VECTOR_FAILED",
|
|
464
|
+
domain: error.ErrorDomain.STORAGE,
|
|
465
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
466
|
+
details: { indexName }
|
|
467
|
+
},
|
|
468
|
+
error$1
|
|
469
|
+
);
|
|
367
470
|
}
|
|
368
471
|
}
|
|
369
472
|
/**
|
|
@@ -377,8 +480,16 @@ var TurbopufferVector = class extends vector.MastraVector {
|
|
|
377
480
|
try {
|
|
378
481
|
const namespace = this.client.namespace(indexName);
|
|
379
482
|
await namespace.delete({ ids: [id] });
|
|
380
|
-
} catch (error) {
|
|
381
|
-
throw new
|
|
483
|
+
} catch (error$1) {
|
|
484
|
+
throw new error.MastraError(
|
|
485
|
+
{
|
|
486
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_DELETE_VECTOR_FAILED",
|
|
487
|
+
domain: error.ErrorDomain.STORAGE,
|
|
488
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
489
|
+
details: { indexName }
|
|
490
|
+
},
|
|
491
|
+
error$1
|
|
492
|
+
);
|
|
382
493
|
}
|
|
383
494
|
}
|
|
384
495
|
};
|
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 { Turbopuffer } from '@turbopuffer/turbopuffer';
|
|
3
4
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
@@ -186,28 +187,40 @@ var TurbopufferVector = class extends MastraVector {
|
|
|
186
187
|
}
|
|
187
188
|
async createIndex({ indexName, dimension, metric }) {
|
|
188
189
|
metric = metric ?? "cosine";
|
|
189
|
-
if (this.createIndexCache.has(indexName)) {
|
|
190
|
-
const expected = this.createIndexCache.get(indexName);
|
|
191
|
-
if (dimension !== expected.dimension || metric !== expected.metric) {
|
|
192
|
-
throw new Error(
|
|
193
|
-
`createIndex() called more than once with inconsistent inputs. Index ${indexName} expected dimensions=${expected.dimension} and metric=${expected.metric} but got dimensions=${dimension} and metric=${metric}`
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (dimension <= 0) {
|
|
199
|
-
throw new Error("Dimension must be a positive integer");
|
|
200
|
-
}
|
|
201
190
|
let distanceMetric = "cosine_distance";
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
191
|
+
try {
|
|
192
|
+
if (this.createIndexCache.has(indexName)) {
|
|
193
|
+
const expected = this.createIndexCache.get(indexName);
|
|
194
|
+
if (dimension !== expected.dimension || metric !== expected.metric) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`createIndex() called more than once with inconsistent inputs. Index ${indexName} expected dimensions=${expected.dimension} and metric=${expected.metric} but got dimensions=${dimension} and metric=${metric}`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (dimension <= 0) {
|
|
202
|
+
throw new Error("Dimension must be a positive integer");
|
|
203
|
+
}
|
|
204
|
+
switch (metric) {
|
|
205
|
+
case "cosine":
|
|
206
|
+
distanceMetric = "cosine_distance";
|
|
207
|
+
break;
|
|
208
|
+
case "euclidean":
|
|
209
|
+
distanceMetric = "euclidean_squared";
|
|
210
|
+
break;
|
|
211
|
+
case "dotproduct":
|
|
212
|
+
throw new Error("dotproduct is not supported in Turbopuffer");
|
|
213
|
+
}
|
|
214
|
+
} catch (error) {
|
|
215
|
+
throw new MastraError(
|
|
216
|
+
{
|
|
217
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_CREATE_INDEX_INVALID_ARGS",
|
|
218
|
+
domain: ErrorDomain.STORAGE,
|
|
219
|
+
category: ErrorCategory.USER,
|
|
220
|
+
details: { indexName, dimension, metric }
|
|
221
|
+
},
|
|
222
|
+
error
|
|
223
|
+
);
|
|
211
224
|
}
|
|
212
225
|
this.createIndexCache.set(indexName, {
|
|
213
226
|
indexName,
|
|
@@ -217,15 +230,29 @@ var TurbopufferVector = class extends MastraVector {
|
|
|
217
230
|
});
|
|
218
231
|
}
|
|
219
232
|
async upsert({ indexName, vectors, metadata, ids }) {
|
|
233
|
+
let index;
|
|
234
|
+
let createIndex;
|
|
220
235
|
try {
|
|
221
236
|
if (vectors.length === 0) {
|
|
222
237
|
throw new Error("upsert() called with empty vectors");
|
|
223
238
|
}
|
|
224
|
-
|
|
225
|
-
|
|
239
|
+
index = this.client.namespace(indexName);
|
|
240
|
+
createIndex = this.createIndexCache.get(indexName);
|
|
226
241
|
if (!createIndex) {
|
|
227
242
|
throw new Error(`createIndex() not called for this index`);
|
|
228
243
|
}
|
|
244
|
+
} catch (error) {
|
|
245
|
+
throw new MastraError(
|
|
246
|
+
{
|
|
247
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_UPSERT_INVALID_ARGS",
|
|
248
|
+
domain: ErrorDomain.STORAGE,
|
|
249
|
+
category: ErrorCategory.USER,
|
|
250
|
+
details: { indexName }
|
|
251
|
+
},
|
|
252
|
+
error
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
229
256
|
const distanceMetric = createIndex.tpufDistanceMetric;
|
|
230
257
|
const vectorIds = ids || vectors.map(() => crypto.randomUUID());
|
|
231
258
|
const records = vectors.map((vector, i) => ({
|
|
@@ -253,21 +280,42 @@ var TurbopufferVector = class extends MastraVector {
|
|
|
253
280
|
}
|
|
254
281
|
return vectorIds;
|
|
255
282
|
} catch (error) {
|
|
256
|
-
throw new
|
|
283
|
+
throw new MastraError(
|
|
284
|
+
{
|
|
285
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_UPSERT_FAILED",
|
|
286
|
+
domain: ErrorDomain.STORAGE,
|
|
287
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
288
|
+
details: { indexName }
|
|
289
|
+
},
|
|
290
|
+
error
|
|
291
|
+
);
|
|
257
292
|
}
|
|
258
293
|
}
|
|
259
294
|
async query({ indexName, queryVector, topK, filter, includeVector }) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
295
|
+
let createIndex;
|
|
296
|
+
try {
|
|
297
|
+
const schemaConfig = this.opts.schemaConfigForIndex?.(indexName);
|
|
298
|
+
if (schemaConfig) {
|
|
299
|
+
if (queryVector.length !== schemaConfig.dimensions) {
|
|
300
|
+
throw new Error(
|
|
301
|
+
`Turbopuffer index ${indexName} was configured with dimensions=${schemaConfig.dimensions} but attempting to query with queryVector.length=${queryVector.length}`
|
|
302
|
+
);
|
|
303
|
+
}
|
|
266
304
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
305
|
+
createIndex = this.createIndexCache.get(indexName);
|
|
306
|
+
if (!createIndex) {
|
|
307
|
+
throw new Error(`createIndex() not called for this index`);
|
|
308
|
+
}
|
|
309
|
+
} catch (error) {
|
|
310
|
+
throw new MastraError(
|
|
311
|
+
{
|
|
312
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_QUERY_INVALID_ARGS",
|
|
313
|
+
domain: ErrorDomain.STORAGE,
|
|
314
|
+
category: ErrorCategory.USER,
|
|
315
|
+
details: { indexName }
|
|
316
|
+
},
|
|
317
|
+
error
|
|
318
|
+
);
|
|
271
319
|
}
|
|
272
320
|
const distanceMetric = createIndex.tpufDistanceMetric;
|
|
273
321
|
try {
|
|
@@ -290,7 +338,15 @@ var TurbopufferVector = class extends MastraVector {
|
|
|
290
338
|
...includeVector && item.vector ? { vector: item.vector } : {}
|
|
291
339
|
}));
|
|
292
340
|
} catch (error) {
|
|
293
|
-
throw new
|
|
341
|
+
throw new MastraError(
|
|
342
|
+
{
|
|
343
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_QUERY_FAILED",
|
|
344
|
+
domain: ErrorDomain.STORAGE,
|
|
345
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
346
|
+
details: { indexName }
|
|
347
|
+
},
|
|
348
|
+
error
|
|
349
|
+
);
|
|
294
350
|
}
|
|
295
351
|
}
|
|
296
352
|
async listIndexes() {
|
|
@@ -298,7 +354,14 @@ var TurbopufferVector = class extends MastraVector {
|
|
|
298
354
|
const namespacesResult = await this.client.namespaces({});
|
|
299
355
|
return namespacesResult.namespaces.map((namespace) => namespace.id);
|
|
300
356
|
} catch (error) {
|
|
301
|
-
throw new
|
|
357
|
+
throw new MastraError(
|
|
358
|
+
{
|
|
359
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_LIST_INDEXES_FAILED",
|
|
360
|
+
domain: ErrorDomain.STORAGE,
|
|
361
|
+
category: ErrorCategory.THIRD_PARTY
|
|
362
|
+
},
|
|
363
|
+
error
|
|
364
|
+
);
|
|
302
365
|
}
|
|
303
366
|
}
|
|
304
367
|
/**
|
|
@@ -323,7 +386,15 @@ var TurbopufferVector = class extends MastraVector {
|
|
|
323
386
|
metric: createIndex.metric
|
|
324
387
|
};
|
|
325
388
|
} catch (error) {
|
|
326
|
-
throw new
|
|
389
|
+
throw new MastraError(
|
|
390
|
+
{
|
|
391
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_DESCRIBE_INDEX_FAILED",
|
|
392
|
+
domain: ErrorDomain.STORAGE,
|
|
393
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
394
|
+
details: { indexName }
|
|
395
|
+
},
|
|
396
|
+
error
|
|
397
|
+
);
|
|
327
398
|
}
|
|
328
399
|
}
|
|
329
400
|
async deleteIndex({ indexName }) {
|
|
@@ -332,7 +403,15 @@ var TurbopufferVector = class extends MastraVector {
|
|
|
332
403
|
await namespace.deleteAll();
|
|
333
404
|
this.createIndexCache.delete(indexName);
|
|
334
405
|
} catch (error) {
|
|
335
|
-
throw new
|
|
406
|
+
throw new MastraError(
|
|
407
|
+
{
|
|
408
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_DELETE_INDEX_FAILED",
|
|
409
|
+
domain: ErrorDomain.STORAGE,
|
|
410
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
411
|
+
details: { indexName }
|
|
412
|
+
},
|
|
413
|
+
error
|
|
414
|
+
);
|
|
336
415
|
}
|
|
337
416
|
}
|
|
338
417
|
/**
|
|
@@ -346,22 +425,46 @@ var TurbopufferVector = class extends MastraVector {
|
|
|
346
425
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
347
426
|
*/
|
|
348
427
|
async updateVector({ indexName, id, update }) {
|
|
428
|
+
let namespace;
|
|
429
|
+
let createIndex;
|
|
430
|
+
let distanceMetric;
|
|
431
|
+
let record;
|
|
349
432
|
try {
|
|
350
|
-
|
|
351
|
-
|
|
433
|
+
namespace = this.client.namespace(indexName);
|
|
434
|
+
createIndex = this.createIndexCache.get(indexName);
|
|
352
435
|
if (!createIndex) {
|
|
353
436
|
throw new Error(`createIndex() not called for this index`);
|
|
354
437
|
}
|
|
355
|
-
|
|
356
|
-
|
|
438
|
+
distanceMetric = createIndex.tpufDistanceMetric;
|
|
439
|
+
record = { id };
|
|
357
440
|
if (update.vector) record.vector = update.vector;
|
|
358
441
|
if (update.metadata) record.attributes = update.metadata;
|
|
442
|
+
} catch (error) {
|
|
443
|
+
throw new MastraError(
|
|
444
|
+
{
|
|
445
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
446
|
+
domain: ErrorDomain.STORAGE,
|
|
447
|
+
category: ErrorCategory.USER,
|
|
448
|
+
details: { indexName }
|
|
449
|
+
},
|
|
450
|
+
error
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
try {
|
|
359
454
|
await namespace.upsert({
|
|
360
455
|
vectors: [record],
|
|
361
456
|
distance_metric: distanceMetric
|
|
362
457
|
});
|
|
363
458
|
} catch (error) {
|
|
364
|
-
throw new
|
|
459
|
+
throw new MastraError(
|
|
460
|
+
{
|
|
461
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_UPDATE_VECTOR_FAILED",
|
|
462
|
+
domain: ErrorDomain.STORAGE,
|
|
463
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
464
|
+
details: { indexName }
|
|
465
|
+
},
|
|
466
|
+
error
|
|
467
|
+
);
|
|
365
468
|
}
|
|
366
469
|
}
|
|
367
470
|
/**
|
|
@@ -376,7 +479,15 @@ var TurbopufferVector = class extends MastraVector {
|
|
|
376
479
|
const namespace = this.client.namespace(indexName);
|
|
377
480
|
await namespace.delete({ ids: [id] });
|
|
378
481
|
} catch (error) {
|
|
379
|
-
throw new
|
|
482
|
+
throw new MastraError(
|
|
483
|
+
{
|
|
484
|
+
id: "STORAGE_TURBOBUFFER_VECTOR_DELETE_VECTOR_FAILED",
|
|
485
|
+
domain: ErrorDomain.STORAGE,
|
|
486
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
487
|
+
details: { indexName }
|
|
488
|
+
},
|
|
489
|
+
error
|
|
490
|
+
);
|
|
380
491
|
}
|
|
381
492
|
}
|
|
382
493
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/turbopuffer",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4-alpha.0",
|
|
4
4
|
"description": "Turbopuffer vector store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"tsup": "^8.5.0",
|
|
34
34
|
"typescript": "^5.8.3",
|
|
35
35
|
"vitest": "^3.2.3",
|
|
36
|
-
"@internal/lint": "0.0.
|
|
37
|
-
"@mastra/core": "0.10.
|
|
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"
|