@mastra/lance 0.0.0-fix-generate-title-20250616171351 → 0.0.0-fix-fetch-workflow-runs-20250624231457
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/CHANGELOG.md +90 -3
- package/dist/_tsup-dts-rollup.d.cts +28 -4
- package/dist/_tsup-dts-rollup.d.ts +28 -4
- package/dist/index.cjs +806 -160
- package/dist/index.js +773 -127
- package/package.json +6 -6
- package/src/storage/index.test.ts +72 -2
- package/src/storage/index.ts +498 -68
- package/src/vector/filter.test.ts +3 -3
- package/src/vector/filter.ts +24 -4
- package/src/vector/index.test.ts +3 -3
- package/src/vector/index.ts +320 -79
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { connect, Index } from '@lancedb/lancedb';
|
|
2
2
|
import { MessageList } from '@mastra/core/agent';
|
|
3
|
+
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
4
|
import { MastraStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_TRACES, TABLE_EVALS, TABLE_WORKFLOW_SNAPSHOT } from '@mastra/core/storage';
|
|
4
5
|
import { Utf8, Float64, Binary, Float32, Int32, Field, Schema } from 'apache-arrow';
|
|
5
6
|
import { MastraVector } from '@mastra/core/vector';
|
|
@@ -36,8 +37,26 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
36
37
|
instance.lanceClient = await connect(uri, options);
|
|
37
38
|
return instance;
|
|
38
39
|
} catch (e) {
|
|
39
|
-
throw new
|
|
40
|
+
throw new MastraError(
|
|
41
|
+
{
|
|
42
|
+
id: "STORAGE_LANCE_STORAGE_CONNECT_FAILED",
|
|
43
|
+
domain: ErrorDomain.STORAGE,
|
|
44
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
45
|
+
text: `Failed to connect to LanceDB: ${e.message || e}`,
|
|
46
|
+
details: { uri, optionsProvided: !!options }
|
|
47
|
+
},
|
|
48
|
+
e
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
getPrimaryKeys(tableName) {
|
|
53
|
+
let primaryId = ["id"];
|
|
54
|
+
if (tableName === TABLE_WORKFLOW_SNAPSHOT) {
|
|
55
|
+
primaryId = ["workflow_name", "run_id"];
|
|
56
|
+
} else if (tableName === TABLE_EVALS) {
|
|
57
|
+
primaryId = ["agent_name", "metric_name", "run_id"];
|
|
40
58
|
}
|
|
59
|
+
return primaryId;
|
|
41
60
|
}
|
|
42
61
|
/**
|
|
43
62
|
* @internal
|
|
@@ -50,11 +69,40 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
50
69
|
tableName,
|
|
51
70
|
schema
|
|
52
71
|
}) {
|
|
72
|
+
try {
|
|
73
|
+
if (!this.lanceClient) {
|
|
74
|
+
throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
|
|
75
|
+
}
|
|
76
|
+
if (!tableName) {
|
|
77
|
+
throw new Error("tableName is required for createTable.");
|
|
78
|
+
}
|
|
79
|
+
if (!schema) {
|
|
80
|
+
throw new Error("schema is required for createTable.");
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw new MastraError(
|
|
84
|
+
{
|
|
85
|
+
id: "STORAGE_LANCE_STORAGE_CREATE_TABLE_INVALID_ARGS",
|
|
86
|
+
domain: ErrorDomain.STORAGE,
|
|
87
|
+
category: ErrorCategory.USER,
|
|
88
|
+
details: { tableName }
|
|
89
|
+
},
|
|
90
|
+
error
|
|
91
|
+
);
|
|
92
|
+
}
|
|
53
93
|
try {
|
|
54
94
|
const arrowSchema = this.translateSchema(schema);
|
|
55
95
|
await this.lanceClient.createEmptyTable(tableName, arrowSchema);
|
|
56
96
|
} catch (error) {
|
|
57
|
-
throw new
|
|
97
|
+
throw new MastraError(
|
|
98
|
+
{
|
|
99
|
+
id: "STORAGE_LANCE_STORAGE_CREATE_TABLE_FAILED",
|
|
100
|
+
domain: ErrorDomain.STORAGE,
|
|
101
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
102
|
+
details: { tableName }
|
|
103
|
+
},
|
|
104
|
+
error
|
|
105
|
+
);
|
|
58
106
|
}
|
|
59
107
|
}
|
|
60
108
|
translateSchema(schema) {
|
|
@@ -97,14 +145,41 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
97
145
|
* @param tableName Name of the table to drop
|
|
98
146
|
*/
|
|
99
147
|
async dropTable(tableName) {
|
|
148
|
+
try {
|
|
149
|
+
if (!this.lanceClient) {
|
|
150
|
+
throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
|
|
151
|
+
}
|
|
152
|
+
if (!tableName) {
|
|
153
|
+
throw new Error("tableName is required for dropTable.");
|
|
154
|
+
}
|
|
155
|
+
} catch (validationError) {
|
|
156
|
+
throw new MastraError(
|
|
157
|
+
{
|
|
158
|
+
id: "STORAGE_LANCE_STORAGE_DROP_TABLE_INVALID_ARGS",
|
|
159
|
+
domain: ErrorDomain.STORAGE,
|
|
160
|
+
category: ErrorCategory.USER,
|
|
161
|
+
text: validationError.message,
|
|
162
|
+
details: { tableName }
|
|
163
|
+
},
|
|
164
|
+
validationError
|
|
165
|
+
);
|
|
166
|
+
}
|
|
100
167
|
try {
|
|
101
168
|
await this.lanceClient.dropTable(tableName);
|
|
102
169
|
} catch (error) {
|
|
103
|
-
if (error.toString().includes("was not found")) {
|
|
170
|
+
if (error.toString().includes("was not found") || error.message?.includes("Table not found")) {
|
|
104
171
|
this.logger.debug(`Table '${tableName}' does not exist, skipping drop`);
|
|
105
172
|
return;
|
|
106
173
|
}
|
|
107
|
-
throw new
|
|
174
|
+
throw new MastraError(
|
|
175
|
+
{
|
|
176
|
+
id: "STORAGE_LANCE_STORAGE_DROP_TABLE_FAILED",
|
|
177
|
+
domain: ErrorDomain.STORAGE,
|
|
178
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
179
|
+
details: { tableName }
|
|
180
|
+
},
|
|
181
|
+
error
|
|
182
|
+
);
|
|
108
183
|
}
|
|
109
184
|
}
|
|
110
185
|
/**
|
|
@@ -113,6 +188,25 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
113
188
|
* @returns Table schema
|
|
114
189
|
*/
|
|
115
190
|
async getTableSchema(tableName) {
|
|
191
|
+
try {
|
|
192
|
+
if (!this.lanceClient) {
|
|
193
|
+
throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
|
|
194
|
+
}
|
|
195
|
+
if (!tableName) {
|
|
196
|
+
throw new Error("tableName is required for getTableSchema.");
|
|
197
|
+
}
|
|
198
|
+
} catch (validationError) {
|
|
199
|
+
throw new MastraError(
|
|
200
|
+
{
|
|
201
|
+
id: "STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_INVALID_ARGS",
|
|
202
|
+
domain: ErrorDomain.STORAGE,
|
|
203
|
+
category: ErrorCategory.USER,
|
|
204
|
+
text: validationError.message,
|
|
205
|
+
details: { tableName }
|
|
206
|
+
},
|
|
207
|
+
validationError
|
|
208
|
+
);
|
|
209
|
+
}
|
|
116
210
|
try {
|
|
117
211
|
const table = await this.lanceClient.openTable(tableName);
|
|
118
212
|
const rawSchema = await table.schema();
|
|
@@ -125,7 +219,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
125
219
|
}
|
|
126
220
|
};
|
|
127
221
|
} catch (error) {
|
|
128
|
-
throw new
|
|
222
|
+
throw new MastraError(
|
|
223
|
+
{
|
|
224
|
+
id: "STORAGE_LANCE_STORAGE_GET_TABLE_SCHEMA_FAILED",
|
|
225
|
+
domain: ErrorDomain.STORAGE,
|
|
226
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
227
|
+
details: { tableName }
|
|
228
|
+
},
|
|
229
|
+
error
|
|
230
|
+
);
|
|
129
231
|
}
|
|
130
232
|
}
|
|
131
233
|
getDefaultValue(type) {
|
|
@@ -156,32 +258,101 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
156
258
|
schema,
|
|
157
259
|
ifNotExists
|
|
158
260
|
}) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
261
|
+
try {
|
|
262
|
+
if (!this.lanceClient) {
|
|
263
|
+
throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
|
|
264
|
+
}
|
|
265
|
+
if (!tableName) {
|
|
266
|
+
throw new Error("tableName is required for alterTable.");
|
|
267
|
+
}
|
|
268
|
+
if (!schema) {
|
|
269
|
+
throw new Error("schema is required for alterTable.");
|
|
270
|
+
}
|
|
271
|
+
if (!ifNotExists || ifNotExists.length === 0) {
|
|
272
|
+
this.logger.debug("No columns specified to add in alterTable, skipping.");
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
} catch (validationError) {
|
|
276
|
+
throw new MastraError(
|
|
277
|
+
{
|
|
278
|
+
id: "STORAGE_LANCE_STORAGE_ALTER_TABLE_INVALID_ARGS",
|
|
279
|
+
domain: ErrorDomain.STORAGE,
|
|
280
|
+
category: ErrorCategory.USER,
|
|
281
|
+
text: validationError.message,
|
|
282
|
+
details: { tableName }
|
|
283
|
+
},
|
|
284
|
+
validationError
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
const table = await this.lanceClient.openTable(tableName);
|
|
289
|
+
const currentSchema = await table.schema();
|
|
290
|
+
const existingFields = new Set(currentSchema.fields.map((f) => f.name));
|
|
291
|
+
const typeMap = {
|
|
292
|
+
text: "string",
|
|
293
|
+
integer: "int",
|
|
294
|
+
bigint: "bigint",
|
|
295
|
+
timestamp: "timestamp",
|
|
296
|
+
jsonb: "string",
|
|
297
|
+
uuid: "string"
|
|
175
298
|
};
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
299
|
+
const columnsToAdd = ifNotExists.filter((col) => schema[col] && !existingFields.has(col)).map((col) => {
|
|
300
|
+
const colDef = schema[col];
|
|
301
|
+
return {
|
|
302
|
+
name: col,
|
|
303
|
+
valueSql: colDef?.nullable ? `cast(NULL as ${typeMap[colDef.type ?? "text"]})` : `cast(${this.getDefaultValue(colDef?.type ?? "text")} as ${typeMap[colDef?.type ?? "text"]})`
|
|
304
|
+
};
|
|
305
|
+
});
|
|
306
|
+
if (columnsToAdd.length > 0) {
|
|
307
|
+
await table.addColumns(columnsToAdd);
|
|
308
|
+
this.logger?.info?.(`Added columns [${columnsToAdd.map((c) => c.name).join(", ")}] to table ${tableName}`);
|
|
309
|
+
}
|
|
310
|
+
} catch (error) {
|
|
311
|
+
throw new MastraError(
|
|
312
|
+
{
|
|
313
|
+
id: "STORAGE_LANCE_STORAGE_ALTER_TABLE_FAILED",
|
|
314
|
+
domain: ErrorDomain.STORAGE,
|
|
315
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
316
|
+
details: { tableName }
|
|
317
|
+
},
|
|
318
|
+
error
|
|
319
|
+
);
|
|
180
320
|
}
|
|
181
321
|
}
|
|
182
322
|
async clearTable({ tableName }) {
|
|
183
|
-
|
|
184
|
-
|
|
323
|
+
try {
|
|
324
|
+
if (!this.lanceClient) {
|
|
325
|
+
throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
|
|
326
|
+
}
|
|
327
|
+
if (!tableName) {
|
|
328
|
+
throw new Error("tableName is required for clearTable.");
|
|
329
|
+
}
|
|
330
|
+
} catch (validationError) {
|
|
331
|
+
throw new MastraError(
|
|
332
|
+
{
|
|
333
|
+
id: "STORAGE_LANCE_STORAGE_CLEAR_TABLE_INVALID_ARGS",
|
|
334
|
+
domain: ErrorDomain.STORAGE,
|
|
335
|
+
category: ErrorCategory.USER,
|
|
336
|
+
text: validationError.message,
|
|
337
|
+
details: { tableName }
|
|
338
|
+
},
|
|
339
|
+
validationError
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
try {
|
|
343
|
+
const table = await this.lanceClient.openTable(tableName);
|
|
344
|
+
await table.delete("1=1");
|
|
345
|
+
} catch (error) {
|
|
346
|
+
throw new MastraError(
|
|
347
|
+
{
|
|
348
|
+
id: "STORAGE_LANCE_STORAGE_CLEAR_TABLE_FAILED",
|
|
349
|
+
domain: ErrorDomain.STORAGE,
|
|
350
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
351
|
+
details: { tableName }
|
|
352
|
+
},
|
|
353
|
+
error
|
|
354
|
+
);
|
|
355
|
+
}
|
|
185
356
|
}
|
|
186
357
|
/**
|
|
187
358
|
* Insert a single record into a table. This function overwrites the existing record if it exists. Use this function for inserting records into tables with custom schemas.
|
|
@@ -189,8 +360,31 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
189
360
|
* @param record The record to insert.
|
|
190
361
|
*/
|
|
191
362
|
async insert({ tableName, record }) {
|
|
363
|
+
try {
|
|
364
|
+
if (!this.lanceClient) {
|
|
365
|
+
throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
|
|
366
|
+
}
|
|
367
|
+
if (!tableName) {
|
|
368
|
+
throw new Error("tableName is required for insert.");
|
|
369
|
+
}
|
|
370
|
+
if (!record || Object.keys(record).length === 0) {
|
|
371
|
+
throw new Error("record is required and cannot be empty for insert.");
|
|
372
|
+
}
|
|
373
|
+
} catch (validationError) {
|
|
374
|
+
throw new MastraError(
|
|
375
|
+
{
|
|
376
|
+
id: "STORAGE_LANCE_STORAGE_INSERT_INVALID_ARGS",
|
|
377
|
+
domain: ErrorDomain.STORAGE,
|
|
378
|
+
category: ErrorCategory.USER,
|
|
379
|
+
text: validationError.message,
|
|
380
|
+
details: { tableName }
|
|
381
|
+
},
|
|
382
|
+
validationError
|
|
383
|
+
);
|
|
384
|
+
}
|
|
192
385
|
try {
|
|
193
386
|
const table = await this.lanceClient.openTable(tableName);
|
|
387
|
+
const primaryId = this.getPrimaryKeys(tableName);
|
|
194
388
|
const processedRecord = { ...record };
|
|
195
389
|
for (const key in processedRecord) {
|
|
196
390
|
if (processedRecord[key] !== null && typeof processedRecord[key] === "object" && !(processedRecord[key] instanceof Date)) {
|
|
@@ -198,9 +392,17 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
198
392
|
processedRecord[key] = JSON.stringify(processedRecord[key]);
|
|
199
393
|
}
|
|
200
394
|
}
|
|
201
|
-
await table.
|
|
395
|
+
await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([processedRecord]);
|
|
202
396
|
} catch (error) {
|
|
203
|
-
throw new
|
|
397
|
+
throw new MastraError(
|
|
398
|
+
{
|
|
399
|
+
id: "STORAGE_LANCE_STORAGE_INSERT_FAILED",
|
|
400
|
+
domain: ErrorDomain.STORAGE,
|
|
401
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
402
|
+
details: { tableName }
|
|
403
|
+
},
|
|
404
|
+
error
|
|
405
|
+
);
|
|
204
406
|
}
|
|
205
407
|
}
|
|
206
408
|
/**
|
|
@@ -209,8 +411,31 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
209
411
|
* @param records The records to insert.
|
|
210
412
|
*/
|
|
211
413
|
async batchInsert({ tableName, records }) {
|
|
414
|
+
try {
|
|
415
|
+
if (!this.lanceClient) {
|
|
416
|
+
throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
|
|
417
|
+
}
|
|
418
|
+
if (!tableName) {
|
|
419
|
+
throw new Error("tableName is required for batchInsert.");
|
|
420
|
+
}
|
|
421
|
+
if (!records || records.length === 0) {
|
|
422
|
+
throw new Error("records array is required and cannot be empty for batchInsert.");
|
|
423
|
+
}
|
|
424
|
+
} catch (validationError) {
|
|
425
|
+
throw new MastraError(
|
|
426
|
+
{
|
|
427
|
+
id: "STORAGE_LANCE_STORAGE_BATCH_INSERT_INVALID_ARGS",
|
|
428
|
+
domain: ErrorDomain.STORAGE,
|
|
429
|
+
category: ErrorCategory.USER,
|
|
430
|
+
text: validationError.message,
|
|
431
|
+
details: { tableName }
|
|
432
|
+
},
|
|
433
|
+
validationError
|
|
434
|
+
);
|
|
435
|
+
}
|
|
212
436
|
try {
|
|
213
437
|
const table = await this.lanceClient.openTable(tableName);
|
|
438
|
+
const primaryId = this.getPrimaryKeys(tableName);
|
|
214
439
|
const processedRecords = records.map((record) => {
|
|
215
440
|
const processedRecord = { ...record };
|
|
216
441
|
for (const key in processedRecord) {
|
|
@@ -221,9 +446,17 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
221
446
|
}
|
|
222
447
|
return processedRecord;
|
|
223
448
|
});
|
|
224
|
-
await table.
|
|
449
|
+
await table.mergeInsert(primaryId).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(processedRecords);
|
|
225
450
|
} catch (error) {
|
|
226
|
-
throw new
|
|
451
|
+
throw new MastraError(
|
|
452
|
+
{
|
|
453
|
+
id: "STORAGE_LANCE_STORAGE_BATCH_INSERT_FAILED",
|
|
454
|
+
domain: ErrorDomain.STORAGE,
|
|
455
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
456
|
+
details: { tableName }
|
|
457
|
+
},
|
|
458
|
+
error
|
|
459
|
+
);
|
|
227
460
|
}
|
|
228
461
|
}
|
|
229
462
|
/**
|
|
@@ -234,6 +467,28 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
234
467
|
* @returns The loaded record with proper type conversions, or null if not found
|
|
235
468
|
*/
|
|
236
469
|
async load({ tableName, keys }) {
|
|
470
|
+
try {
|
|
471
|
+
if (!this.lanceClient) {
|
|
472
|
+
throw new Error("LanceDB client not initialized. Call LanceStorage.create() first.");
|
|
473
|
+
}
|
|
474
|
+
if (!tableName) {
|
|
475
|
+
throw new Error("tableName is required for load.");
|
|
476
|
+
}
|
|
477
|
+
if (!keys || Object.keys(keys).length === 0) {
|
|
478
|
+
throw new Error("keys are required and cannot be empty for load.");
|
|
479
|
+
}
|
|
480
|
+
} catch (validationError) {
|
|
481
|
+
throw new MastraError(
|
|
482
|
+
{
|
|
483
|
+
id: "STORAGE_LANCE_STORAGE_LOAD_INVALID_ARGS",
|
|
484
|
+
domain: ErrorDomain.STORAGE,
|
|
485
|
+
category: ErrorCategory.USER,
|
|
486
|
+
text: validationError.message,
|
|
487
|
+
details: { tableName }
|
|
488
|
+
},
|
|
489
|
+
validationError
|
|
490
|
+
);
|
|
491
|
+
}
|
|
237
492
|
try {
|
|
238
493
|
const table = await this.lanceClient.openTable(tableName);
|
|
239
494
|
const tableSchema = await this.getTableSchema(tableName);
|
|
@@ -261,7 +516,16 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
261
516
|
}
|
|
262
517
|
return this.processResultWithTypeConversion(result[0], tableSchema);
|
|
263
518
|
} catch (error) {
|
|
264
|
-
|
|
519
|
+
if (error instanceof MastraError) throw error;
|
|
520
|
+
throw new MastraError(
|
|
521
|
+
{
|
|
522
|
+
id: "STORAGE_LANCE_STORAGE_LOAD_FAILED",
|
|
523
|
+
domain: ErrorDomain.STORAGE,
|
|
524
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
525
|
+
details: { tableName, keyCount: Object.keys(keys).length, firstKey: Object.keys(keys)[0] ?? "" }
|
|
526
|
+
},
|
|
527
|
+
error
|
|
528
|
+
);
|
|
265
529
|
}
|
|
266
530
|
}
|
|
267
531
|
/**
|
|
@@ -336,7 +600,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
336
600
|
try {
|
|
337
601
|
return this.load({ tableName: TABLE_THREADS, keys: { id: threadId } });
|
|
338
602
|
} catch (error) {
|
|
339
|
-
throw new
|
|
603
|
+
throw new MastraError(
|
|
604
|
+
{
|
|
605
|
+
id: "LANCE_STORE_GET_THREAD_BY_ID_FAILED",
|
|
606
|
+
domain: ErrorDomain.STORAGE,
|
|
607
|
+
category: ErrorCategory.THIRD_PARTY
|
|
608
|
+
},
|
|
609
|
+
error
|
|
610
|
+
);
|
|
340
611
|
}
|
|
341
612
|
}
|
|
342
613
|
async getThreadsByResourceId({ resourceId }) {
|
|
@@ -349,7 +620,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
349
620
|
await this.getTableSchema(TABLE_THREADS)
|
|
350
621
|
);
|
|
351
622
|
} catch (error) {
|
|
352
|
-
throw new
|
|
623
|
+
throw new MastraError(
|
|
624
|
+
{
|
|
625
|
+
id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED",
|
|
626
|
+
domain: ErrorDomain.STORAGE,
|
|
627
|
+
category: ErrorCategory.THIRD_PARTY
|
|
628
|
+
},
|
|
629
|
+
error
|
|
630
|
+
);
|
|
353
631
|
}
|
|
354
632
|
}
|
|
355
633
|
/**
|
|
@@ -364,7 +642,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
364
642
|
await table.add([record], { mode: "append" });
|
|
365
643
|
return thread;
|
|
366
644
|
} catch (error) {
|
|
367
|
-
throw new
|
|
645
|
+
throw new MastraError(
|
|
646
|
+
{
|
|
647
|
+
id: "LANCE_STORE_SAVE_THREAD_FAILED",
|
|
648
|
+
domain: ErrorDomain.STORAGE,
|
|
649
|
+
category: ErrorCategory.THIRD_PARTY
|
|
650
|
+
},
|
|
651
|
+
error
|
|
652
|
+
);
|
|
368
653
|
}
|
|
369
654
|
}
|
|
370
655
|
async updateThread({
|
|
@@ -375,7 +660,7 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
375
660
|
try {
|
|
376
661
|
const record = { id, title, metadata: JSON.stringify(metadata) };
|
|
377
662
|
const table = await this.lanceClient.openTable(TABLE_THREADS);
|
|
378
|
-
await table.
|
|
663
|
+
await table.mergeInsert("id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([record]);
|
|
379
664
|
const query = table.query().where(`id = '${id}'`);
|
|
380
665
|
const records = await query.toArray();
|
|
381
666
|
return this.processResultWithTypeConversion(
|
|
@@ -383,7 +668,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
383
668
|
await this.getTableSchema(TABLE_THREADS)
|
|
384
669
|
);
|
|
385
670
|
} catch (error) {
|
|
386
|
-
throw new
|
|
671
|
+
throw new MastraError(
|
|
672
|
+
{
|
|
673
|
+
id: "LANCE_STORE_UPDATE_THREAD_FAILED",
|
|
674
|
+
domain: ErrorDomain.STORAGE,
|
|
675
|
+
category: ErrorCategory.THIRD_PARTY
|
|
676
|
+
},
|
|
677
|
+
error
|
|
678
|
+
);
|
|
387
679
|
}
|
|
388
680
|
}
|
|
389
681
|
async deleteThread({ threadId }) {
|
|
@@ -391,7 +683,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
391
683
|
const table = await this.lanceClient.openTable(TABLE_THREADS);
|
|
392
684
|
await table.delete(`id = '${threadId}'`);
|
|
393
685
|
} catch (error) {
|
|
394
|
-
throw new
|
|
686
|
+
throw new MastraError(
|
|
687
|
+
{
|
|
688
|
+
id: "LANCE_STORE_DELETE_THREAD_FAILED",
|
|
689
|
+
domain: ErrorDomain.STORAGE,
|
|
690
|
+
category: ErrorCategory.THIRD_PARTY
|
|
691
|
+
},
|
|
692
|
+
error
|
|
693
|
+
);
|
|
395
694
|
}
|
|
396
695
|
}
|
|
397
696
|
/**
|
|
@@ -453,6 +752,7 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
453
752
|
if (threadConfig) {
|
|
454
753
|
throw new Error("ThreadConfig is not supported by LanceDB storage");
|
|
455
754
|
}
|
|
755
|
+
const limit = this.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
|
|
456
756
|
const table = await this.lanceClient.openTable(TABLE_MESSAGES);
|
|
457
757
|
let query = table.query().where(`\`threadId\` = '${threadId}'`);
|
|
458
758
|
if (selectBy) {
|
|
@@ -471,8 +771,8 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
471
771
|
if (selectBy?.include && selectBy.include.length > 0) {
|
|
472
772
|
records = this.processMessagesWithContext(records, selectBy.include);
|
|
473
773
|
}
|
|
474
|
-
if (
|
|
475
|
-
records = records.slice(-
|
|
774
|
+
if (limit !== Number.MAX_SAFE_INTEGER) {
|
|
775
|
+
records = records.slice(-limit);
|
|
476
776
|
}
|
|
477
777
|
const messages = this.processResultWithTypeConversion(records, await this.getTableSchema(TABLE_MESSAGES));
|
|
478
778
|
const normalized = messages.map((msg) => ({
|
|
@@ -489,7 +789,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
489
789
|
if (format === "v2") return list.get.all.v2();
|
|
490
790
|
return list.get.all.v1();
|
|
491
791
|
} catch (error) {
|
|
492
|
-
throw new
|
|
792
|
+
throw new MastraError(
|
|
793
|
+
{
|
|
794
|
+
id: "LANCE_STORE_GET_MESSAGES_FAILED",
|
|
795
|
+
domain: ErrorDomain.STORAGE,
|
|
796
|
+
category: ErrorCategory.THIRD_PARTY
|
|
797
|
+
},
|
|
798
|
+
error
|
|
799
|
+
);
|
|
493
800
|
}
|
|
494
801
|
}
|
|
495
802
|
async saveMessages(args) {
|
|
@@ -507,12 +814,19 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
507
814
|
content: JSON.stringify(message.content)
|
|
508
815
|
}));
|
|
509
816
|
const table = await this.lanceClient.openTable(TABLE_MESSAGES);
|
|
510
|
-
await table.
|
|
817
|
+
await table.mergeInsert("id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(transformedMessages);
|
|
511
818
|
const list = new MessageList().add(messages, "memory");
|
|
512
819
|
if (format === `v2`) return list.get.all.v2();
|
|
513
820
|
return list.get.all.v1();
|
|
514
821
|
} catch (error) {
|
|
515
|
-
throw new
|
|
822
|
+
throw new MastraError(
|
|
823
|
+
{
|
|
824
|
+
id: "LANCE_STORE_SAVE_MESSAGES_FAILED",
|
|
825
|
+
domain: ErrorDomain.STORAGE,
|
|
826
|
+
category: ErrorCategory.THIRD_PARTY
|
|
827
|
+
},
|
|
828
|
+
error
|
|
829
|
+
);
|
|
516
830
|
}
|
|
517
831
|
}
|
|
518
832
|
async saveTrace({ trace }) {
|
|
@@ -529,7 +843,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
529
843
|
await table.add([record], { mode: "append" });
|
|
530
844
|
return trace;
|
|
531
845
|
} catch (error) {
|
|
532
|
-
throw new
|
|
846
|
+
throw new MastraError(
|
|
847
|
+
{
|
|
848
|
+
id: "LANCE_STORE_SAVE_TRACE_FAILED",
|
|
849
|
+
domain: ErrorDomain.STORAGE,
|
|
850
|
+
category: ErrorCategory.THIRD_PARTY
|
|
851
|
+
},
|
|
852
|
+
error
|
|
853
|
+
);
|
|
533
854
|
}
|
|
534
855
|
}
|
|
535
856
|
async getTraceById({ traceId }) {
|
|
@@ -539,7 +860,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
539
860
|
const records = await query.toArray();
|
|
540
861
|
return this.processResultWithTypeConversion(records[0], await this.getTableSchema(TABLE_TRACES));
|
|
541
862
|
} catch (error) {
|
|
542
|
-
throw new
|
|
863
|
+
throw new MastraError(
|
|
864
|
+
{
|
|
865
|
+
id: "LANCE_STORE_GET_TRACE_BY_ID_FAILED",
|
|
866
|
+
domain: ErrorDomain.STORAGE,
|
|
867
|
+
category: ErrorCategory.THIRD_PARTY
|
|
868
|
+
},
|
|
869
|
+
error
|
|
870
|
+
);
|
|
543
871
|
}
|
|
544
872
|
}
|
|
545
873
|
async getTraces({
|
|
@@ -581,7 +909,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
581
909
|
};
|
|
582
910
|
});
|
|
583
911
|
} catch (error) {
|
|
584
|
-
throw new
|
|
912
|
+
throw new MastraError(
|
|
913
|
+
{
|
|
914
|
+
id: "LANCE_STORE_GET_TRACES_FAILED",
|
|
915
|
+
domain: ErrorDomain.STORAGE,
|
|
916
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
917
|
+
details: { name: name ?? "", scope: scope ?? "" }
|
|
918
|
+
},
|
|
919
|
+
error
|
|
920
|
+
);
|
|
585
921
|
}
|
|
586
922
|
}
|
|
587
923
|
async saveEvals({ evals }) {
|
|
@@ -602,7 +938,14 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
602
938
|
await table.add(transformedEvals, { mode: "append" });
|
|
603
939
|
return evals;
|
|
604
940
|
} catch (error) {
|
|
605
|
-
throw new
|
|
941
|
+
throw new MastraError(
|
|
942
|
+
{
|
|
943
|
+
id: "LANCE_STORE_SAVE_EVALS_FAILED",
|
|
944
|
+
domain: ErrorDomain.STORAGE,
|
|
945
|
+
category: ErrorCategory.THIRD_PARTY
|
|
946
|
+
},
|
|
947
|
+
error
|
|
948
|
+
);
|
|
606
949
|
}
|
|
607
950
|
}
|
|
608
951
|
async getEvalsByAgentName(agentName, type) {
|
|
@@ -629,7 +972,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
629
972
|
};
|
|
630
973
|
});
|
|
631
974
|
} catch (error) {
|
|
632
|
-
throw new
|
|
975
|
+
throw new MastraError(
|
|
976
|
+
{
|
|
977
|
+
id: "LANCE_STORE_GET_EVALS_BY_AGENT_NAME_FAILED",
|
|
978
|
+
domain: ErrorDomain.STORAGE,
|
|
979
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
980
|
+
details: { agentName }
|
|
981
|
+
},
|
|
982
|
+
error
|
|
983
|
+
);
|
|
633
984
|
}
|
|
634
985
|
}
|
|
635
986
|
parseWorkflowRun(row) {
|
|
@@ -675,7 +1026,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
675
1026
|
total: records.length
|
|
676
1027
|
};
|
|
677
1028
|
} catch (error) {
|
|
678
|
-
throw new
|
|
1029
|
+
throw new MastraError(
|
|
1030
|
+
{
|
|
1031
|
+
id: "LANCE_STORE_GET_WORKFLOW_RUNS_FAILED",
|
|
1032
|
+
domain: ErrorDomain.STORAGE,
|
|
1033
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1034
|
+
details: { namespace: args?.namespace ?? "", workflowName: args?.workflowName ?? "" }
|
|
1035
|
+
},
|
|
1036
|
+
error
|
|
1037
|
+
);
|
|
679
1038
|
}
|
|
680
1039
|
}
|
|
681
1040
|
/**
|
|
@@ -696,7 +1055,15 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
696
1055
|
const record = records[0];
|
|
697
1056
|
return this.parseWorkflowRun(record);
|
|
698
1057
|
} catch (error) {
|
|
699
|
-
throw new
|
|
1058
|
+
throw new MastraError(
|
|
1059
|
+
{
|
|
1060
|
+
id: "LANCE_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
|
|
1061
|
+
domain: ErrorDomain.STORAGE,
|
|
1062
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1063
|
+
details: { runId: args.runId, workflowName: args.workflowName ?? "" }
|
|
1064
|
+
},
|
|
1065
|
+
error
|
|
1066
|
+
);
|
|
700
1067
|
}
|
|
701
1068
|
}
|
|
702
1069
|
async persistWorkflowSnapshot({
|
|
@@ -710,10 +1077,8 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
710
1077
|
const records = await query.toArray();
|
|
711
1078
|
let createdAt;
|
|
712
1079
|
const now = Date.now();
|
|
713
|
-
let mode = "append";
|
|
714
1080
|
if (records.length > 0) {
|
|
715
1081
|
createdAt = records[0].createdAt ?? now;
|
|
716
|
-
mode = "overwrite";
|
|
717
1082
|
} else {
|
|
718
1083
|
createdAt = now;
|
|
719
1084
|
}
|
|
@@ -724,9 +1089,17 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
724
1089
|
createdAt,
|
|
725
1090
|
updatedAt: now
|
|
726
1091
|
};
|
|
727
|
-
await table.
|
|
1092
|
+
await table.mergeInsert(["workflow_name", "run_id"]).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute([record]);
|
|
728
1093
|
} catch (error) {
|
|
729
|
-
throw new
|
|
1094
|
+
throw new MastraError(
|
|
1095
|
+
{
|
|
1096
|
+
id: "LANCE_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
|
|
1097
|
+
domain: ErrorDomain.STORAGE,
|
|
1098
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1099
|
+
details: { workflowName, runId }
|
|
1100
|
+
},
|
|
1101
|
+
error
|
|
1102
|
+
);
|
|
730
1103
|
}
|
|
731
1104
|
}
|
|
732
1105
|
async loadWorkflowSnapshot({
|
|
@@ -739,17 +1112,50 @@ var LanceStorage = class _LanceStorage extends MastraStorage {
|
|
|
739
1112
|
const records = await query.toArray();
|
|
740
1113
|
return records.length > 0 ? JSON.parse(records[0].snapshot) : null;
|
|
741
1114
|
} catch (error) {
|
|
742
|
-
throw new
|
|
1115
|
+
throw new MastraError(
|
|
1116
|
+
{
|
|
1117
|
+
id: "LANCE_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
|
|
1118
|
+
domain: ErrorDomain.STORAGE,
|
|
1119
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1120
|
+
details: { workflowName, runId }
|
|
1121
|
+
},
|
|
1122
|
+
error
|
|
1123
|
+
);
|
|
743
1124
|
}
|
|
744
1125
|
}
|
|
745
1126
|
async getTracesPaginated(_args) {
|
|
746
|
-
throw new
|
|
1127
|
+
throw new MastraError(
|
|
1128
|
+
{
|
|
1129
|
+
id: "LANCE_STORE_GET_TRACES_PAGINATED_FAILED",
|
|
1130
|
+
domain: ErrorDomain.STORAGE,
|
|
1131
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1132
|
+
},
|
|
1133
|
+
"Method not implemented."
|
|
1134
|
+
);
|
|
747
1135
|
}
|
|
748
1136
|
async getThreadsByResourceIdPaginated(_args) {
|
|
749
|
-
throw new
|
|
1137
|
+
throw new MastraError(
|
|
1138
|
+
{
|
|
1139
|
+
id: "LANCE_STORE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED",
|
|
1140
|
+
domain: ErrorDomain.STORAGE,
|
|
1141
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1142
|
+
},
|
|
1143
|
+
"Method not implemented."
|
|
1144
|
+
);
|
|
750
1145
|
}
|
|
751
1146
|
async getMessagesPaginated(_args) {
|
|
752
|
-
throw new
|
|
1147
|
+
throw new MastraError(
|
|
1148
|
+
{
|
|
1149
|
+
id: "LANCE_STORE_GET_MESSAGES_PAGINATED_FAILED",
|
|
1150
|
+
domain: ErrorDomain.STORAGE,
|
|
1151
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1152
|
+
},
|
|
1153
|
+
"Method not implemented."
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
async updateMessages(_args) {
|
|
1157
|
+
this.logger.error("updateMessages is not yet implemented in LanceStore");
|
|
1158
|
+
throw new Error("Method not implemented");
|
|
753
1159
|
}
|
|
754
1160
|
};
|
|
755
1161
|
var LanceFilterTranslator = class extends BaseFilterTranslator {
|
|
@@ -1103,7 +1509,15 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1103
1509
|
instance.lanceClient = await connect(uri, options);
|
|
1104
1510
|
return instance;
|
|
1105
1511
|
} catch (e) {
|
|
1106
|
-
throw new
|
|
1512
|
+
throw new MastraError(
|
|
1513
|
+
{
|
|
1514
|
+
id: "STORAGE_LANCE_VECTOR_CONNECT_FAILED",
|
|
1515
|
+
domain: ErrorDomain.STORAGE,
|
|
1516
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1517
|
+
details: { uri }
|
|
1518
|
+
},
|
|
1519
|
+
e
|
|
1520
|
+
);
|
|
1107
1521
|
}
|
|
1108
1522
|
}
|
|
1109
1523
|
/**
|
|
@@ -1127,14 +1541,27 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1127
1541
|
columns = [],
|
|
1128
1542
|
includeAllColumns = false
|
|
1129
1543
|
}) {
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1544
|
+
try {
|
|
1545
|
+
if (!this.lanceClient) {
|
|
1546
|
+
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
1547
|
+
}
|
|
1548
|
+
if (!tableName) {
|
|
1549
|
+
throw new Error("tableName is required");
|
|
1550
|
+
}
|
|
1551
|
+
if (!queryVector) {
|
|
1552
|
+
throw new Error("queryVector is required");
|
|
1553
|
+
}
|
|
1554
|
+
} catch (error) {
|
|
1555
|
+
throw new MastraError(
|
|
1556
|
+
{
|
|
1557
|
+
id: "STORAGE_LANCE_VECTOR_QUERY_FAILED_INVALID_ARGS",
|
|
1558
|
+
domain: ErrorDomain.STORAGE,
|
|
1559
|
+
category: ErrorCategory.USER,
|
|
1560
|
+
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
1561
|
+
details: { tableName }
|
|
1562
|
+
},
|
|
1563
|
+
error
|
|
1564
|
+
);
|
|
1138
1565
|
}
|
|
1139
1566
|
try {
|
|
1140
1567
|
const table = await this.lanceClient.openTable(tableName);
|
|
@@ -1173,7 +1600,15 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1173
1600
|
};
|
|
1174
1601
|
});
|
|
1175
1602
|
} catch (error) {
|
|
1176
|
-
throw new
|
|
1603
|
+
throw new MastraError(
|
|
1604
|
+
{
|
|
1605
|
+
id: "STORAGE_LANCE_VECTOR_QUERY_FAILED",
|
|
1606
|
+
domain: ErrorDomain.STORAGE,
|
|
1607
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1608
|
+
details: { tableName, includeVector, columnsCount: columns?.length, includeAllColumns }
|
|
1609
|
+
},
|
|
1610
|
+
error
|
|
1611
|
+
);
|
|
1177
1612
|
}
|
|
1178
1613
|
}
|
|
1179
1614
|
filterTranslator(filter) {
|
|
@@ -1206,14 +1641,27 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1206
1641
|
return translator.translate(prefixedFilter);
|
|
1207
1642
|
}
|
|
1208
1643
|
async upsert({ tableName, vectors, metadata = [], ids = [] }) {
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1644
|
+
try {
|
|
1645
|
+
if (!this.lanceClient) {
|
|
1646
|
+
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
1647
|
+
}
|
|
1648
|
+
if (!tableName) {
|
|
1649
|
+
throw new Error("tableName is required");
|
|
1650
|
+
}
|
|
1651
|
+
if (!vectors || !Array.isArray(vectors) || vectors.length === 0) {
|
|
1652
|
+
throw new Error("vectors array is required and must not be empty");
|
|
1653
|
+
}
|
|
1654
|
+
} catch (error) {
|
|
1655
|
+
throw new MastraError(
|
|
1656
|
+
{
|
|
1657
|
+
id: "STORAGE_LANCE_VECTOR_UPSERT_FAILED_INVALID_ARGS",
|
|
1658
|
+
domain: ErrorDomain.STORAGE,
|
|
1659
|
+
category: ErrorCategory.USER,
|
|
1660
|
+
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
1661
|
+
details: { tableName }
|
|
1662
|
+
},
|
|
1663
|
+
error
|
|
1664
|
+
);
|
|
1217
1665
|
}
|
|
1218
1666
|
try {
|
|
1219
1667
|
const tables = await this.lanceClient.tableNames();
|
|
@@ -1240,7 +1688,15 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1240
1688
|
await table.add(data, { mode: "overwrite" });
|
|
1241
1689
|
return vectorIds;
|
|
1242
1690
|
} catch (error) {
|
|
1243
|
-
throw new
|
|
1691
|
+
throw new MastraError(
|
|
1692
|
+
{
|
|
1693
|
+
id: "STORAGE_LANCE_VECTOR_UPSERT_FAILED",
|
|
1694
|
+
domain: ErrorDomain.STORAGE,
|
|
1695
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1696
|
+
details: { tableName, vectorCount: vectors.length, metadataCount: metadata.length, idsCount: ids.length }
|
|
1697
|
+
},
|
|
1698
|
+
error
|
|
1699
|
+
);
|
|
1244
1700
|
}
|
|
1245
1701
|
}
|
|
1246
1702
|
/**
|
|
@@ -1260,29 +1716,78 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1260
1716
|
}
|
|
1261
1717
|
async createTable(tableName, data, options) {
|
|
1262
1718
|
if (!this.lanceClient) {
|
|
1263
|
-
throw new
|
|
1719
|
+
throw new MastraError({
|
|
1720
|
+
id: "STORAGE_LANCE_VECTOR_CREATE_TABLE_FAILED_INVALID_ARGS",
|
|
1721
|
+
domain: ErrorDomain.STORAGE,
|
|
1722
|
+
category: ErrorCategory.USER,
|
|
1723
|
+
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
1724
|
+
details: { tableName }
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
if (Array.isArray(data)) {
|
|
1728
|
+
data = data.map((record) => this.flattenObject(record));
|
|
1264
1729
|
}
|
|
1265
1730
|
try {
|
|
1266
|
-
if (Array.isArray(data)) {
|
|
1267
|
-
data = data.map((record) => this.flattenObject(record));
|
|
1268
|
-
}
|
|
1269
1731
|
return await this.lanceClient.createTable(tableName, data, options);
|
|
1270
1732
|
} catch (error) {
|
|
1271
|
-
throw new
|
|
1733
|
+
throw new MastraError(
|
|
1734
|
+
{
|
|
1735
|
+
id: "STORAGE_LANCE_VECTOR_CREATE_TABLE_FAILED",
|
|
1736
|
+
domain: ErrorDomain.STORAGE,
|
|
1737
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1738
|
+
details: { tableName }
|
|
1739
|
+
},
|
|
1740
|
+
error
|
|
1741
|
+
);
|
|
1272
1742
|
}
|
|
1273
1743
|
}
|
|
1274
1744
|
async listTables() {
|
|
1275
1745
|
if (!this.lanceClient) {
|
|
1276
|
-
throw new
|
|
1746
|
+
throw new MastraError({
|
|
1747
|
+
id: "STORAGE_LANCE_VECTOR_LIST_TABLES_FAILED_INVALID_ARGS",
|
|
1748
|
+
domain: ErrorDomain.STORAGE,
|
|
1749
|
+
category: ErrorCategory.USER,
|
|
1750
|
+
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
1751
|
+
details: { methodName: "listTables" }
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
try {
|
|
1755
|
+
return await this.lanceClient.tableNames();
|
|
1756
|
+
} catch (error) {
|
|
1757
|
+
throw new MastraError(
|
|
1758
|
+
{
|
|
1759
|
+
id: "STORAGE_LANCE_VECTOR_LIST_TABLES_FAILED",
|
|
1760
|
+
domain: ErrorDomain.STORAGE,
|
|
1761
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1762
|
+
},
|
|
1763
|
+
error
|
|
1764
|
+
);
|
|
1277
1765
|
}
|
|
1278
|
-
return await this.lanceClient.tableNames();
|
|
1279
1766
|
}
|
|
1280
1767
|
async getTableSchema(tableName) {
|
|
1281
1768
|
if (!this.lanceClient) {
|
|
1282
|
-
throw new
|
|
1769
|
+
throw new MastraError({
|
|
1770
|
+
id: "STORAGE_LANCE_VECTOR_GET_TABLE_SCHEMA_FAILED_INVALID_ARGS",
|
|
1771
|
+
domain: ErrorDomain.STORAGE,
|
|
1772
|
+
category: ErrorCategory.USER,
|
|
1773
|
+
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
1774
|
+
details: { tableName }
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
try {
|
|
1778
|
+
const table = await this.lanceClient.openTable(tableName);
|
|
1779
|
+
return await table.schema();
|
|
1780
|
+
} catch (error) {
|
|
1781
|
+
throw new MastraError(
|
|
1782
|
+
{
|
|
1783
|
+
id: "STORAGE_LANCE_VECTOR_GET_TABLE_SCHEMA_FAILED",
|
|
1784
|
+
domain: ErrorDomain.STORAGE,
|
|
1785
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1786
|
+
details: { tableName }
|
|
1787
|
+
},
|
|
1788
|
+
error
|
|
1789
|
+
);
|
|
1283
1790
|
}
|
|
1284
|
-
const table = await this.lanceClient.openTable(tableName);
|
|
1285
|
-
return await table.schema();
|
|
1286
1791
|
}
|
|
1287
1792
|
/**
|
|
1288
1793
|
* indexName is actually a column name in a table in lanceDB
|
|
@@ -1294,10 +1799,10 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1294
1799
|
metric = "cosine",
|
|
1295
1800
|
indexConfig = {}
|
|
1296
1801
|
}) {
|
|
1297
|
-
if (!this.lanceClient) {
|
|
1298
|
-
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
1299
|
-
}
|
|
1300
1802
|
try {
|
|
1803
|
+
if (!this.lanceClient) {
|
|
1804
|
+
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
1805
|
+
}
|
|
1301
1806
|
if (!tableName) {
|
|
1302
1807
|
throw new Error("tableName is required");
|
|
1303
1808
|
}
|
|
@@ -1307,6 +1812,18 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1307
1812
|
if (typeof dimension !== "number" || dimension <= 0) {
|
|
1308
1813
|
throw new Error("dimension must be a positive number");
|
|
1309
1814
|
}
|
|
1815
|
+
} catch (err) {
|
|
1816
|
+
throw new MastraError(
|
|
1817
|
+
{
|
|
1818
|
+
id: "STORAGE_LANCE_VECTOR_CREATE_INDEX_FAILED_INVALID_ARGS",
|
|
1819
|
+
domain: ErrorDomain.STORAGE,
|
|
1820
|
+
category: ErrorCategory.USER,
|
|
1821
|
+
details: { tableName: tableName || "", indexName, dimension, metric }
|
|
1822
|
+
},
|
|
1823
|
+
err
|
|
1824
|
+
);
|
|
1825
|
+
}
|
|
1826
|
+
try {
|
|
1310
1827
|
const tables = await this.lanceClient.tableNames();
|
|
1311
1828
|
if (!tables.includes(tableName)) {
|
|
1312
1829
|
throw new Error(
|
|
@@ -1341,12 +1858,26 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1341
1858
|
});
|
|
1342
1859
|
}
|
|
1343
1860
|
} catch (error) {
|
|
1344
|
-
throw new
|
|
1861
|
+
throw new MastraError(
|
|
1862
|
+
{
|
|
1863
|
+
id: "STORAGE_LANCE_VECTOR_CREATE_INDEX_FAILED",
|
|
1864
|
+
domain: ErrorDomain.STORAGE,
|
|
1865
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1866
|
+
details: { tableName: tableName || "", indexName, dimension }
|
|
1867
|
+
},
|
|
1868
|
+
error
|
|
1869
|
+
);
|
|
1345
1870
|
}
|
|
1346
1871
|
}
|
|
1347
1872
|
async listIndexes() {
|
|
1348
1873
|
if (!this.lanceClient) {
|
|
1349
|
-
throw new
|
|
1874
|
+
throw new MastraError({
|
|
1875
|
+
id: "STORAGE_LANCE_VECTOR_LIST_INDEXES_FAILED_INVALID_ARGS",
|
|
1876
|
+
domain: ErrorDomain.STORAGE,
|
|
1877
|
+
category: ErrorCategory.USER,
|
|
1878
|
+
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance",
|
|
1879
|
+
details: { methodName: "listIndexes" }
|
|
1880
|
+
});
|
|
1350
1881
|
}
|
|
1351
1882
|
try {
|
|
1352
1883
|
const tables = await this.lanceClient.tableNames();
|
|
@@ -1358,15 +1889,34 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1358
1889
|
}
|
|
1359
1890
|
return allIndices;
|
|
1360
1891
|
} catch (error) {
|
|
1361
|
-
throw new
|
|
1892
|
+
throw new MastraError(
|
|
1893
|
+
{
|
|
1894
|
+
id: "STORAGE_LANCE_VECTOR_LIST_INDEXES_FAILED",
|
|
1895
|
+
domain: ErrorDomain.STORAGE,
|
|
1896
|
+
category: ErrorCategory.THIRD_PARTY
|
|
1897
|
+
},
|
|
1898
|
+
error
|
|
1899
|
+
);
|
|
1362
1900
|
}
|
|
1363
1901
|
}
|
|
1364
1902
|
async describeIndex({ indexName }) {
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1903
|
+
try {
|
|
1904
|
+
if (!this.lanceClient) {
|
|
1905
|
+
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
1906
|
+
}
|
|
1907
|
+
if (!indexName) {
|
|
1908
|
+
throw new Error("indexName is required");
|
|
1909
|
+
}
|
|
1910
|
+
} catch (err) {
|
|
1911
|
+
throw new MastraError(
|
|
1912
|
+
{
|
|
1913
|
+
id: "STORAGE_LANCE_VECTOR_DESCRIBE_INDEX_FAILED_INVALID_ARGS",
|
|
1914
|
+
domain: ErrorDomain.STORAGE,
|
|
1915
|
+
category: ErrorCategory.USER,
|
|
1916
|
+
details: { indexName }
|
|
1917
|
+
},
|
|
1918
|
+
err
|
|
1919
|
+
);
|
|
1370
1920
|
}
|
|
1371
1921
|
try {
|
|
1372
1922
|
const tables = await this.lanceClient.tableNames();
|
|
@@ -1393,15 +1943,35 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1393
1943
|
}
|
|
1394
1944
|
throw new Error(`IndexName: ${indexName} not found`);
|
|
1395
1945
|
} catch (error) {
|
|
1396
|
-
throw new
|
|
1946
|
+
throw new MastraError(
|
|
1947
|
+
{
|
|
1948
|
+
id: "STORAGE_LANCE_VECTOR_DESCRIBE_INDEX_FAILED",
|
|
1949
|
+
domain: ErrorDomain.STORAGE,
|
|
1950
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1951
|
+
details: { indexName }
|
|
1952
|
+
},
|
|
1953
|
+
error
|
|
1954
|
+
);
|
|
1397
1955
|
}
|
|
1398
1956
|
}
|
|
1399
1957
|
async deleteIndex({ indexName }) {
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1958
|
+
try {
|
|
1959
|
+
if (!this.lanceClient) {
|
|
1960
|
+
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
1961
|
+
}
|
|
1962
|
+
if (!indexName) {
|
|
1963
|
+
throw new Error("indexName is required");
|
|
1964
|
+
}
|
|
1965
|
+
} catch (err) {
|
|
1966
|
+
throw new MastraError(
|
|
1967
|
+
{
|
|
1968
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_INDEX_FAILED_INVALID_ARGS",
|
|
1969
|
+
domain: ErrorDomain.STORAGE,
|
|
1970
|
+
category: ErrorCategory.USER,
|
|
1971
|
+
details: { indexName }
|
|
1972
|
+
},
|
|
1973
|
+
err
|
|
1974
|
+
);
|
|
1405
1975
|
}
|
|
1406
1976
|
try {
|
|
1407
1977
|
const tables = await this.lanceClient.tableNames();
|
|
@@ -1416,7 +1986,15 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1416
1986
|
}
|
|
1417
1987
|
throw new Error(`Index ${indexName} not found`);
|
|
1418
1988
|
} catch (error) {
|
|
1419
|
-
throw new
|
|
1989
|
+
throw new MastraError(
|
|
1990
|
+
{
|
|
1991
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_INDEX_FAILED",
|
|
1992
|
+
domain: ErrorDomain.STORAGE,
|
|
1993
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
1994
|
+
details: { indexName }
|
|
1995
|
+
},
|
|
1996
|
+
error
|
|
1997
|
+
);
|
|
1420
1998
|
}
|
|
1421
1999
|
}
|
|
1422
2000
|
/**
|
|
@@ -1424,33 +2002,73 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1424
2002
|
*/
|
|
1425
2003
|
async deleteAllTables() {
|
|
1426
2004
|
if (!this.lanceClient) {
|
|
1427
|
-
throw new
|
|
2005
|
+
throw new MastraError({
|
|
2006
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_ALL_TABLES_FAILED_INVALID_ARGS",
|
|
2007
|
+
domain: ErrorDomain.STORAGE,
|
|
2008
|
+
category: ErrorCategory.USER,
|
|
2009
|
+
details: { methodName: "deleteAllTables" },
|
|
2010
|
+
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance"
|
|
2011
|
+
});
|
|
1428
2012
|
}
|
|
1429
2013
|
try {
|
|
1430
2014
|
await this.lanceClient.dropAllTables();
|
|
1431
2015
|
} catch (error) {
|
|
1432
|
-
throw new
|
|
2016
|
+
throw new MastraError(
|
|
2017
|
+
{
|
|
2018
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_ALL_TABLES_FAILED",
|
|
2019
|
+
domain: ErrorDomain.STORAGE,
|
|
2020
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
2021
|
+
details: { methodName: "deleteAllTables" }
|
|
2022
|
+
},
|
|
2023
|
+
error
|
|
2024
|
+
);
|
|
1433
2025
|
}
|
|
1434
2026
|
}
|
|
1435
2027
|
async deleteTable(tableName) {
|
|
1436
2028
|
if (!this.lanceClient) {
|
|
1437
|
-
throw new
|
|
2029
|
+
throw new MastraError({
|
|
2030
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_TABLE_FAILED_INVALID_ARGS",
|
|
2031
|
+
domain: ErrorDomain.STORAGE,
|
|
2032
|
+
category: ErrorCategory.USER,
|
|
2033
|
+
details: { tableName },
|
|
2034
|
+
text: "LanceDB client not initialized. Use LanceVectorStore.create() to create an instance"
|
|
2035
|
+
});
|
|
1438
2036
|
}
|
|
1439
2037
|
try {
|
|
1440
2038
|
await this.lanceClient.dropTable(tableName);
|
|
1441
2039
|
} catch (error) {
|
|
1442
|
-
throw new
|
|
2040
|
+
throw new MastraError(
|
|
2041
|
+
{
|
|
2042
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_TABLE_FAILED",
|
|
2043
|
+
domain: ErrorDomain.STORAGE,
|
|
2044
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
2045
|
+
details: { tableName }
|
|
2046
|
+
},
|
|
2047
|
+
error
|
|
2048
|
+
);
|
|
1443
2049
|
}
|
|
1444
2050
|
}
|
|
1445
2051
|
async updateVector({ indexName, id, update }) {
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
2052
|
+
try {
|
|
2053
|
+
if (!this.lanceClient) {
|
|
2054
|
+
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
2055
|
+
}
|
|
2056
|
+
if (!indexName) {
|
|
2057
|
+
throw new Error("indexName is required");
|
|
2058
|
+
}
|
|
2059
|
+
if (!id) {
|
|
2060
|
+
throw new Error("id is required");
|
|
2061
|
+
}
|
|
2062
|
+
} catch (err) {
|
|
2063
|
+
throw new MastraError(
|
|
2064
|
+
{
|
|
2065
|
+
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_FAILED_INVALID_ARGS",
|
|
2066
|
+
domain: ErrorDomain.STORAGE,
|
|
2067
|
+
category: ErrorCategory.USER,
|
|
2068
|
+
details: { indexName, id }
|
|
2069
|
+
},
|
|
2070
|
+
err
|
|
2071
|
+
);
|
|
1454
2072
|
}
|
|
1455
2073
|
try {
|
|
1456
2074
|
const tables = await this.lanceClient.tableNames();
|
|
@@ -1504,18 +2122,38 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1504
2122
|
}
|
|
1505
2123
|
throw new Error(`No table found with column/index '${indexName}'`);
|
|
1506
2124
|
} catch (error) {
|
|
1507
|
-
throw new
|
|
2125
|
+
throw new MastraError(
|
|
2126
|
+
{
|
|
2127
|
+
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_FAILED",
|
|
2128
|
+
domain: ErrorDomain.STORAGE,
|
|
2129
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
2130
|
+
details: { indexName, id, hasVector: !!update.vector, hasMetadata: !!update.metadata }
|
|
2131
|
+
},
|
|
2132
|
+
error
|
|
2133
|
+
);
|
|
1508
2134
|
}
|
|
1509
2135
|
}
|
|
1510
2136
|
async deleteVector({ indexName, id }) {
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
2137
|
+
try {
|
|
2138
|
+
if (!this.lanceClient) {
|
|
2139
|
+
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
2140
|
+
}
|
|
2141
|
+
if (!indexName) {
|
|
2142
|
+
throw new Error("indexName is required");
|
|
2143
|
+
}
|
|
2144
|
+
if (!id) {
|
|
2145
|
+
throw new Error("id is required");
|
|
2146
|
+
}
|
|
2147
|
+
} catch (err) {
|
|
2148
|
+
throw new MastraError(
|
|
2149
|
+
{
|
|
2150
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED_INVALID_ARGS",
|
|
2151
|
+
domain: ErrorDomain.STORAGE,
|
|
2152
|
+
category: ErrorCategory.USER,
|
|
2153
|
+
details: { indexName, id }
|
|
2154
|
+
},
|
|
2155
|
+
err
|
|
2156
|
+
);
|
|
1519
2157
|
}
|
|
1520
2158
|
try {
|
|
1521
2159
|
const tables = await this.lanceClient.tableNames();
|
|
@@ -1537,7 +2175,15 @@ var LanceVectorStore = class _LanceVectorStore extends MastraVector {
|
|
|
1537
2175
|
}
|
|
1538
2176
|
throw new Error(`No table found with column/index '${indexName}'`);
|
|
1539
2177
|
} catch (error) {
|
|
1540
|
-
throw new
|
|
2178
|
+
throw new MastraError(
|
|
2179
|
+
{
|
|
2180
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED",
|
|
2181
|
+
domain: ErrorDomain.STORAGE,
|
|
2182
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
2183
|
+
details: { indexName, id }
|
|
2184
|
+
},
|
|
2185
|
+
error
|
|
2186
|
+
);
|
|
1541
2187
|
}
|
|
1542
2188
|
}
|
|
1543
2189
|
/**
|