@mastra/turbopuffer 0.0.0-switch-to-core-20250424015131 → 0.0.0-vector-query-sources-20250516172905

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,12 +1,17 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
2
  import type { CreateIndexParams } from '@mastra/core/vector';
3
+ import type { DeleteIndexParams } from '@mastra/core/vector';
4
+ import type { DeleteVectorParams } from '@mastra/core/vector';
5
+ import type { DescribeIndexParams } from '@mastra/core/vector';
3
6
  import type { Filters } from '@turbopuffer/turbopuffer';
4
7
  import type { IndexStats } from '@mastra/core/vector';
5
8
  import { MastraVector } from '@mastra/core/vector';
6
9
  import type { OperatorSupport } from '@mastra/core/vector/filter';
10
+ import type { ParamsToArgs } from '@mastra/core/vector';
7
11
  import type { QueryResult } from '@mastra/core/vector';
8
12
  import type { QueryVectorParams } from '@mastra/core/vector';
9
13
  import type { Schema } from '@turbopuffer/turbopuffer';
14
+ import type { UpdateVectorParams } from '@mastra/core/vector';
10
15
  import type { UpsertVectorParams } from '@mastra/core/vector';
11
16
  import type { VectorFilter } from '@mastra/core/vector/filter';
12
17
 
@@ -62,8 +67,34 @@ declare class TurbopufferVector extends MastraVector {
62
67
  upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
63
68
  query({ indexName, queryVector, topK, filter, includeVector }: QueryVectorParams): Promise<QueryResult[]>;
64
69
  listIndexes(): Promise<string[]>;
65
- describeIndex(indexName: string): Promise<IndexStats>;
66
- deleteIndex(indexName: string): Promise<void>;
70
+ /**
71
+ * Retrieves statistics about a vector index.
72
+ *
73
+ * @param params - The parameters for describing an index
74
+ * @param params.indexName - The name of the index to describe
75
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
76
+ */
77
+ describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
78
+ deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
79
+ /**
80
+ * Updates a vector by its ID with the provided vector and/or metadata.
81
+ * @param indexName - The name of the index containing the vector.
82
+ * @param id - The ID of the vector to update.
83
+ * @param update - An object containing the vector and/or metadata to update.
84
+ * @param update.vector - An optional array of numbers representing the new vector.
85
+ * @param update.metadata - An optional record containing the new metadata.
86
+ * @returns A promise that resolves when the update is complete.
87
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
88
+ */
89
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
90
+ /**
91
+ * Deletes a vector by its ID.
92
+ * @param indexName - The name of the index containing the vector.
93
+ * @param id - The ID of the vector to delete.
94
+ * @returns A promise that resolves when the deletion is complete.
95
+ * @throws Will throw an error if the deletion operation fails.
96
+ */
97
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
67
98
  }
68
99
  export { TurbopufferVector }
69
100
  export { TurbopufferVector as TurbopufferVector_alias_1 }
@@ -1,12 +1,17 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
2
  import type { CreateIndexParams } from '@mastra/core/vector';
3
+ import type { DeleteIndexParams } from '@mastra/core/vector';
4
+ import type { DeleteVectorParams } from '@mastra/core/vector';
5
+ import type { DescribeIndexParams } from '@mastra/core/vector';
3
6
  import type { Filters } from '@turbopuffer/turbopuffer';
4
7
  import type { IndexStats } from '@mastra/core/vector';
5
8
  import { MastraVector } from '@mastra/core/vector';
6
9
  import type { OperatorSupport } from '@mastra/core/vector/filter';
10
+ import type { ParamsToArgs } from '@mastra/core/vector';
7
11
  import type { QueryResult } from '@mastra/core/vector';
8
12
  import type { QueryVectorParams } from '@mastra/core/vector';
9
13
  import type { Schema } from '@turbopuffer/turbopuffer';
14
+ import type { UpdateVectorParams } from '@mastra/core/vector';
10
15
  import type { UpsertVectorParams } from '@mastra/core/vector';
11
16
  import type { VectorFilter } from '@mastra/core/vector/filter';
12
17
 
@@ -62,8 +67,34 @@ declare class TurbopufferVector extends MastraVector {
62
67
  upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
63
68
  query({ indexName, queryVector, topK, filter, includeVector }: QueryVectorParams): Promise<QueryResult[]>;
64
69
  listIndexes(): Promise<string[]>;
65
- describeIndex(indexName: string): Promise<IndexStats>;
66
- deleteIndex(indexName: string): Promise<void>;
70
+ /**
71
+ * Retrieves statistics about a vector index.
72
+ *
73
+ * @param params - The parameters for describing an index
74
+ * @param params.indexName - The name of the index to describe
75
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
76
+ */
77
+ describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
78
+ deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
79
+ /**
80
+ * Updates a vector by its ID with the provided vector and/or metadata.
81
+ * @param indexName - The name of the index containing the vector.
82
+ * @param id - The ID of the vector to update.
83
+ * @param update - An object containing the vector and/or metadata to update.
84
+ * @param update.vector - An optional array of numbers representing the new vector.
85
+ * @param update.metadata - An optional record containing the new metadata.
86
+ * @returns A promise that resolves when the update is complete.
87
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
88
+ */
89
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
90
+ /**
91
+ * Deletes a vector by its ID.
92
+ * @param indexName - The name of the index containing the vector.
93
+ * @param id - The ID of the vector to delete.
94
+ * @returns A promise that resolves when the deletion is complete.
95
+ * @throws Will throw an error if the deletion operation fails.
96
+ */
97
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
67
98
  }
68
99
  export { TurbopufferVector }
69
100
  export { TurbopufferVector as TurbopufferVector_alias_1 }
package/dist/index.cjs CHANGED
@@ -303,7 +303,16 @@ var TurbopufferVector = class extends vector.MastraVector {
303
303
  throw new Error(`Failed to list Turbopuffer namespaces: ${error}`);
304
304
  }
305
305
  }
306
- async describeIndex(indexName) {
306
+ /**
307
+ * Retrieves statistics about a vector index.
308
+ *
309
+ * @param params - The parameters for describing an index
310
+ * @param params.indexName - The name of the index to describe
311
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
312
+ */
313
+ async describeIndex(...args) {
314
+ const params = this.normalizeArgs("describeIndex", args);
315
+ const { indexName } = params;
307
316
  try {
308
317
  const namespace = this.client.namespace(indexName);
309
318
  const metadata = await namespace.metadata();
@@ -322,7 +331,9 @@ var TurbopufferVector = class extends vector.MastraVector {
322
331
  throw new Error(`Failed to describe Turbopuffer namespace ${indexName}: ${error}`);
323
332
  }
324
333
  }
325
- async deleteIndex(indexName) {
334
+ async deleteIndex(...args) {
335
+ const params = this.normalizeArgs("deleteIndex", args);
336
+ const { indexName } = params;
326
337
  try {
327
338
  const namespace = this.client.namespace(indexName);
328
339
  await namespace.deleteAll();
@@ -331,6 +342,54 @@ var TurbopufferVector = class extends vector.MastraVector {
331
342
  throw new Error(`Failed to delete Turbopuffer namespace ${indexName}: ${error.message}`);
332
343
  }
333
344
  }
345
+ /**
346
+ * Updates a vector by its ID with the provided vector and/or metadata.
347
+ * @param indexName - The name of the index containing the vector.
348
+ * @param id - The ID of the vector to update.
349
+ * @param update - An object containing the vector and/or metadata to update.
350
+ * @param update.vector - An optional array of numbers representing the new vector.
351
+ * @param update.metadata - An optional record containing the new metadata.
352
+ * @returns A promise that resolves when the update is complete.
353
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
354
+ */
355
+ async updateVector(...args) {
356
+ const params = this.normalizeArgs("updateVector", args);
357
+ const { indexName, id, update } = params;
358
+ try {
359
+ const namespace = this.client.namespace(indexName);
360
+ const createIndex = this.createIndexCache.get(indexName);
361
+ if (!createIndex) {
362
+ throw new Error(`createIndex() not called for this index`);
363
+ }
364
+ const distanceMetric = createIndex.tpufDistanceMetric;
365
+ const record = { id };
366
+ if (update.vector) record.vector = update.vector;
367
+ if (update.metadata) record.attributes = update.metadata;
368
+ await namespace.upsert({
369
+ vectors: [record],
370
+ distance_metric: distanceMetric
371
+ });
372
+ } catch (error) {
373
+ throw new Error(`Failed to update Turbopuffer namespace ${indexName}: ${error.message}`);
374
+ }
375
+ }
376
+ /**
377
+ * Deletes a vector by its ID.
378
+ * @param indexName - The name of the index containing the vector.
379
+ * @param id - The ID of the vector to delete.
380
+ * @returns A promise that resolves when the deletion is complete.
381
+ * @throws Will throw an error if the deletion operation fails.
382
+ */
383
+ async deleteVector(...args) {
384
+ const params = this.normalizeArgs("deleteVector", args);
385
+ const { indexName, id } = params;
386
+ try {
387
+ const namespace = this.client.namespace(indexName);
388
+ await namespace.delete({ ids: [id] });
389
+ } catch (error) {
390
+ throw new Error(`Failed to delete Turbopuffer namespace ${indexName}: ${error.message}`);
391
+ }
392
+ }
334
393
  };
335
394
 
336
395
  exports.TurbopufferVector = TurbopufferVector;
package/dist/index.js CHANGED
@@ -301,7 +301,16 @@ var TurbopufferVector = class extends MastraVector {
301
301
  throw new Error(`Failed to list Turbopuffer namespaces: ${error}`);
302
302
  }
303
303
  }
304
- async describeIndex(indexName) {
304
+ /**
305
+ * Retrieves statistics about a vector index.
306
+ *
307
+ * @param params - The parameters for describing an index
308
+ * @param params.indexName - The name of the index to describe
309
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
310
+ */
311
+ async describeIndex(...args) {
312
+ const params = this.normalizeArgs("describeIndex", args);
313
+ const { indexName } = params;
305
314
  try {
306
315
  const namespace = this.client.namespace(indexName);
307
316
  const metadata = await namespace.metadata();
@@ -320,7 +329,9 @@ var TurbopufferVector = class extends MastraVector {
320
329
  throw new Error(`Failed to describe Turbopuffer namespace ${indexName}: ${error}`);
321
330
  }
322
331
  }
323
- async deleteIndex(indexName) {
332
+ async deleteIndex(...args) {
333
+ const params = this.normalizeArgs("deleteIndex", args);
334
+ const { indexName } = params;
324
335
  try {
325
336
  const namespace = this.client.namespace(indexName);
326
337
  await namespace.deleteAll();
@@ -329,6 +340,54 @@ var TurbopufferVector = class extends MastraVector {
329
340
  throw new Error(`Failed to delete Turbopuffer namespace ${indexName}: ${error.message}`);
330
341
  }
331
342
  }
343
+ /**
344
+ * Updates a vector by its ID with the provided vector and/or metadata.
345
+ * @param indexName - The name of the index containing the vector.
346
+ * @param id - The ID of the vector to update.
347
+ * @param update - An object containing the vector and/or metadata to update.
348
+ * @param update.vector - An optional array of numbers representing the new vector.
349
+ * @param update.metadata - An optional record containing the new metadata.
350
+ * @returns A promise that resolves when the update is complete.
351
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
352
+ */
353
+ async updateVector(...args) {
354
+ const params = this.normalizeArgs("updateVector", args);
355
+ const { indexName, id, update } = params;
356
+ try {
357
+ const namespace = this.client.namespace(indexName);
358
+ const createIndex = this.createIndexCache.get(indexName);
359
+ if (!createIndex) {
360
+ throw new Error(`createIndex() not called for this index`);
361
+ }
362
+ const distanceMetric = createIndex.tpufDistanceMetric;
363
+ const record = { id };
364
+ if (update.vector) record.vector = update.vector;
365
+ if (update.metadata) record.attributes = update.metadata;
366
+ await namespace.upsert({
367
+ vectors: [record],
368
+ distance_metric: distanceMetric
369
+ });
370
+ } catch (error) {
371
+ throw new Error(`Failed to update Turbopuffer namespace ${indexName}: ${error.message}`);
372
+ }
373
+ }
374
+ /**
375
+ * Deletes a vector by its ID.
376
+ * @param indexName - The name of the index containing the vector.
377
+ * @param id - The ID of the vector to delete.
378
+ * @returns A promise that resolves when the deletion is complete.
379
+ * @throws Will throw an error if the deletion operation fails.
380
+ */
381
+ async deleteVector(...args) {
382
+ const params = this.normalizeArgs("deleteVector", args);
383
+ const { indexName, id } = params;
384
+ try {
385
+ const namespace = this.client.namespace(indexName);
386
+ await namespace.delete({ ids: [id] });
387
+ } catch (error) {
388
+ throw new Error(`Failed to delete Turbopuffer namespace ${indexName}: ${error.message}`);
389
+ }
390
+ }
332
391
  };
333
392
 
334
393
  export { TurbopufferVector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/turbopuffer",
3
- "version": "0.0.0-switch-to-core-20250424015131",
3
+ "version": "0.0.0-vector-query-sources-20250516172905",
4
4
  "description": "Turbopuffer vector store provider for Mastra",
5
5
  "type": "module",
6
6
  "files": [
@@ -24,17 +24,17 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@turbopuffer/turbopuffer": "^0.6.4",
27
- "@mastra/core": "0.0.0-switch-to-core-20250424015131"
27
+ "@mastra/core": "0.0.0-vector-query-sources-20250516172905"
28
28
  },
29
29
  "devDependencies": {
30
- "@microsoft/api-extractor": "^7.52.1",
30
+ "@microsoft/api-extractor": "^7.52.5",
31
31
  "@types/node": "^20.17.27",
32
32
  "dotenv": "^16.4.7",
33
33
  "eslint": "^9.23.0",
34
34
  "tsup": "^8.4.0",
35
35
  "typescript": "^5.8.2",
36
- "vitest": "^3.0.9",
37
- "@internal/lint": "0.0.2"
36
+ "vitest": "^3.1.2",
37
+ "@internal/lint": "0.0.0-vector-query-sources-20250516172905"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",