@mastra/libsql 0.0.5-alpha.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +51 -0
- package/dist/_tsup-dts-rollup.d.cts +9 -40
- package/dist/_tsup-dts-rollup.d.ts +9 -40
- package/dist/index.cjs +21 -68
- package/dist/index.js +21 -68
- package/package.json +8 -5
- package/src/vector/index.test.ts +2 -100
- package/src/vector/index.ts +16 -80
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/libsql@0.0
|
|
2
|
+
> @mastra/libsql@0.10.0-alpha.1 build /home/runner/work/mastra/mastra/stores/libsql
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 8671ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/libsql/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/libsql/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 8251ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
21
|
-
[32mCJS[39m ⚡️ Build success in
|
|
22
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
23
|
-
[32mESM[39m ⚡️ Build success in
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m45.42 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 1060ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m45.22 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 1062ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @mastra/libsql
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 83da932: Move @mastra/core to peerdeps
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- eabdcd9: [MASTRA-3451] SQL Injection Protection
|
|
12
|
+
- d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
|
|
13
|
+
- a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
|
|
14
|
+
- Updated dependencies [b3a3d63]
|
|
15
|
+
- Updated dependencies [344f453]
|
|
16
|
+
- Updated dependencies [0a3ae6d]
|
|
17
|
+
- Updated dependencies [95911be]
|
|
18
|
+
- Updated dependencies [f53a6ac]
|
|
19
|
+
- Updated dependencies [5eb5a99]
|
|
20
|
+
- Updated dependencies [7e632c5]
|
|
21
|
+
- Updated dependencies [1e9fbfa]
|
|
22
|
+
- Updated dependencies [eabdcd9]
|
|
23
|
+
- Updated dependencies [90be034]
|
|
24
|
+
- Updated dependencies [99f050a]
|
|
25
|
+
- Updated dependencies [d0ee3c6]
|
|
26
|
+
- Updated dependencies [b2ae5aa]
|
|
27
|
+
- Updated dependencies [23f258c]
|
|
28
|
+
- Updated dependencies [a7292b0]
|
|
29
|
+
- Updated dependencies [0dcb9f0]
|
|
30
|
+
- Updated dependencies [2672a05]
|
|
31
|
+
- @mastra/core@0.10.0
|
|
32
|
+
|
|
33
|
+
## 0.1.0-alpha.1
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- 83da932: Move @mastra/core to peerdeps
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
|
|
42
|
+
- Updated dependencies [b3a3d63]
|
|
43
|
+
- Updated dependencies [344f453]
|
|
44
|
+
- Updated dependencies [0a3ae6d]
|
|
45
|
+
- Updated dependencies [95911be]
|
|
46
|
+
- Updated dependencies [5eb5a99]
|
|
47
|
+
- Updated dependencies [7e632c5]
|
|
48
|
+
- Updated dependencies [1e9fbfa]
|
|
49
|
+
- Updated dependencies [b2ae5aa]
|
|
50
|
+
- Updated dependencies [a7292b0]
|
|
51
|
+
- Updated dependencies [0dcb9f0]
|
|
52
|
+
- @mastra/core@0.10.0-alpha.1
|
|
53
|
+
|
|
3
54
|
## 0.0.5-alpha.0
|
|
4
55
|
|
|
5
56
|
### Patch Changes
|
|
@@ -10,9 +10,7 @@ import { MastraStorage } from '@mastra/core/storage';
|
|
|
10
10
|
import { MastraVector } from '@mastra/core/vector';
|
|
11
11
|
import type { MessageType } from '@mastra/core/memory';
|
|
12
12
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
13
|
-
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
14
13
|
import type { QueryResult } from '@mastra/core/vector';
|
|
15
|
-
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
16
14
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
17
15
|
import type { StorageColumn } from '@mastra/core/storage';
|
|
18
16
|
import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
@@ -62,8 +60,6 @@ export declare class LibSQLFilterTranslator extends BaseFilterTranslator {
|
|
|
62
60
|
private translateNode;
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
declare type LibSQLQueryArgs = [...QueryVectorArgs, number?];
|
|
66
|
-
|
|
67
63
|
declare interface LibSQLQueryParams extends QueryVectorParams {
|
|
68
64
|
minScore?: number;
|
|
69
65
|
}
|
|
@@ -155,35 +151,18 @@ declare class LibSQLVector extends MastraVector {
|
|
|
155
151
|
syncInterval?: number;
|
|
156
152
|
});
|
|
157
153
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
158
|
-
query(
|
|
159
|
-
upsert(
|
|
160
|
-
createIndex(
|
|
161
|
-
deleteIndex(
|
|
154
|
+
query({ indexName, queryVector, topK, filter, includeVector, minScore, }: LibSQLQueryParams): Promise<QueryResult[]>;
|
|
155
|
+
upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
|
|
156
|
+
createIndex({ indexName, dimension }: CreateIndexParams): Promise<void>;
|
|
157
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
162
158
|
listIndexes(): Promise<string[]>;
|
|
163
159
|
/**
|
|
164
160
|
* Retrieves statistics about a vector index.
|
|
165
161
|
*
|
|
166
|
-
* @param
|
|
167
|
-
* @param params.indexName - The name of the index to describe
|
|
162
|
+
* @param {string} indexName - The name of the index to describe
|
|
168
163
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
169
164
|
*/
|
|
170
|
-
describeIndex(
|
|
171
|
-
/**
|
|
172
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
173
|
-
*
|
|
174
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
175
|
-
* @param indexName - The name of the index containing the vector.
|
|
176
|
-
* @param id - The ID of the vector to update.
|
|
177
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
178
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
179
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
180
|
-
* @returns A promise that resolves when the update is complete.
|
|
181
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
182
|
-
*/
|
|
183
|
-
updateIndexById(indexName: string, id: string, update: {
|
|
184
|
-
vector?: number[];
|
|
185
|
-
metadata?: Record<string, any>;
|
|
186
|
-
}): Promise<void>;
|
|
165
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
187
166
|
/**
|
|
188
167
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
189
168
|
*
|
|
@@ -195,17 +174,7 @@ declare class LibSQLVector extends MastraVector {
|
|
|
195
174
|
* @returns A promise that resolves when the update is complete.
|
|
196
175
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
197
176
|
*/
|
|
198
|
-
updateVector(
|
|
199
|
-
/**
|
|
200
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
201
|
-
*
|
|
202
|
-
* Deletes a vector by its ID.
|
|
203
|
-
* @param indexName - The name of the index containing the vector.
|
|
204
|
-
* @param id - The ID of the vector to delete.
|
|
205
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
206
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
207
|
-
*/
|
|
208
|
-
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
177
|
+
updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
|
|
209
178
|
/**
|
|
210
179
|
* Deletes a vector by its ID.
|
|
211
180
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -213,8 +182,8 @@ declare class LibSQLVector extends MastraVector {
|
|
|
213
182
|
* @returns A promise that resolves when the deletion is complete.
|
|
214
183
|
* @throws Will throw an error if the deletion operation fails.
|
|
215
184
|
*/
|
|
216
|
-
deleteVector(
|
|
217
|
-
truncateIndex(
|
|
185
|
+
deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
|
|
186
|
+
truncateIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
218
187
|
}
|
|
219
188
|
export { LibSQLVector }
|
|
220
189
|
export { LibSQLVector as LibSQLVector_alias_1 }
|
|
@@ -10,9 +10,7 @@ import { MastraStorage } from '@mastra/core/storage';
|
|
|
10
10
|
import { MastraVector } from '@mastra/core/vector';
|
|
11
11
|
import type { MessageType } from '@mastra/core/memory';
|
|
12
12
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
13
|
-
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
14
13
|
import type { QueryResult } from '@mastra/core/vector';
|
|
15
|
-
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
16
14
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
17
15
|
import type { StorageColumn } from '@mastra/core/storage';
|
|
18
16
|
import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
@@ -62,8 +60,6 @@ export declare class LibSQLFilterTranslator extends BaseFilterTranslator {
|
|
|
62
60
|
private translateNode;
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
declare type LibSQLQueryArgs = [...QueryVectorArgs, number?];
|
|
66
|
-
|
|
67
63
|
declare interface LibSQLQueryParams extends QueryVectorParams {
|
|
68
64
|
minScore?: number;
|
|
69
65
|
}
|
|
@@ -155,35 +151,18 @@ declare class LibSQLVector extends MastraVector {
|
|
|
155
151
|
syncInterval?: number;
|
|
156
152
|
});
|
|
157
153
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
158
|
-
query(
|
|
159
|
-
upsert(
|
|
160
|
-
createIndex(
|
|
161
|
-
deleteIndex(
|
|
154
|
+
query({ indexName, queryVector, topK, filter, includeVector, minScore, }: LibSQLQueryParams): Promise<QueryResult[]>;
|
|
155
|
+
upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
|
|
156
|
+
createIndex({ indexName, dimension }: CreateIndexParams): Promise<void>;
|
|
157
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
162
158
|
listIndexes(): Promise<string[]>;
|
|
163
159
|
/**
|
|
164
160
|
* Retrieves statistics about a vector index.
|
|
165
161
|
*
|
|
166
|
-
* @param
|
|
167
|
-
* @param params.indexName - The name of the index to describe
|
|
162
|
+
* @param {string} indexName - The name of the index to describe
|
|
168
163
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
169
164
|
*/
|
|
170
|
-
describeIndex(
|
|
171
|
-
/**
|
|
172
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
173
|
-
*
|
|
174
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
175
|
-
* @param indexName - The name of the index containing the vector.
|
|
176
|
-
* @param id - The ID of the vector to update.
|
|
177
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
178
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
179
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
180
|
-
* @returns A promise that resolves when the update is complete.
|
|
181
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
182
|
-
*/
|
|
183
|
-
updateIndexById(indexName: string, id: string, update: {
|
|
184
|
-
vector?: number[];
|
|
185
|
-
metadata?: Record<string, any>;
|
|
186
|
-
}): Promise<void>;
|
|
165
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
187
166
|
/**
|
|
188
167
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
189
168
|
*
|
|
@@ -195,17 +174,7 @@ declare class LibSQLVector extends MastraVector {
|
|
|
195
174
|
* @returns A promise that resolves when the update is complete.
|
|
196
175
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
197
176
|
*/
|
|
198
|
-
updateVector(
|
|
199
|
-
/**
|
|
200
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
201
|
-
*
|
|
202
|
-
* Deletes a vector by its ID.
|
|
203
|
-
* @param indexName - The name of the index containing the vector.
|
|
204
|
-
* @param id - The ID of the vector to delete.
|
|
205
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
206
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
207
|
-
*/
|
|
208
|
-
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
177
|
+
updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
|
|
209
178
|
/**
|
|
210
179
|
* Deletes a vector by its ID.
|
|
211
180
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -213,8 +182,8 @@ declare class LibSQLVector extends MastraVector {
|
|
|
213
182
|
* @returns A promise that resolves when the deletion is complete.
|
|
214
183
|
* @throws Will throw an error if the deletion operation fails.
|
|
215
184
|
*/
|
|
216
|
-
deleteVector(
|
|
217
|
-
truncateIndex(
|
|
185
|
+
deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
|
|
186
|
+
truncateIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
218
187
|
}
|
|
219
188
|
export { LibSQLVector }
|
|
220
189
|
export { LibSQLVector as LibSQLVector_alias_1 }
|
package/dist/index.cjs
CHANGED
|
@@ -508,10 +508,15 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
508
508
|
const translator = new LibSQLFilterTranslator();
|
|
509
509
|
return translator.translate(filter);
|
|
510
510
|
}
|
|
511
|
-
async query(
|
|
512
|
-
|
|
511
|
+
async query({
|
|
512
|
+
indexName,
|
|
513
|
+
queryVector,
|
|
514
|
+
topK = 10,
|
|
515
|
+
filter,
|
|
516
|
+
includeVector = false,
|
|
517
|
+
minScore = 0
|
|
518
|
+
}) {
|
|
513
519
|
try {
|
|
514
|
-
const { indexName, queryVector, topK = 10, filter, includeVector = false, minScore = 0 } = params;
|
|
515
520
|
if (!Number.isInteger(topK) || topK <= 0) {
|
|
516
521
|
throw new Error("topK must be a positive integer");
|
|
517
522
|
}
|
|
@@ -552,9 +557,7 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
552
557
|
} finally {
|
|
553
558
|
}
|
|
554
559
|
}
|
|
555
|
-
async upsert(
|
|
556
|
-
const params = this.normalizeArgs("upsert", args);
|
|
557
|
-
const { indexName, vectors, metadata, ids } = params;
|
|
560
|
+
async upsert({ indexName, vectors, metadata, ids }) {
|
|
558
561
|
const tx = await this.turso.transaction("write");
|
|
559
562
|
try {
|
|
560
563
|
const parsedIndexName = utils.parseSqlIdentifier(indexName, "index name");
|
|
@@ -595,9 +598,7 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
595
598
|
throw error;
|
|
596
599
|
}
|
|
597
600
|
}
|
|
598
|
-
async createIndex(
|
|
599
|
-
const params = this.normalizeArgs("createIndex", args);
|
|
600
|
-
const { indexName, dimension } = params;
|
|
601
|
+
async createIndex({ indexName, dimension }) {
|
|
601
602
|
try {
|
|
602
603
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
603
604
|
throw new Error("Dimension must be a positive integer");
|
|
@@ -627,9 +628,7 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
627
628
|
} finally {
|
|
628
629
|
}
|
|
629
630
|
}
|
|
630
|
-
async deleteIndex(
|
|
631
|
-
const params = this.normalizeArgs("deleteIndex", args);
|
|
632
|
-
const { indexName } = params;
|
|
631
|
+
async deleteIndex({ indexName }) {
|
|
633
632
|
try {
|
|
634
633
|
const parsedIndexName = utils.parseSqlIdentifier(indexName, "index name");
|
|
635
634
|
await this.turso.execute({
|
|
@@ -661,13 +660,10 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
661
660
|
/**
|
|
662
661
|
* Retrieves statistics about a vector index.
|
|
663
662
|
*
|
|
664
|
-
* @param
|
|
665
|
-
* @param params.indexName - The name of the index to describe
|
|
663
|
+
* @param {string} indexName - The name of the index to describe
|
|
666
664
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
667
665
|
*/
|
|
668
|
-
async describeIndex(
|
|
669
|
-
const params = this.normalizeArgs("describeIndex", args);
|
|
670
|
-
const { indexName } = params;
|
|
666
|
+
async describeIndex({ indexName }) {
|
|
671
667
|
try {
|
|
672
668
|
const parsedIndexName = utils.parseSqlIdentifier(indexName, "index name");
|
|
673
669
|
const tableInfoQuery = `
|
|
@@ -702,26 +698,6 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
702
698
|
throw new Error(`Failed to describe vector table: ${e.message}`);
|
|
703
699
|
}
|
|
704
700
|
}
|
|
705
|
-
/**
|
|
706
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
707
|
-
*
|
|
708
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
709
|
-
* @param indexName - The name of the index containing the vector.
|
|
710
|
-
* @param id - The ID of the vector to update.
|
|
711
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
712
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
713
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
714
|
-
* @returns A promise that resolves when the update is complete.
|
|
715
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
716
|
-
*/
|
|
717
|
-
async updateIndexById(indexName, id, update) {
|
|
718
|
-
this.logger.warn(
|
|
719
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
720
|
-
Please use updateVector() instead.
|
|
721
|
-
updateIndexById() will be removed on May 20th, 2025.`
|
|
722
|
-
);
|
|
723
|
-
await this.updateVector({ indexName, id, update });
|
|
724
|
-
}
|
|
725
701
|
/**
|
|
726
702
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
727
703
|
*
|
|
@@ -733,25 +709,23 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
733
709
|
* @returns A promise that resolves when the update is complete.
|
|
734
710
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
735
711
|
*/
|
|
736
|
-
async updateVector(
|
|
737
|
-
const params = this.normalizeArgs("updateVector", args);
|
|
738
|
-
const { indexName, id, update } = params;
|
|
712
|
+
async updateVector({ indexName, id, update }) {
|
|
739
713
|
try {
|
|
740
714
|
const parsedIndexName = utils.parseSqlIdentifier(indexName, "index name");
|
|
741
715
|
const updates = [];
|
|
742
|
-
const
|
|
716
|
+
const args = [];
|
|
743
717
|
if (update.vector) {
|
|
744
718
|
updates.push("embedding = vector32(?)");
|
|
745
|
-
|
|
719
|
+
args.push(JSON.stringify(update.vector));
|
|
746
720
|
}
|
|
747
721
|
if (update.metadata) {
|
|
748
722
|
updates.push("metadata = ?");
|
|
749
|
-
|
|
723
|
+
args.push(JSON.stringify(update.metadata));
|
|
750
724
|
}
|
|
751
725
|
if (updates.length === 0) {
|
|
752
726
|
throw new Error("No updates provided");
|
|
753
727
|
}
|
|
754
|
-
|
|
728
|
+
args.push(id);
|
|
755
729
|
const query = `
|
|
756
730
|
UPDATE ${parsedIndexName}
|
|
757
731
|
SET ${updates.join(", ")}
|
|
@@ -759,29 +733,12 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
759
733
|
`;
|
|
760
734
|
await this.turso.execute({
|
|
761
735
|
sql: query,
|
|
762
|
-
args
|
|
736
|
+
args
|
|
763
737
|
});
|
|
764
738
|
} catch (error) {
|
|
765
739
|
throw new Error(`Failed to update vector by id: ${id} for index: ${indexName}: ${error.message}`);
|
|
766
740
|
}
|
|
767
741
|
}
|
|
768
|
-
/**
|
|
769
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
770
|
-
*
|
|
771
|
-
* Deletes a vector by its ID.
|
|
772
|
-
* @param indexName - The name of the index containing the vector.
|
|
773
|
-
* @param id - The ID of the vector to delete.
|
|
774
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
775
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
776
|
-
*/
|
|
777
|
-
async deleteIndexById(indexName, id) {
|
|
778
|
-
this.logger.warn(
|
|
779
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
780
|
-
Please use deleteVector() instead.
|
|
781
|
-
deleteIndexById() will be removed on May 20th, 2025.`
|
|
782
|
-
);
|
|
783
|
-
await this.deleteVector({ indexName, id });
|
|
784
|
-
}
|
|
785
742
|
/**
|
|
786
743
|
* Deletes a vector by its ID.
|
|
787
744
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -789,9 +746,7 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
789
746
|
* @returns A promise that resolves when the deletion is complete.
|
|
790
747
|
* @throws Will throw an error if the deletion operation fails.
|
|
791
748
|
*/
|
|
792
|
-
async deleteVector(
|
|
793
|
-
const params = this.normalizeArgs("deleteVector", args);
|
|
794
|
-
const { indexName, id } = params;
|
|
749
|
+
async deleteVector({ indexName, id }) {
|
|
795
750
|
try {
|
|
796
751
|
const parsedIndexName = utils.parseSqlIdentifier(indexName, "index name");
|
|
797
752
|
await this.turso.execute({
|
|
@@ -802,9 +757,7 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
802
757
|
throw new Error(`Failed to delete vector by id: ${id} for index: ${indexName}: ${error.message}`);
|
|
803
758
|
}
|
|
804
759
|
}
|
|
805
|
-
async truncateIndex(
|
|
806
|
-
const params = this.normalizeArgs("truncateIndex", args);
|
|
807
|
-
const { indexName } = params;
|
|
760
|
+
async truncateIndex({ indexName }) {
|
|
808
761
|
await this.turso.execute({
|
|
809
762
|
sql: `DELETE FROM ${utils.parseSqlIdentifier(indexName, "index name")}`,
|
|
810
763
|
args: []
|
package/dist/index.js
CHANGED
|
@@ -506,10 +506,15 @@ var LibSQLVector = class extends MastraVector {
|
|
|
506
506
|
const translator = new LibSQLFilterTranslator();
|
|
507
507
|
return translator.translate(filter);
|
|
508
508
|
}
|
|
509
|
-
async query(
|
|
510
|
-
|
|
509
|
+
async query({
|
|
510
|
+
indexName,
|
|
511
|
+
queryVector,
|
|
512
|
+
topK = 10,
|
|
513
|
+
filter,
|
|
514
|
+
includeVector = false,
|
|
515
|
+
minScore = 0
|
|
516
|
+
}) {
|
|
511
517
|
try {
|
|
512
|
-
const { indexName, queryVector, topK = 10, filter, includeVector = false, minScore = 0 } = params;
|
|
513
518
|
if (!Number.isInteger(topK) || topK <= 0) {
|
|
514
519
|
throw new Error("topK must be a positive integer");
|
|
515
520
|
}
|
|
@@ -550,9 +555,7 @@ var LibSQLVector = class extends MastraVector {
|
|
|
550
555
|
} finally {
|
|
551
556
|
}
|
|
552
557
|
}
|
|
553
|
-
async upsert(
|
|
554
|
-
const params = this.normalizeArgs("upsert", args);
|
|
555
|
-
const { indexName, vectors, metadata, ids } = params;
|
|
558
|
+
async upsert({ indexName, vectors, metadata, ids }) {
|
|
556
559
|
const tx = await this.turso.transaction("write");
|
|
557
560
|
try {
|
|
558
561
|
const parsedIndexName = parseSqlIdentifier(indexName, "index name");
|
|
@@ -593,9 +596,7 @@ var LibSQLVector = class extends MastraVector {
|
|
|
593
596
|
throw error;
|
|
594
597
|
}
|
|
595
598
|
}
|
|
596
|
-
async createIndex(
|
|
597
|
-
const params = this.normalizeArgs("createIndex", args);
|
|
598
|
-
const { indexName, dimension } = params;
|
|
599
|
+
async createIndex({ indexName, dimension }) {
|
|
599
600
|
try {
|
|
600
601
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
601
602
|
throw new Error("Dimension must be a positive integer");
|
|
@@ -625,9 +626,7 @@ var LibSQLVector = class extends MastraVector {
|
|
|
625
626
|
} finally {
|
|
626
627
|
}
|
|
627
628
|
}
|
|
628
|
-
async deleteIndex(
|
|
629
|
-
const params = this.normalizeArgs("deleteIndex", args);
|
|
630
|
-
const { indexName } = params;
|
|
629
|
+
async deleteIndex({ indexName }) {
|
|
631
630
|
try {
|
|
632
631
|
const parsedIndexName = parseSqlIdentifier(indexName, "index name");
|
|
633
632
|
await this.turso.execute({
|
|
@@ -659,13 +658,10 @@ var LibSQLVector = class extends MastraVector {
|
|
|
659
658
|
/**
|
|
660
659
|
* Retrieves statistics about a vector index.
|
|
661
660
|
*
|
|
662
|
-
* @param
|
|
663
|
-
* @param params.indexName - The name of the index to describe
|
|
661
|
+
* @param {string} indexName - The name of the index to describe
|
|
664
662
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
665
663
|
*/
|
|
666
|
-
async describeIndex(
|
|
667
|
-
const params = this.normalizeArgs("describeIndex", args);
|
|
668
|
-
const { indexName } = params;
|
|
664
|
+
async describeIndex({ indexName }) {
|
|
669
665
|
try {
|
|
670
666
|
const parsedIndexName = parseSqlIdentifier(indexName, "index name");
|
|
671
667
|
const tableInfoQuery = `
|
|
@@ -700,26 +696,6 @@ var LibSQLVector = class extends MastraVector {
|
|
|
700
696
|
throw new Error(`Failed to describe vector table: ${e.message}`);
|
|
701
697
|
}
|
|
702
698
|
}
|
|
703
|
-
/**
|
|
704
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
705
|
-
*
|
|
706
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
707
|
-
* @param indexName - The name of the index containing the vector.
|
|
708
|
-
* @param id - The ID of the vector to update.
|
|
709
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
710
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
711
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
712
|
-
* @returns A promise that resolves when the update is complete.
|
|
713
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
714
|
-
*/
|
|
715
|
-
async updateIndexById(indexName, id, update) {
|
|
716
|
-
this.logger.warn(
|
|
717
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
718
|
-
Please use updateVector() instead.
|
|
719
|
-
updateIndexById() will be removed on May 20th, 2025.`
|
|
720
|
-
);
|
|
721
|
-
await this.updateVector({ indexName, id, update });
|
|
722
|
-
}
|
|
723
699
|
/**
|
|
724
700
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
725
701
|
*
|
|
@@ -731,25 +707,23 @@ var LibSQLVector = class extends MastraVector {
|
|
|
731
707
|
* @returns A promise that resolves when the update is complete.
|
|
732
708
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
733
709
|
*/
|
|
734
|
-
async updateVector(
|
|
735
|
-
const params = this.normalizeArgs("updateVector", args);
|
|
736
|
-
const { indexName, id, update } = params;
|
|
710
|
+
async updateVector({ indexName, id, update }) {
|
|
737
711
|
try {
|
|
738
712
|
const parsedIndexName = parseSqlIdentifier(indexName, "index name");
|
|
739
713
|
const updates = [];
|
|
740
|
-
const
|
|
714
|
+
const args = [];
|
|
741
715
|
if (update.vector) {
|
|
742
716
|
updates.push("embedding = vector32(?)");
|
|
743
|
-
|
|
717
|
+
args.push(JSON.stringify(update.vector));
|
|
744
718
|
}
|
|
745
719
|
if (update.metadata) {
|
|
746
720
|
updates.push("metadata = ?");
|
|
747
|
-
|
|
721
|
+
args.push(JSON.stringify(update.metadata));
|
|
748
722
|
}
|
|
749
723
|
if (updates.length === 0) {
|
|
750
724
|
throw new Error("No updates provided");
|
|
751
725
|
}
|
|
752
|
-
|
|
726
|
+
args.push(id);
|
|
753
727
|
const query = `
|
|
754
728
|
UPDATE ${parsedIndexName}
|
|
755
729
|
SET ${updates.join(", ")}
|
|
@@ -757,29 +731,12 @@ var LibSQLVector = class extends MastraVector {
|
|
|
757
731
|
`;
|
|
758
732
|
await this.turso.execute({
|
|
759
733
|
sql: query,
|
|
760
|
-
args
|
|
734
|
+
args
|
|
761
735
|
});
|
|
762
736
|
} catch (error) {
|
|
763
737
|
throw new Error(`Failed to update vector by id: ${id} for index: ${indexName}: ${error.message}`);
|
|
764
738
|
}
|
|
765
739
|
}
|
|
766
|
-
/**
|
|
767
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
768
|
-
*
|
|
769
|
-
* Deletes a vector by its ID.
|
|
770
|
-
* @param indexName - The name of the index containing the vector.
|
|
771
|
-
* @param id - The ID of the vector to delete.
|
|
772
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
773
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
774
|
-
*/
|
|
775
|
-
async deleteIndexById(indexName, id) {
|
|
776
|
-
this.logger.warn(
|
|
777
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
778
|
-
Please use deleteVector() instead.
|
|
779
|
-
deleteIndexById() will be removed on May 20th, 2025.`
|
|
780
|
-
);
|
|
781
|
-
await this.deleteVector({ indexName, id });
|
|
782
|
-
}
|
|
783
740
|
/**
|
|
784
741
|
* Deletes a vector by its ID.
|
|
785
742
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -787,9 +744,7 @@ var LibSQLVector = class extends MastraVector {
|
|
|
787
744
|
* @returns A promise that resolves when the deletion is complete.
|
|
788
745
|
* @throws Will throw an error if the deletion operation fails.
|
|
789
746
|
*/
|
|
790
|
-
async deleteVector(
|
|
791
|
-
const params = this.normalizeArgs("deleteVector", args);
|
|
792
|
-
const { indexName, id } = params;
|
|
747
|
+
async deleteVector({ indexName, id }) {
|
|
793
748
|
try {
|
|
794
749
|
const parsedIndexName = parseSqlIdentifier(indexName, "index name");
|
|
795
750
|
await this.turso.execute({
|
|
@@ -800,9 +755,7 @@ var LibSQLVector = class extends MastraVector {
|
|
|
800
755
|
throw new Error(`Failed to delete vector by id: ${id} for index: ${indexName}: ${error.message}`);
|
|
801
756
|
}
|
|
802
757
|
}
|
|
803
|
-
async truncateIndex(
|
|
804
|
-
const params = this.normalizeArgs("truncateIndex", args);
|
|
805
|
-
const { indexName } = params;
|
|
758
|
+
async truncateIndex({ indexName }) {
|
|
806
759
|
await this.turso.execute({
|
|
807
760
|
sql: `DELETE FROM ${parseSqlIdentifier(indexName, "index name")}`,
|
|
808
761
|
args: []
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/libsql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Libsql provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@libsql/client": "^0.15.4"
|
|
24
|
-
"@mastra/core": "^0.9.5-alpha.0"
|
|
23
|
+
"@libsql/client": "^0.15.4"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
27
26
|
"@microsoft/api-extractor": "^7.52.5",
|
|
@@ -30,8 +29,12 @@
|
|
|
30
29
|
"tsup": "^8.4.0",
|
|
31
30
|
"typescript": "^5.8.3",
|
|
32
31
|
"vitest": "^3.1.2",
|
|
33
|
-
"@internal/lint": "0.0.
|
|
34
|
-
"@internal/storage-test-utils": "0.0.2
|
|
32
|
+
"@internal/lint": "0.0.6",
|
|
33
|
+
"@internal/storage-test-utils": "0.0.2",
|
|
34
|
+
"@mastra/core": "0.10.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@mastra/core": "^0.10.0"
|
|
35
38
|
},
|
|
36
39
|
"scripts": {
|
|
37
40
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import { LibSQLVector } from './index.js';
|
|
4
4
|
|
|
@@ -58,7 +58,7 @@ describe('LibSQLVector', () => {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
it('should not return created index in list if it is deleted', async () => {
|
|
61
|
-
await vectorDB.deleteIndex(indexName);
|
|
61
|
+
await vectorDB.deleteIndex({ indexName });
|
|
62
62
|
const indexes = await vectorDB.listIndexes();
|
|
63
63
|
expect(indexes).not.toContain(indexName);
|
|
64
64
|
});
|
|
@@ -1679,102 +1679,4 @@ describe('LibSQLVector', () => {
|
|
|
1679
1679
|
await vectorDB.deleteIndex({ indexName: duplicateIndexName });
|
|
1680
1680
|
});
|
|
1681
1681
|
});
|
|
1682
|
-
|
|
1683
|
-
describe('Deprecation Warnings', () => {
|
|
1684
|
-
const indexName = 'testdeprecationwarnings';
|
|
1685
|
-
|
|
1686
|
-
const indexName2 = 'testdeprecationwarnings2';
|
|
1687
|
-
|
|
1688
|
-
let warnSpy;
|
|
1689
|
-
|
|
1690
|
-
beforeAll(async () => {
|
|
1691
|
-
await vectorDB.createIndex({ indexName: indexName, dimension: 3 });
|
|
1692
|
-
});
|
|
1693
|
-
|
|
1694
|
-
afterAll(async () => {
|
|
1695
|
-
await vectorDB.deleteIndex({ indexName });
|
|
1696
|
-
await vectorDB.deleteIndex({ indexName: indexName2 });
|
|
1697
|
-
});
|
|
1698
|
-
|
|
1699
|
-
beforeEach(async () => {
|
|
1700
|
-
warnSpy = vi.spyOn(vectorDB['logger'], 'warn');
|
|
1701
|
-
});
|
|
1702
|
-
|
|
1703
|
-
afterEach(async () => {
|
|
1704
|
-
warnSpy.mockRestore();
|
|
1705
|
-
await vectorDB.deleteIndex({ indexName: indexName2 });
|
|
1706
|
-
});
|
|
1707
|
-
|
|
1708
|
-
it('should show deprecation warning when using individual args for createIndex', async () => {
|
|
1709
|
-
await vectorDB.createIndex(indexName2, 3, 'cosine');
|
|
1710
|
-
|
|
1711
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1712
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to createIndex() is deprecated'),
|
|
1713
|
-
);
|
|
1714
|
-
});
|
|
1715
|
-
|
|
1716
|
-
it('should show deprecation warning when using individual args for upsert', async () => {
|
|
1717
|
-
await vectorDB.upsert(indexName, [[1, 2, 3]], [{ test: 'data' }]);
|
|
1718
|
-
|
|
1719
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1720
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to upsert() is deprecated'),
|
|
1721
|
-
);
|
|
1722
|
-
});
|
|
1723
|
-
|
|
1724
|
-
it('should show deprecation warning when using individual args for query', async () => {
|
|
1725
|
-
await vectorDB.query(indexName, [1, 2, 3], 5);
|
|
1726
|
-
|
|
1727
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
1728
|
-
expect.stringContaining('Deprecation Warning: Passing individual arguments to query() is deprecated'),
|
|
1729
|
-
);
|
|
1730
|
-
});
|
|
1731
|
-
|
|
1732
|
-
it('should not show deprecation warning when using object param for query', async () => {
|
|
1733
|
-
await vectorDB.query({
|
|
1734
|
-
indexName,
|
|
1735
|
-
queryVector: [1, 2, 3],
|
|
1736
|
-
topK: 5,
|
|
1737
|
-
});
|
|
1738
|
-
|
|
1739
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1740
|
-
});
|
|
1741
|
-
|
|
1742
|
-
it('should not show deprecation warning when using object param for createIndex', async () => {
|
|
1743
|
-
await vectorDB.createIndex({
|
|
1744
|
-
indexName: indexName2,
|
|
1745
|
-
dimension: 3,
|
|
1746
|
-
metric: 'cosine',
|
|
1747
|
-
});
|
|
1748
|
-
|
|
1749
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1750
|
-
});
|
|
1751
|
-
|
|
1752
|
-
it('should not show deprecation warning when using object param for upsert', async () => {
|
|
1753
|
-
await vectorDB.upsert({
|
|
1754
|
-
indexName,
|
|
1755
|
-
vectors: [[1, 2, 3]],
|
|
1756
|
-
metadata: [{ test: 'data' }],
|
|
1757
|
-
});
|
|
1758
|
-
|
|
1759
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
1760
|
-
});
|
|
1761
|
-
|
|
1762
|
-
it('should maintain backward compatibility with individual args', async () => {
|
|
1763
|
-
// Query
|
|
1764
|
-
const queryResults = await vectorDB.query(indexName, [1, 2, 3], 5);
|
|
1765
|
-
expect(Array.isArray(queryResults)).toBe(true);
|
|
1766
|
-
|
|
1767
|
-
// CreateIndex
|
|
1768
|
-
await expect(vectorDB.createIndex(indexName2, 3, 'cosine')).resolves.not.toThrow();
|
|
1769
|
-
|
|
1770
|
-
// Upsert
|
|
1771
|
-
const upsertResults = await vectorDB.upsert({
|
|
1772
|
-
indexName,
|
|
1773
|
-
vectors: [[1, 2, 3]],
|
|
1774
|
-
metadata: [{ test: 'data' }],
|
|
1775
|
-
});
|
|
1776
|
-
expect(Array.isArray(upsertResults)).toBe(true);
|
|
1777
|
-
expect(upsertResults).toHaveLength(1);
|
|
1778
|
-
});
|
|
1779
|
-
});
|
|
1780
1682
|
});
|
package/src/vector/index.ts
CHANGED
|
@@ -9,8 +9,6 @@ import type {
|
|
|
9
9
|
QueryVectorParams,
|
|
10
10
|
CreateIndexParams,
|
|
11
11
|
UpsertVectorParams,
|
|
12
|
-
ParamsToArgs,
|
|
13
|
-
QueryVectorArgs,
|
|
14
12
|
DescribeIndexParams,
|
|
15
13
|
DeleteIndexParams,
|
|
16
14
|
DeleteVectorParams,
|
|
@@ -24,8 +22,6 @@ interface LibSQLQueryParams extends QueryVectorParams {
|
|
|
24
22
|
minScore?: number;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
type LibSQLQueryArgs = [...QueryVectorArgs, number?];
|
|
28
|
-
|
|
29
25
|
export class LibSQLVector extends MastraVector {
|
|
30
26
|
private turso: TursoClient;
|
|
31
27
|
|
|
@@ -62,12 +58,15 @@ export class LibSQLVector extends MastraVector {
|
|
|
62
58
|
return translator.translate(filter);
|
|
63
59
|
}
|
|
64
60
|
|
|
65
|
-
async query(
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
async query({
|
|
62
|
+
indexName,
|
|
63
|
+
queryVector,
|
|
64
|
+
topK = 10,
|
|
65
|
+
filter,
|
|
66
|
+
includeVector = false,
|
|
67
|
+
minScore = 0,
|
|
68
|
+
}: LibSQLQueryParams): Promise<QueryResult[]> {
|
|
68
69
|
try {
|
|
69
|
-
const { indexName, queryVector, topK = 10, filter, includeVector = false, minScore = 0 } = params;
|
|
70
|
-
|
|
71
70
|
if (!Number.isInteger(topK) || topK <= 0) {
|
|
72
71
|
throw new Error('topK must be a positive integer');
|
|
73
72
|
}
|
|
@@ -116,10 +115,7 @@ export class LibSQLVector extends MastraVector {
|
|
|
116
115
|
}
|
|
117
116
|
}
|
|
118
117
|
|
|
119
|
-
async upsert(
|
|
120
|
-
const params = this.normalizeArgs<UpsertVectorParams>('upsert', args);
|
|
121
|
-
|
|
122
|
-
const { indexName, vectors, metadata, ids } = params;
|
|
118
|
+
async upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {
|
|
123
119
|
const tx = await this.turso.transaction('write');
|
|
124
120
|
|
|
125
121
|
try {
|
|
@@ -173,10 +169,7 @@ export class LibSQLVector extends MastraVector {
|
|
|
173
169
|
}
|
|
174
170
|
}
|
|
175
171
|
|
|
176
|
-
async createIndex(
|
|
177
|
-
const params = this.normalizeArgs<CreateIndexParams>('createIndex', args);
|
|
178
|
-
|
|
179
|
-
const { indexName, dimension } = params;
|
|
172
|
+
async createIndex({ indexName, dimension }: CreateIndexParams): Promise<void> {
|
|
180
173
|
try {
|
|
181
174
|
// Validate inputs
|
|
182
175
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
@@ -212,10 +205,7 @@ export class LibSQLVector extends MastraVector {
|
|
|
212
205
|
}
|
|
213
206
|
}
|
|
214
207
|
|
|
215
|
-
async deleteIndex(
|
|
216
|
-
const params = this.normalizeArgs<DeleteIndexParams>('deleteIndex', args);
|
|
217
|
-
|
|
218
|
-
const { indexName } = params;
|
|
208
|
+
async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {
|
|
219
209
|
try {
|
|
220
210
|
const parsedIndexName = parseSqlIdentifier(indexName, 'index name');
|
|
221
211
|
// Drop the table
|
|
@@ -251,14 +241,10 @@ export class LibSQLVector extends MastraVector {
|
|
|
251
241
|
/**
|
|
252
242
|
* Retrieves statistics about a vector index.
|
|
253
243
|
*
|
|
254
|
-
* @param
|
|
255
|
-
* @param params.indexName - The name of the index to describe
|
|
244
|
+
* @param {string} indexName - The name of the index to describe
|
|
256
245
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
257
246
|
*/
|
|
258
|
-
async describeIndex(
|
|
259
|
-
const params = this.normalizeArgs<DescribeIndexParams>('describeIndex', args);
|
|
260
|
-
|
|
261
|
-
const { indexName } = params;
|
|
247
|
+
async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {
|
|
262
248
|
try {
|
|
263
249
|
const parsedIndexName = parseSqlIdentifier(indexName, 'index name');
|
|
264
250
|
// Get table info including column info
|
|
@@ -303,31 +289,6 @@ export class LibSQLVector extends MastraVector {
|
|
|
303
289
|
}
|
|
304
290
|
}
|
|
305
291
|
|
|
306
|
-
/**
|
|
307
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
308
|
-
*
|
|
309
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
310
|
-
* @param indexName - The name of the index containing the vector.
|
|
311
|
-
* @param id - The ID of the vector to update.
|
|
312
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
313
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
314
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
315
|
-
* @returns A promise that resolves when the update is complete.
|
|
316
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
317
|
-
*/
|
|
318
|
-
async updateIndexById(
|
|
319
|
-
indexName: string,
|
|
320
|
-
id: string,
|
|
321
|
-
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
322
|
-
): Promise<void> {
|
|
323
|
-
this.logger.warn(
|
|
324
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
325
|
-
Please use updateVector() instead.
|
|
326
|
-
updateIndexById() will be removed on May 20th, 2025.`,
|
|
327
|
-
);
|
|
328
|
-
await this.updateVector({ indexName, id, update });
|
|
329
|
-
}
|
|
330
|
-
|
|
331
292
|
/**
|
|
332
293
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
333
294
|
*
|
|
@@ -339,9 +300,7 @@ export class LibSQLVector extends MastraVector {
|
|
|
339
300
|
* @returns A promise that resolves when the update is complete.
|
|
340
301
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
341
302
|
*/
|
|
342
|
-
async updateVector(
|
|
343
|
-
const params = this.normalizeArgs<UpdateVectorParams>('updateVector', args);
|
|
344
|
-
const { indexName, id, update } = params;
|
|
303
|
+
async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {
|
|
345
304
|
try {
|
|
346
305
|
const parsedIndexName = parseSqlIdentifier(indexName, 'index name');
|
|
347
306
|
const updates = [];
|
|
@@ -379,34 +338,13 @@ export class LibSQLVector extends MastraVector {
|
|
|
379
338
|
}
|
|
380
339
|
|
|
381
340
|
/**
|
|
382
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
383
|
-
*
|
|
384
341
|
* Deletes a vector by its ID.
|
|
385
342
|
* @param indexName - The name of the index containing the vector.
|
|
386
343
|
* @param id - The ID of the vector to delete.
|
|
387
344
|
* @returns A promise that resolves when the deletion is complete.
|
|
388
345
|
* @throws Will throw an error if the deletion operation fails.
|
|
389
346
|
*/
|
|
390
|
-
async
|
|
391
|
-
this.logger.warn(
|
|
392
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
393
|
-
Please use deleteVector() instead.
|
|
394
|
-
deleteIndexById() will be removed on May 20th, 2025.`,
|
|
395
|
-
);
|
|
396
|
-
await this.deleteVector({ indexName, id });
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Deletes a vector by its ID.
|
|
401
|
-
* @param indexName - The name of the index containing the vector.
|
|
402
|
-
* @param id - The ID of the vector to delete.
|
|
403
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
404
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
405
|
-
*/
|
|
406
|
-
async deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void> {
|
|
407
|
-
const params = this.normalizeArgs<DeleteVectorParams>('deleteVector', args);
|
|
408
|
-
|
|
409
|
-
const { indexName, id } = params;
|
|
347
|
+
async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {
|
|
410
348
|
try {
|
|
411
349
|
const parsedIndexName = parseSqlIdentifier(indexName, 'index name');
|
|
412
350
|
await this.turso.execute({
|
|
@@ -418,9 +356,7 @@ export class LibSQLVector extends MastraVector {
|
|
|
418
356
|
}
|
|
419
357
|
}
|
|
420
358
|
|
|
421
|
-
async truncateIndex(
|
|
422
|
-
const params = this.normalizeArgs<DeleteIndexParams>('truncateIndex', args);
|
|
423
|
-
const { indexName } = params;
|
|
359
|
+
async truncateIndex({ indexName }: DeleteIndexParams): Promise<void> {
|
|
424
360
|
await this.turso.execute({
|
|
425
361
|
sql: `DELETE FROM ${parseSqlIdentifier(indexName, 'index name')}`,
|
|
426
362
|
args: [],
|