@mastra/lance 1.0.0-beta.0 → 1.0.0-beta.2
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 +22 -0
- package/dist/index.cjs +217 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +217 -46
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflows/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 +8 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @mastra/lance
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add new deleteVectors, updateVector by filter ([#10408](https://github.com/mastra-ai/mastra/pull/10408))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`21a15de`](https://github.com/mastra-ai/mastra/commit/21a15de369fe82aac26bb642ed7be73505475e8b), [`feb7ee4`](https://github.com/mastra-ai/mastra/commit/feb7ee4d09a75edb46c6669a3beaceec78811747), [`b0e2ea5`](https://github.com/mastra-ai/mastra/commit/b0e2ea5b52c40fae438b9e2f7baee6f0f89c5442), [`c456e01`](https://github.com/mastra-ai/mastra/commit/c456e0149e3c176afcefdbd9bb1d2c5917723725), [`ab035c2`](https://github.com/mastra-ai/mastra/commit/ab035c2ef6d8cc7bb25f06f1a38508bd9e6f126b), [`1a46a56`](https://github.com/mastra-ai/mastra/commit/1a46a566f45a3fcbadc1cf36bf86d351f264bfa3), [`3cf540b`](https://github.com/mastra-ai/mastra/commit/3cf540b9fbfea8f4fc8d3a2319a4e6c0b0cbfd52), [`1c6ce51`](https://github.com/mastra-ai/mastra/commit/1c6ce51f875915ab57fd36873623013699a2a65d), [`898a972`](https://github.com/mastra-ai/mastra/commit/898a9727d286c2510d6b702dfd367e6aaf5c6b0f), [`a97003a`](https://github.com/mastra-ai/mastra/commit/a97003aa1cf2f4022a41912324a1e77263b326b8), [`ccc141e`](https://github.com/mastra-ai/mastra/commit/ccc141ed27da0abc3a3fc28e9e5128152e8e37f4), [`fe3b897`](https://github.com/mastra-ai/mastra/commit/fe3b897c2ccbcd2b10e81b099438c7337feddf89), [`00123ba`](https://github.com/mastra-ai/mastra/commit/00123ba96dc9e5cd0b110420ebdba56d8f237b25), [`29c4309`](https://github.com/mastra-ai/mastra/commit/29c4309f818b24304c041bcb4a8f19b5f13f6b62), [`16785ce`](https://github.com/mastra-ai/mastra/commit/16785ced928f6f22638f4488cf8a125d99211799), [`de8239b`](https://github.com/mastra-ai/mastra/commit/de8239bdcb1d8c0cfa06da21f1569912a66bbc8a), [`b5e6cd7`](https://github.com/mastra-ai/mastra/commit/b5e6cd77fc8c8e64e0494c1d06cee3d84e795d1e), [`3759cb0`](https://github.com/mastra-ai/mastra/commit/3759cb064935b5f74c65ac2f52a1145f7352899d), [`651e772`](https://github.com/mastra-ai/mastra/commit/651e772eb1475fb13e126d3fcc01751297a88214), [`b61b93f`](https://github.com/mastra-ai/mastra/commit/b61b93f9e058b11dd2eec169853175d31dbdd567), [`bae33d9`](https://github.com/mastra-ai/mastra/commit/bae33d91a63fbb64d1e80519e1fc1acaed1e9013), [`c0b731f`](https://github.com/mastra-ai/mastra/commit/c0b731fb27d712dc8582e846df5c0332a6a0c5ba), [`43ca8f2`](https://github.com/mastra-ai/mastra/commit/43ca8f2c7334851cc7b4d3d2f037d8784bfbdd5f), [`2ca67cc`](https://github.com/mastra-ai/mastra/commit/2ca67cc3bb1f6a617353fdcab197d9efebe60d6f), [`9e67002`](https://github.com/mastra-ai/mastra/commit/9e67002b52c9be19936c420a489dbee9c5fd6a78), [`35edc49`](https://github.com/mastra-ai/mastra/commit/35edc49ac0556db609189641d6341e76771b81fc)]:
|
|
10
|
+
- @mastra/core@1.0.0-beta.5
|
|
11
|
+
|
|
12
|
+
## 1.0.0-beta.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- dependencies updates: ([#9921](https://github.com/mastra-ai/mastra/pull/9921))
|
|
17
|
+
- Updated dependency [`@lancedb/lancedb@^0.22.3` ↗︎](https://www.npmjs.com/package/@lancedb/lancedb/v/0.22.3) (from `^0.22.2`, in `dependencies`)
|
|
18
|
+
|
|
19
|
+
- Add restart method to workflow run that allows restarting an active workflow run ([#9750](https://github.com/mastra-ai/mastra/pull/9750))
|
|
20
|
+
Add status filter to `listWorkflowRuns`
|
|
21
|
+
Add automatic restart to restart active workflow runs when server starts
|
|
22
|
+
- Updated dependencies [[`2319326`](https://github.com/mastra-ai/mastra/commit/2319326f8c64e503a09bbcf14be2dd65405445e0), [`d629361`](https://github.com/mastra-ai/mastra/commit/d629361a60f6565b5bfb11976fdaf7308af858e2), [`08c31c1`](https://github.com/mastra-ai/mastra/commit/08c31c188ebccd598acaf55e888b6397d01f7eae), [`fd3d338`](https://github.com/mastra-ai/mastra/commit/fd3d338a2c362174ed5b383f1f011ad9fb0302aa), [`c30400a`](https://github.com/mastra-ai/mastra/commit/c30400a49b994b1b97256fe785eb6c906fc2b232), [`69e0a87`](https://github.com/mastra-ai/mastra/commit/69e0a878896a2da9494945d86e056a5f8f05b851), [`01f8878`](https://github.com/mastra-ai/mastra/commit/01f88783de25e4de048c1c8aace43e26373c6ea5), [`4c77209`](https://github.com/mastra-ai/mastra/commit/4c77209e6c11678808b365d545845918c40045c8), [`d827d08`](https://github.com/mastra-ai/mastra/commit/d827d0808ffe1f3553a84e975806cc989b9735dd), [`23c10a1`](https://github.com/mastra-ai/mastra/commit/23c10a1efdd9a693c405511ab2dc8a1236603162), [`676ccc7`](https://github.com/mastra-ai/mastra/commit/676ccc7fe92468d2d45d39c31a87825c89fd1ea0), [`c10398d`](https://github.com/mastra-ai/mastra/commit/c10398d5b88f1d4af556f4267ff06f1d11e89179), [`00c2387`](https://github.com/mastra-ai/mastra/commit/00c2387f5f04a365316f851e58666ac43f8c4edf), [`ad6250d`](https://github.com/mastra-ai/mastra/commit/ad6250dbdaad927e29f74a27b83f6c468b50a705), [`3a73998`](https://github.com/mastra-ai/mastra/commit/3a73998fa4ebeb7f3dc9301afe78095fc63e7999), [`e16d553`](https://github.com/mastra-ai/mastra/commit/e16d55338403c7553531cc568125c63d53653dff), [`4d59f58`](https://github.com/mastra-ai/mastra/commit/4d59f58de2d90d6e2810a19d4518e38ddddb9038), [`e1bb9c9`](https://github.com/mastra-ai/mastra/commit/e1bb9c94b4eb68b019ae275981be3feb769b5365), [`351a11f`](https://github.com/mastra-ai/mastra/commit/351a11fcaf2ed1008977fa9b9a489fc422e51cd4)]:
|
|
23
|
+
- @mastra/core@1.0.0-beta.3
|
|
24
|
+
|
|
3
25
|
## 1.0.0-beta.0
|
|
4
26
|
|
|
5
27
|
### Major Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1555,11 +1555,13 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1555
1555
|
} else {
|
|
1556
1556
|
createdAt = now;
|
|
1557
1557
|
}
|
|
1558
|
+
const { status, value, ...rest } = snapshot;
|
|
1558
1559
|
const record = {
|
|
1559
1560
|
workflow_name: workflowName,
|
|
1560
1561
|
run_id: runId,
|
|
1561
1562
|
resourceId,
|
|
1562
|
-
snapshot: JSON.stringify(
|
|
1563
|
+
snapshot: JSON.stringify({ status, value, ...rest }),
|
|
1564
|
+
// this is to ensure status is always just before value, for when querying the db by status
|
|
1563
1565
|
createdAt,
|
|
1564
1566
|
updatedAt: now
|
|
1565
1567
|
};
|
|
@@ -1629,6 +1631,10 @@ var StoreWorkflowsLance = class extends storage.WorkflowsStorage {
|
|
|
1629
1631
|
if (args?.workflowName) {
|
|
1630
1632
|
conditions.push(`workflow_name = '${args.workflowName.replace(/'/g, "''")}'`);
|
|
1631
1633
|
}
|
|
1634
|
+
if (args?.status) {
|
|
1635
|
+
const escapedStatus = args.status.replace(/\\/g, "\\\\").replace(/'/g, "''").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
1636
|
+
conditions.push(`\`snapshot\` LIKE '%"status":"${escapedStatus}","value"%'`);
|
|
1637
|
+
}
|
|
1632
1638
|
if (args?.resourceId) {
|
|
1633
1639
|
conditions.push(`\`resourceId\` = '${args.resourceId}'`);
|
|
1634
1640
|
}
|
|
@@ -2839,7 +2845,44 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2839
2845
|
);
|
|
2840
2846
|
}
|
|
2841
2847
|
}
|
|
2842
|
-
async updateVector(
|
|
2848
|
+
async updateVector(params) {
|
|
2849
|
+
const { indexName, update } = params;
|
|
2850
|
+
if ("id" in params && "filter" in params && params.id && params.filter) {
|
|
2851
|
+
throw new error.MastraError({
|
|
2852
|
+
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
2853
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2854
|
+
category: error.ErrorCategory.USER,
|
|
2855
|
+
text: "id and filter are mutually exclusive",
|
|
2856
|
+
details: { indexName }
|
|
2857
|
+
});
|
|
2858
|
+
}
|
|
2859
|
+
if (!("id" in params || "filter" in params) || !params.id && !params.filter) {
|
|
2860
|
+
throw new error.MastraError({
|
|
2861
|
+
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
2862
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2863
|
+
category: error.ErrorCategory.USER,
|
|
2864
|
+
text: "Either id or filter must be provided",
|
|
2865
|
+
details: { indexName }
|
|
2866
|
+
});
|
|
2867
|
+
}
|
|
2868
|
+
if ("filter" in params && params.filter && Object.keys(params.filter).length === 0) {
|
|
2869
|
+
throw new error.MastraError({
|
|
2870
|
+
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
2871
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2872
|
+
category: error.ErrorCategory.USER,
|
|
2873
|
+
text: "Cannot update with empty filter",
|
|
2874
|
+
details: { indexName }
|
|
2875
|
+
});
|
|
2876
|
+
}
|
|
2877
|
+
if (!update.vector && !update.metadata) {
|
|
2878
|
+
throw new error.MastraError({
|
|
2879
|
+
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_INVALID_ARGS",
|
|
2880
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2881
|
+
category: error.ErrorCategory.USER,
|
|
2882
|
+
text: "No updates provided",
|
|
2883
|
+
details: { indexName }
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2843
2886
|
try {
|
|
2844
2887
|
if (!this.lanceClient) {
|
|
2845
2888
|
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
@@ -2847,21 +2890,6 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2847
2890
|
if (!indexName) {
|
|
2848
2891
|
throw new Error("indexName is required");
|
|
2849
2892
|
}
|
|
2850
|
-
if (!id) {
|
|
2851
|
-
throw new Error("id is required");
|
|
2852
|
-
}
|
|
2853
|
-
} catch (err) {
|
|
2854
|
-
throw new error.MastraError(
|
|
2855
|
-
{
|
|
2856
|
-
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_FAILED_INVALID_ARGS",
|
|
2857
|
-
domain: error.ErrorDomain.STORAGE,
|
|
2858
|
-
category: error.ErrorCategory.USER,
|
|
2859
|
-
details: { indexName, id }
|
|
2860
|
-
},
|
|
2861
|
-
err
|
|
2862
|
-
);
|
|
2863
|
-
}
|
|
2864
|
-
try {
|
|
2865
2893
|
const tables = await this.lanceClient.tableNames();
|
|
2866
2894
|
for (const tableName of tables) {
|
|
2867
2895
|
this.logger.debug("Checking table:" + tableName);
|
|
@@ -2871,39 +2899,66 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2871
2899
|
const hasColumn = schema.fields.some((field) => field.name === indexName);
|
|
2872
2900
|
if (hasColumn) {
|
|
2873
2901
|
this.logger.debug(`Found column ${indexName} in table ${tableName}`);
|
|
2874
|
-
|
|
2875
|
-
if (
|
|
2876
|
-
|
|
2902
|
+
let whereClause;
|
|
2903
|
+
if ("id" in params && params.id) {
|
|
2904
|
+
whereClause = `id = '${params.id}'`;
|
|
2905
|
+
} else if ("filter" in params && params.filter) {
|
|
2906
|
+
const translator = new LanceFilterTranslator();
|
|
2907
|
+
const processFilterKeys = (filter) => {
|
|
2908
|
+
const processedFilter = {};
|
|
2909
|
+
Object.entries(filter).forEach(([key, value]) => {
|
|
2910
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
2911
|
+
Object.entries(value).forEach(([nestedKey, nestedValue]) => {
|
|
2912
|
+
processedFilter[`metadata_${key}_${nestedKey}`] = nestedValue;
|
|
2913
|
+
});
|
|
2914
|
+
} else {
|
|
2915
|
+
processedFilter[`metadata_${key}`] = value;
|
|
2916
|
+
}
|
|
2917
|
+
});
|
|
2918
|
+
return processedFilter;
|
|
2919
|
+
};
|
|
2920
|
+
const prefixedFilter = processFilterKeys(params.filter);
|
|
2921
|
+
whereClause = translator.translate(prefixedFilter) || "";
|
|
2922
|
+
if (!whereClause) {
|
|
2923
|
+
throw new Error("Failed to translate filter to SQL");
|
|
2924
|
+
}
|
|
2925
|
+
} else {
|
|
2926
|
+
throw new Error("Either id or filter must be provided");
|
|
2877
2927
|
}
|
|
2878
|
-
const
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2928
|
+
const existingRecords = await table.query().where(whereClause).select(schema.fields.map((field) => field.name)).toArray();
|
|
2929
|
+
if (existingRecords.length === 0) {
|
|
2930
|
+
this.logger.info(`No records found matching criteria in table ${tableName}`);
|
|
2931
|
+
return;
|
|
2932
|
+
}
|
|
2933
|
+
const updatedRecords = existingRecords.map((record) => {
|
|
2934
|
+
const rowData = {};
|
|
2935
|
+
Object.entries(record).forEach(([key, value]) => {
|
|
2936
|
+
if (key !== "_distance") {
|
|
2937
|
+
if (key === indexName) {
|
|
2938
|
+
if (update.vector) {
|
|
2939
|
+
rowData[key] = update.vector;
|
|
2889
2940
|
} else {
|
|
2890
|
-
|
|
2941
|
+
if (Array.isArray(value)) {
|
|
2942
|
+
rowData[key] = [...value];
|
|
2943
|
+
} else if (typeof value === "object" && value !== null) {
|
|
2944
|
+
rowData[key] = Array.from(value);
|
|
2945
|
+
} else {
|
|
2946
|
+
rowData[key] = value;
|
|
2947
|
+
}
|
|
2891
2948
|
}
|
|
2949
|
+
} else {
|
|
2950
|
+
rowData[key] = value;
|
|
2892
2951
|
}
|
|
2893
|
-
} else {
|
|
2894
|
-
rowData[key] = value;
|
|
2895
2952
|
}
|
|
2953
|
+
});
|
|
2954
|
+
if (update.metadata) {
|
|
2955
|
+
Object.entries(update.metadata).forEach(([key, value]) => {
|
|
2956
|
+
rowData[`metadata_${key}`] = value;
|
|
2957
|
+
});
|
|
2896
2958
|
}
|
|
2959
|
+
return rowData;
|
|
2897
2960
|
});
|
|
2898
|
-
|
|
2899
|
-
rowData[indexName] = update.vector;
|
|
2900
|
-
}
|
|
2901
|
-
if (update.metadata) {
|
|
2902
|
-
Object.entries(update.metadata).forEach(([key, value]) => {
|
|
2903
|
-
rowData[`metadata_${key}`] = value;
|
|
2904
|
-
});
|
|
2905
|
-
}
|
|
2906
|
-
await table.add([rowData], { mode: "overwrite" });
|
|
2961
|
+
await table.add(updatedRecords, { mode: "overwrite" });
|
|
2907
2962
|
return;
|
|
2908
2963
|
}
|
|
2909
2964
|
} catch (err) {
|
|
@@ -2913,12 +2968,19 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2913
2968
|
}
|
|
2914
2969
|
throw new Error(`No table found with column/index '${indexName}'`);
|
|
2915
2970
|
} catch (error$1) {
|
|
2971
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
2916
2972
|
throw new error.MastraError(
|
|
2917
2973
|
{
|
|
2918
2974
|
id: "STORAGE_LANCE_VECTOR_UPDATE_VECTOR_FAILED",
|
|
2919
2975
|
domain: error.ErrorDomain.STORAGE,
|
|
2920
2976
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2921
|
-
details: {
|
|
2977
|
+
details: {
|
|
2978
|
+
indexName,
|
|
2979
|
+
..."id" in params && params.id && { id: params.id },
|
|
2980
|
+
..."filter" in params && params.filter && { filter: JSON.stringify(params.filter) },
|
|
2981
|
+
hasVector: !!update.vector,
|
|
2982
|
+
hasMetadata: !!update.metadata
|
|
2983
|
+
}
|
|
2922
2984
|
},
|
|
2923
2985
|
error$1
|
|
2924
2986
|
);
|
|
@@ -2941,7 +3003,10 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2941
3003
|
id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED_INVALID_ARGS",
|
|
2942
3004
|
domain: error.ErrorDomain.STORAGE,
|
|
2943
3005
|
category: error.ErrorCategory.USER,
|
|
2944
|
-
details: {
|
|
3006
|
+
details: {
|
|
3007
|
+
indexName,
|
|
3008
|
+
...id && { id }
|
|
3009
|
+
}
|
|
2945
3010
|
},
|
|
2946
3011
|
err
|
|
2947
3012
|
);
|
|
@@ -2971,7 +3036,10 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
2971
3036
|
id: "STORAGE_LANCE_VECTOR_DELETE_VECTOR_FAILED",
|
|
2972
3037
|
domain: error.ErrorDomain.STORAGE,
|
|
2973
3038
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
2974
|
-
details: {
|
|
3039
|
+
details: {
|
|
3040
|
+
indexName,
|
|
3041
|
+
...id && { id }
|
|
3042
|
+
}
|
|
2975
3043
|
},
|
|
2976
3044
|
error$1
|
|
2977
3045
|
);
|
|
@@ -3002,6 +3070,109 @@ var LanceVectorStore = class _LanceVectorStore extends vector.MastraVector {
|
|
|
3002
3070
|
});
|
|
3003
3071
|
return result;
|
|
3004
3072
|
}
|
|
3073
|
+
async deleteVectors({ indexName, filter, ids }) {
|
|
3074
|
+
if (ids && filter) {
|
|
3075
|
+
throw new error.MastraError({
|
|
3076
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
|
|
3077
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3078
|
+
category: error.ErrorCategory.USER,
|
|
3079
|
+
text: "ids and filter are mutually exclusive",
|
|
3080
|
+
details: { indexName }
|
|
3081
|
+
});
|
|
3082
|
+
}
|
|
3083
|
+
if (!ids && !filter) {
|
|
3084
|
+
throw new error.MastraError({
|
|
3085
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
|
|
3086
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3087
|
+
category: error.ErrorCategory.USER,
|
|
3088
|
+
text: "Either filter or ids must be provided",
|
|
3089
|
+
details: { indexName }
|
|
3090
|
+
});
|
|
3091
|
+
}
|
|
3092
|
+
if (ids && ids.length === 0) {
|
|
3093
|
+
throw new error.MastraError({
|
|
3094
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
|
|
3095
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3096
|
+
category: error.ErrorCategory.USER,
|
|
3097
|
+
text: "Cannot delete with empty ids array",
|
|
3098
|
+
details: { indexName }
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3101
|
+
if (filter && Object.keys(filter).length === 0) {
|
|
3102
|
+
throw new error.MastraError({
|
|
3103
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_INVALID_ARGS",
|
|
3104
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3105
|
+
category: error.ErrorCategory.USER,
|
|
3106
|
+
text: "Cannot delete with empty filter",
|
|
3107
|
+
details: { indexName }
|
|
3108
|
+
});
|
|
3109
|
+
}
|
|
3110
|
+
try {
|
|
3111
|
+
if (!this.lanceClient) {
|
|
3112
|
+
throw new Error("LanceDB client not initialized. Use LanceVectorStore.create() to create an instance");
|
|
3113
|
+
}
|
|
3114
|
+
if (!indexName) {
|
|
3115
|
+
throw new Error("indexName is required");
|
|
3116
|
+
}
|
|
3117
|
+
const tables = await this.lanceClient.tableNames();
|
|
3118
|
+
for (const tableName of tables) {
|
|
3119
|
+
this.logger.debug("Checking table:" + tableName);
|
|
3120
|
+
const table = await this.lanceClient.openTable(tableName);
|
|
3121
|
+
try {
|
|
3122
|
+
const schema = await table.schema();
|
|
3123
|
+
const hasColumn = schema.fields.some((field) => field.name === indexName);
|
|
3124
|
+
if (hasColumn) {
|
|
3125
|
+
this.logger.debug(`Found column ${indexName} in table ${tableName}`);
|
|
3126
|
+
if (ids) {
|
|
3127
|
+
const idsConditions = ids.map((id) => `id = '${id}'`).join(" OR ");
|
|
3128
|
+
await table.delete(idsConditions);
|
|
3129
|
+
} else if (filter) {
|
|
3130
|
+
const translator = new LanceFilterTranslator();
|
|
3131
|
+
const processFilterKeys = (filter2) => {
|
|
3132
|
+
const processedFilter = {};
|
|
3133
|
+
Object.entries(filter2).forEach(([key, value]) => {
|
|
3134
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
3135
|
+
Object.entries(value).forEach(([nestedKey, nestedValue]) => {
|
|
3136
|
+
processedFilter[`metadata_${key}_${nestedKey}`] = nestedValue;
|
|
3137
|
+
});
|
|
3138
|
+
} else {
|
|
3139
|
+
processedFilter[`metadata_${key}`] = value;
|
|
3140
|
+
}
|
|
3141
|
+
});
|
|
3142
|
+
return processedFilter;
|
|
3143
|
+
};
|
|
3144
|
+
const prefixedFilter = processFilterKeys(filter);
|
|
3145
|
+
const whereClause = translator.translate(prefixedFilter);
|
|
3146
|
+
if (!whereClause) {
|
|
3147
|
+
throw new Error("Failed to translate filter to SQL");
|
|
3148
|
+
}
|
|
3149
|
+
await table.delete(whereClause);
|
|
3150
|
+
}
|
|
3151
|
+
return;
|
|
3152
|
+
}
|
|
3153
|
+
} catch (err) {
|
|
3154
|
+
this.logger.error(`Error checking schema for table ${tableName}:` + err);
|
|
3155
|
+
continue;
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
throw new Error(`No table found with column/index '${indexName}'`);
|
|
3159
|
+
} catch (error$1) {
|
|
3160
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
3161
|
+
throw new error.MastraError(
|
|
3162
|
+
{
|
|
3163
|
+
id: "STORAGE_LANCE_VECTOR_DELETE_VECTORS_FAILED",
|
|
3164
|
+
domain: error.ErrorDomain.STORAGE,
|
|
3165
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
3166
|
+
details: {
|
|
3167
|
+
indexName,
|
|
3168
|
+
...filter && { filter: JSON.stringify(filter) },
|
|
3169
|
+
...ids && { idsCount: ids.length }
|
|
3170
|
+
}
|
|
3171
|
+
},
|
|
3172
|
+
error$1
|
|
3173
|
+
);
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3005
3176
|
};
|
|
3006
3177
|
|
|
3007
3178
|
exports.LanceStorage = LanceStorage;
|