@mastra/lance 0.0.0-roamin-openaivoice-speak-options-passing-20250926163614 → 0.0.0-safe-stringify-telemetry-20251205024938
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 +179 -3
- package/dist/index.cjs +285 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +285 -51
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +8 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +2 -9
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +11 -9
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/vector/filter.d.ts +5 -5
- package/dist/vector/index.d.ts +3 -2
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +15 -8
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var error = require('@mastra/core/error');
|
|
|
5
5
|
var storage = require('@mastra/core/storage');
|
|
6
6
|
var agent = require('@mastra/core/agent');
|
|
7
7
|
var apacheArrow = require('apache-arrow');
|
|
8
|
+
var scores = require('@mastra/core/scores');
|
|
8
9
|
var vector = require('@mastra/core/vector');
|
|
9
10
|
var filter = require('@mastra/core/vector/filter');
|
|
10
11
|
|
|
@@ -61,9 +62,9 @@ var StoreLegacyEvalsLance = class extends storage.LegacyEvalsStorage {
|
|
|
61
62
|
conditions.push(`agent_name = '${options.agentName}'`);
|
|
62
63
|
}
|
|
63
64
|
if (options.type === "live") {
|
|
64
|
-
conditions.push("
|
|
65
|
+
conditions.push("test_info IS NULL");
|
|
65
66
|
} else if (options.type === "test") {
|
|
66
|
-
conditions.push("
|
|
67
|
+
conditions.push("test_info IS NOT NULL");
|
|
67
68
|
}
|
|
68
69
|
const startDate = options.dateRange?.start || options.fromDate;
|
|
69
70
|
const endDate = options.dateRange?.end || options.toDate;
|
|
@@ -1398,13 +1399,27 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1398
1399
|
this.client = client;
|
|
1399
1400
|
}
|
|
1400
1401
|
async saveScore(score) {
|
|
1402
|
+
let validatedScore;
|
|
1403
|
+
try {
|
|
1404
|
+
validatedScore = scores.saveScorePayloadSchema.parse(score);
|
|
1405
|
+
} catch (error$1) {
|
|
1406
|
+
throw new error.MastraError(
|
|
1407
|
+
{
|
|
1408
|
+
id: "LANCE_STORAGE_SAVE_SCORE_FAILED",
|
|
1409
|
+
text: "Failed to save score in LanceStorage",
|
|
1410
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1411
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
1412
|
+
},
|
|
1413
|
+
error$1
|
|
1414
|
+
);
|
|
1415
|
+
}
|
|
1401
1416
|
try {
|
|
1402
1417
|
const id = crypto.randomUUID();
|
|
1403
1418
|
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1404
1419
|
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1405
1420
|
const allowedFields = new Set(schema.fields.map((f) => f.name));
|
|
1406
1421
|
const filteredScore = {};
|
|
1407
|
-
Object.keys(
|
|
1422
|
+
Object.keys(validatedScore).forEach((key) => {
|
|
1408
1423
|
if (allowedFields.has(key)) {
|
|
1409
1424
|
filteredScore[key] = score[key];
|
|
1410
1425
|
}
|
|
@@ -1414,6 +1429,8 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1414
1429
|
filteredScore[key] = JSON.stringify(filteredScore[key]);
|
|
1415
1430
|
}
|
|
1416
1431
|
}
|
|
1432
|
+
filteredScore.createdAt = /* @__PURE__ */ new Date();
|
|
1433
|
+
filteredScore.updatedAt = /* @__PURE__ */ new Date();
|
|
1417
1434
|
filteredScore.id = id;
|
|
1418
1435
|
await table.add([filteredScore], { mode: "append" });
|
|
1419
1436
|
return { score };
|
|
@@ -1580,6 +1597,44 @@ var StoreScoresLance = class extends storage.ScoresStorage {
|
|
|
1580
1597
|
);
|
|
1581
1598
|
}
|
|
1582
1599
|
}
|
|
1600
|
+
async getScoresBySpan({
|
|
1601
|
+
traceId,
|
|
1602
|
+
spanId,
|
|
1603
|
+
pagination
|
|
1604
|
+
}) {
|
|
1605
|
+
try {
|
|
1606
|
+
const table = await this.client.openTable(storage.TABLE_SCORERS);
|
|
1607
|
+
const { page = 0, perPage = 10 } = pagination || {};
|
|
1608
|
+
const offset = page * perPage;
|
|
1609
|
+
const query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).limit(perPage);
|
|
1610
|
+
if (offset > 0) query.offset(offset);
|
|
1611
|
+
const records = await query.toArray();
|
|
1612
|
+
const schema = await getTableSchema({ tableName: storage.TABLE_SCORERS, client: this.client });
|
|
1613
|
+
const scores = processResultWithTypeConversion(records, schema);
|
|
1614
|
+
const allRecords = await table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).toArray();
|
|
1615
|
+
const total = allRecords.length;
|
|
1616
|
+
return {
|
|
1617
|
+
pagination: {
|
|
1618
|
+
page,
|
|
1619
|
+
perPage,
|
|
1620
|
+
total,
|
|
1621
|
+
hasMore: offset + scores.length < total
|
|
1622
|
+
},
|
|
1623
|
+
scores
|
|
1624
|
+
};
|
|
1625
|
+
} catch (error$1) {
|
|
1626
|
+
throw new error.MastraError(
|
|
1627
|
+
{
|
|
1628
|
+
id: "LANCE_STORAGE_GET_SCORES_BY_SPAN_FAILED",
|
|
1629
|
+
text: "Failed to get scores by traceId and spanId in LanceStorage",
|
|
1630
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1631
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1632
|
+
details: { error: error$1?.message }
|
|
1633
|
+
},
|
|
1634
|
+
error$1
|
|
1635
|
+
);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1583
1638
|
};
|
|
1584
1639
|
var StoreTracesLance = class extends storage.TracesStorage {
|
|
1585
1640
|
client;
|
|
@@ -1830,11 +1885,13 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1830
1885
|
} else {
|
|
1831
1886
|
createdAt = now;
|
|
1832
1887
|
}
|
|
1888
|
+
const { status, value, ...rest } = snapshot;
|
|
1833
1889
|
const record = {
|
|
1834
1890
|
workflow_name: workflowName,
|
|
1835
1891
|
run_id: runId,
|
|
1836
1892
|
resourceId,
|
|
1837
|
-
snapshot: JSON.stringify(
|
|
1893
|
+
snapshot: JSON.stringify({ status, value, ...rest }),
|
|
1894
|
+
// this is to ensure status is always just before value, for when querying the db by status
|
|
1838
1895
|
createdAt,
|
|
1839
1896
|
updatedAt: now
|
|
1840
1897
|
};
|
|
@@ -1904,6 +1961,10 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1904
1961
|
if (args?.workflowName) {
|
|
1905
1962
|
conditions.push(`workflow_name = '${args.workflowName.replace(/'/g, "''")}'`);
|
|
1906
1963
|
}
|
|
1964
|
+
if (args?.status) {
|
|
1965
|
+
const escapedStatus = args.status.replace(/\\/g, "\\\\").replace(/'/g, "''").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
1966
|
+
conditions.push(`\`snapshot\` LIKE '%"status":"${escapedStatus}","value"%'`);
|
|
1967
|
+
}
|
|
1907
1968
|
if (args?.resourceId) {
|
|
1908
1969
|
conditions.push(`\`resourceId\` = '${args.resourceId}'`);
|
|
1909
1970
|
}
|
|
@@ -1937,7 +1998,7 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1937
1998
|
id: "LANCE_STORE_GET_WORKFLOW_RUNS_FAILED",
|
|
1938
1999
|
domain: error.ErrorDomain.STORAGE,
|
|
1939
2000
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1940
|
-
details: {
|
|
2001
|
+
details: { resourceId: args?.resourceId ?? "", workflowName: args?.workflowName ?? "" }
|
|
1941
2002
|
},
|
|
1942
2003
|
error$1
|
|
1943
2004
|
);
|
|
@@ -2072,7 +2133,8 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2072
2133
|
resourceWorkingMemory: true,
|
|
2073
2134
|
hasColumn: true,
|
|
2074
2135
|
createTable: true,
|
|
2075
|
-
deleteMessages: false
|
|
2136
|
+
deleteMessages: false,
|
|
2137
|
+
getScoresBySpan: true
|
|
2076
2138
|
};
|
|
2077
2139
|
}
|
|
2078
2140
|
async getResourceById({ resourceId }) {
|
|
@@ -2242,6 +2304,13 @@ var LanceStorage = class _LanceStorage extends storage.MastraStorage {
|
|
|
2242
2304
|
}) {
|
|
2243
2305
|
return this.stores.scores.getScoresByEntityId({ entityId, entityType, pagination });
|
|
2244
2306
|
}
|
|
2307
|
+
async getScoresBySpan({
|
|
2308
|
+
traceId,
|
|
2309
|
+
spanId,
|
|
2310
|
+
pagination
|
|
2311
|
+
}) {
|
|
2312
|
+
return this.stores.scores.getScoresBySpan({ traceId, spanId, pagination });
|
|
2313
|
+
}
|
|
2245
2314
|
};
|
|
2246
2315
|
var LanceFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
2247
2316
|
translate(filter) {
|
|
@@ -3133,7 +3202,44 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3133
3202
|
);
|
|
3134
3203
|
}
|
|
3135
3204
|
}
|
|
3136
|
-
async updateVector(
|
|
3205
|
+
async updateVector(params) {
|
|
3206
|
+
const { indexName, update } = params;
|
|
3207
|
+
if ("id" in params && "filter" in params && params.id && params.filter) {
|
|
3208
|
+
throw new error.MastraError({
|
|
3209
|
+
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
3210
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3211
|
+
category: error.ErrorCategory.USER,
|
|
3212
|
+
text: "id and filter are mutually exclusive",
|
|
3213
|
+
details: { indexName }
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
if (!("id" in params || "filter" in params) || !params.id && !params.filter) {
|
|
3217
|
+
throw new error.MastraError({
|
|
3218
|
+
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
3219
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3220
|
+
category: error.ErrorCategory.USER,
|
|
3221
|
+
text: "Either id or filter must be provided",
|
|
3222
|
+
details: { indexName }
|
|
3223
|
+
});
|
|
3224
|
+
}
|
|
3225
|
+
if ("filter" in params && params.filter && Object.keys(params.filter).length === 0) {
|
|
3226
|
+
throw new error.MastraError({
|
|
3227
|
+
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
3228
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3229
|
+
category: error.ErrorCategory.USER,
|
|
3230
|
+
text: "Cannot update with empty filter",
|
|
3231
|
+
details: { indexName }
|
|
3232
|
+
});
|
|
3233
|
+
}
|
|
3234
|
+
if (!update.vector && !update.metadata) {
|
|
3235
|
+
throw new error.MastraError({
|
|
3236
|
+
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
3237
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3238
|
+
category: error.ErrorCategory.USER,
|
|
3239
|
+
text: "No updates provided",
|
|
3240
|
+
details: { indexName }
|
|
3241
|
+
});
|
|
3242
|
+
}
|
|
3137
3243
|
try {
|
|
3138
3244
|
if (!this.lanceClient) {
|
|
3139
3245
|
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
@@ -3141,21 +3247,6 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3141
3247
|
if (!indexName) {
|
|
3142
3248
|
throw new Error("indexName is required");
|
|
3143
3249
|
}
|
|
3144
|
-
if (!id) {
|
|
3145
|
-
throw new Error("id is required");
|
|
3146
|
-
}
|
|
3147
|
-
} catch (err) {
|
|
3148
|
-
throw new error.MastraError(
|
|
3149
|
-
{
|
|
3150
|
-
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_FAILED_INVALID_ARGS",
|
|
3151
|
-
domain: error.ErrorDomain.STORAGE,
|
|
3152
|
-
category: error.ErrorCategory.USER,
|
|
3153
|
-
details: { indexName, id }
|
|
3154
|
-
},
|
|
3155
|
-
err
|
|
3156
|
-
);
|
|
3157
|
-
}
|
|
3158
|
-
try {
|
|
3159
3250
|
const tables = await this.lanceClient.tableNames();
|
|
3160
3251
|
for (const tableName of tables) {
|
|
3161
3252
|
this.logger.debug("Checking table:" + tableName);
|
|
@@ -3165,39 +3256,66 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3165
3256
|
const hasColumn = schema.fields.some((field) => field.name === indexName);
|
|
3166
3257
|
if (hasColumn) {
|
|
3167
3258
|
this.logger.debug(`Found column ${indexName} in table ${tableName}`);
|
|
3168
|
-
|
|
3169
|
-
if (
|
|
3170
|
-
|
|
3259
|
+
let whereClause;
|
|
3260
|
+
if ("id" in params && params.id) {
|
|
3261
|
+
whereClause = `id = '${params.id}'`;
|
|
3262
|
+
} else if ("filter" in params && params.filter) {
|
|
3263
|
+
const translator = new LanceFilterTranslator();
|
|
3264
|
+
const processFilterKeys = (filter) => {
|
|
3265
|
+
const processedFilter = {};
|
|
3266
|
+
Object.entries(filter).forEach(([key, value]) => {
|
|
3267
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
3268
|
+
Object.entries(value).forEach(([nestedKey, nestedValue]) => {
|
|
3269
|
+
processedFilter[`metadata_${key}_${nestedKey}`] = nestedValue;
|
|
3270
|
+
});
|
|
3271
|
+
} else {
|
|
3272
|
+
processedFilter[`metadata_${key}`] = value;
|
|
3273
|
+
}
|
|
3274
|
+
});
|
|
3275
|
+
return processedFilter;
|
|
3276
|
+
};
|
|
3277
|
+
const prefixedFilter = processFilterKeys(params.filter);
|
|
3278
|
+
whereClause = translator.translate(prefixedFilter) || "";
|
|
3279
|
+
if (!whereClause) {
|
|
3280
|
+
throw new Error("Failed to translate filter to SQL");
|
|
3281
|
+
}
|
|
3282
|
+
} else {
|
|
3283
|
+
throw new Error("Either id or filter must be provided");
|
|
3171
3284
|
}
|
|
3172
|
-
const
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3285
|
+
const existingRecords = await table.query().where(whereClause).select(schema.fields.map((field) => field.name)).toArray();
|
|
3286
|
+
if (existingRecords.length === 0) {
|
|
3287
|
+
this.logger.info(`No records found matching criteria in table ${tableName}`);
|
|
3288
|
+
return;
|
|
3289
|
+
}
|
|
3290
|
+
const updatedRecords = existingRecords.map((record) => {
|
|
3291
|
+
const rowData = {};
|
|
3292
|
+
Object.entries(record).forEach(([key, value]) => {
|
|
3293
|
+
if (key !== "_distance") {
|
|
3294
|
+
if (key === indexName) {
|
|
3295
|
+
if (update.vector) {
|
|
3296
|
+
rowData[key] = update.vector;
|
|
3183
3297
|
} else {
|
|
3184
|
-
|
|
3298
|
+
if (Array.isArray(value)) {
|
|
3299
|
+
rowData[key] = [...value];
|
|
3300
|
+
} else if (typeof value === "object" && value !== null) {
|
|
3301
|
+
rowData[key] = Array.from(value);
|
|
3302
|
+
} else {
|
|
3303
|
+
rowData[key] = value;
|
|
3304
|
+
}
|
|
3185
3305
|
}
|
|
3306
|
+
} else {
|
|
3307
|
+
rowData[key] = value;
|
|
3186
3308
|
}
|
|
3187
|
-
} else {
|
|
3188
|
-
rowData[key] = value;
|
|
3189
3309
|
}
|
|
3310
|
+
});
|
|
3311
|
+
if (update.metadata) {
|
|
3312
|
+
Object.entries(update.metadata).forEach(([key, value]) => {
|
|
3313
|
+
rowData[`metadata_${key}`] = value;
|
|
3314
|
+
});
|
|
3190
3315
|
}
|
|
3316
|
+
return rowData;
|
|
3191
3317
|
});
|
|
3192
|
-
|
|
3193
|
-
rowData[indexName] = update.vector;
|
|
3194
|
-
}
|
|
3195
|
-
if (update.metadata) {
|
|
3196
|
-
Object.entries(update.metadata).forEach(([key, value]) => {
|
|
3197
|
-
rowData[`metadata_${key}`] = value;
|
|
3198
|
-
});
|
|
3199
|
-
}
|
|
3200
|
-
await table.add([rowData], { mode: "overwrite" });
|
|
3318
|
+
await table.add(updatedRecords, { mode: "overwrite" });
|
|
3201
3319
|
return;
|
|
3202
3320
|
}
|
|
3203
3321
|
} catch (err) {
|
|
@@ -3207,12 +3325,19 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3207
3325
|
}
|
|
3208
3326
|
throw new Error(`No table found with column/index '${indexName}'`);
|
|
3209
3327
|
} catch (error$1) {
|
|
3328
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
3210
3329
|
throw new error.MastraError(
|
|
3211
3330
|
{
|
|
3212
3331
|
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_FAILED",
|
|
3213
3332
|
domain: error.ErrorDomain.STORAGE,
|
|
3214
3333
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3215
|
-
details: {
|
|
3334
|
+
details: {
|
|
3335
|
+
indexName,
|
|
3336
|
+
..."id" in params && params.id && { id: params.id },
|
|
3337
|
+
..."filter" in params && params.filter && { filter: JSON.stringify(params.filter) },
|
|
3338
|
+
hasVector: !!update.vector,
|
|
3339
|
+
hasMetadata: !!update.metadata
|
|
3340
|
+
}
|
|
3216
3341
|
},
|
|
3217
3342
|
error$1
|
|
3218
3343
|
);
|
|
@@ -3235,7 +3360,10 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3235
3360
|
id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED_INVALID_ARGS",
|
|
3236
3361
|
domain: error.ErrorDomain.STORAGE,
|
|
3237
3362
|
category: error.ErrorCategory.USER,
|
|
3238
|
-
details: {
|
|
3363
|
+
details: {
|
|
3364
|
+
indexName,
|
|
3365
|
+
...id && { id }
|
|
3366
|
+
}
|
|
3239
3367
|
},
|
|
3240
3368
|
err
|
|
3241
3369
|
);
|
|
@@ -3265,7 +3393,10 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3265
3393
|
id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED",
|
|
3266
3394
|
domain: error.ErrorDomain.STORAGE,
|
|
3267
3395
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
3268
|
-
details: {
|
|
3396
|
+
details: {
|
|
3397
|
+
indexName,
|
|
3398
|
+
...id && { id }
|
|
3399
|
+
}
|
|
3269
3400
|
},
|
|
3270
3401
|
error$1
|
|
3271
3402
|
);
|
|
@@ -3296,6 +3427,109 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3296
3427
|
});
|
|
3297
3428
|
return result;
|
|
3298
3429
|
}
|
|
3430
|
+
async deleteVectors({ indexName, filter, ids }) {
|
|
3431
|
+
if (ids && filter) {
|
|
3432
|
+
throw new error.MastraError({
|
|
3433
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
|
|
3434
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3435
|
+
category: error.ErrorCategory.USER,
|
|
3436
|
+
text: "ids and filter are mutually exclusive",
|
|
3437
|
+
details: { indexName }
|
|
3438
|
+
});
|
|
3439
|
+
}
|
|
3440
|
+
if (!ids && !filter) {
|
|
3441
|
+
throw new error.MastraError({
|
|
3442
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
|
|
3443
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3444
|
+
category: error.ErrorCategory.USER,
|
|
3445
|
+
text: "Either filter or ids must be provided",
|
|
3446
|
+
details: { indexName }
|
|
3447
|
+
});
|
|
3448
|
+
}
|
|
3449
|
+
if (ids && ids.length === 0) {
|
|
3450
|
+
throw new error.MastraError({
|
|
3451
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
|
|
3452
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3453
|
+
category: error.ErrorCategory.USER,
|
|
3454
|
+
text: "Cannot delete with empty ids array",
|
|
3455
|
+
details: { indexName }
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
if (filter && Object.keys(filter).length === 0) {
|
|
3459
|
+
throw new error.MastraError({
|
|
3460
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
|
|
3461
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3462
|
+
category: error.ErrorCategory.USER,
|
|
3463
|
+
text: "Cannot delete with empty filter",
|
|
3464
|
+
details: { indexName }
|
|
3465
|
+
});
|
|
3466
|
+
}
|
|
3467
|
+
try {
|
|
3468
|
+
if (!this.lanceClient) {
|
|
3469
|
+
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
3470
|
+
}
|
|
3471
|
+
if (!indexName) {
|
|
3472
|
+
throw new Error("indexName is required");
|
|
3473
|
+
}
|
|
3474
|
+
const tables = await this.lanceClient.tableNames();
|
|
3475
|
+
for (const tableName of tables) {
|
|
3476
|
+
this.logger.debug("Checking table:" + tableName);
|
|
3477
|
+
const table = await this.lanceClient.openTable(tableName);
|
|
3478
|
+
try {
|
|
3479
|
+
const schema = await table.schema();
|
|
3480
|
+
const hasColumn = schema.fields.some((field) => field.name === indexName);
|
|
3481
|
+
if (hasColumn) {
|
|
3482
|
+
this.logger.debug(`Found column ${indexName} in table ${tableName}`);
|
|
3483
|
+
if (ids) {
|
|
3484
|
+
const idsConditions = ids.map((id) => `id = '${id}'`).join(" OR ");
|
|
3485
|
+
await table.delete(idsConditions);
|
|
3486
|
+
} else if (filter) {
|
|
3487
|
+
const translator = new LanceFilterTranslator();
|
|
3488
|
+
const processFilterKeys = (filter2) => {
|
|
3489
|
+
const processedFilter = {};
|
|
3490
|
+
Object.entries(filter2).forEach(([key, value]) => {
|
|
3491
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
3492
|
+
Object.entries(value).forEach(([nestedKey, nestedValue]) => {
|
|
3493
|
+
processedFilter[`metadata_${key}_${nestedKey}`] = nestedValue;
|
|
3494
|
+
});
|
|
3495
|
+
} else {
|
|
3496
|
+
processedFilter[`metadata_${key}`] = value;
|
|
3497
|
+
}
|
|
3498
|
+
});
|
|
3499
|
+
return processedFilter;
|
|
3500
|
+
};
|
|
3501
|
+
const prefixedFilter = processFilterKeys(filter);
|
|
3502
|
+
const whereClause = translator.translate(prefixedFilter);
|
|
3503
|
+
if (!whereClause) {
|
|
3504
|
+
throw new Error("Failed to translate filter to SQL");
|
|
3505
|
+
}
|
|
3506
|
+
await table.delete(whereClause);
|
|
3507
|
+
}
|
|
3508
|
+
return;
|
|
3509
|
+
}
|
|
3510
|
+
} catch (err) {
|
|
3511
|
+
this.logger.error(`Error checking schema for table ${tableName}:` + err);
|
|
3512
|
+
continue;
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
throw new Error(`No table found with column/index '${indexName}'`);
|
|
3516
|
+
} catch (error$1) {
|
|
3517
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
3518
|
+
throw new error.MastraError(
|
|
3519
|
+
{
|
|
3520
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_FAILED",
|
|
3521
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3522
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
3523
|
+
details: {
|
|
3524
|
+
indexName,
|
|
3525
|
+
...filter && { filter: JSON.stringify(filter) },
|
|
3526
|
+
...ids && { idsCount: ids.length }
|
|
3527
|
+
}
|
|
3528
|
+
},
|
|
3529
|
+
error$1
|
|
3530
|
+
);
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3299
3533
|
};
|
|
3300
3534
|
|
|
3301
3535
|
exports.LanceStorage = LanceStorage;
|