@storecraft/database-turso 1.0.10 → 1.0.12
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/README.md +10 -2
- package/package.json +3 -2
- package/vector-store/index.js +15 -12
package/README.md
CHANGED
@@ -5,7 +5,8 @@
|
|
5
5
|
width='90%' />
|
6
6
|
</div><hr/><br/>
|
7
7
|
|
8
|
-
Official `
|
8
|
+
Official `libSql` / `Turso` driver for `StoreCraft` on any platforms.
|
9
|
+
Includes a vector store.
|
9
10
|
|
10
11
|
```bash
|
11
12
|
npm i @storecraft/database-turso
|
@@ -29,7 +30,7 @@ import http from "node:http";
|
|
29
30
|
import { App } from '@storecraft/core'
|
30
31
|
import { NodePlatform } from '@storecraft/core/platform/node';
|
31
32
|
import { NodeLocalStorage } from '@storecraft/core/storage/node'
|
32
|
-
import { Turso } from '@storecraft/database-turso'
|
33
|
+
import { Turso, LibSQLVectorStore } from '@storecraft/database-turso'
|
33
34
|
import { migrateToLatest } from '@storecraft/database-turso/migrate.js'
|
34
35
|
|
35
36
|
const app = new App(
|
@@ -53,6 +54,13 @@ const app = new App(
|
|
53
54
|
)
|
54
55
|
)
|
55
56
|
.withStorage(new NodeLocalStorage('storage'))
|
57
|
+
.withVectorStore(
|
58
|
+
new LibSQLVectorStore(
|
59
|
+
{
|
60
|
+
embedder: new OpenAIEmbedder()
|
61
|
+
}
|
62
|
+
)
|
63
|
+
)
|
56
64
|
|
57
65
|
await app.init();
|
58
66
|
await migrateToLatest(app.db, false);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storecraft/database-turso",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.12",
|
4
4
|
"description": "`Storecraft` database driver for `Turso` (cloud sqlite)",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": "Tomer Shalev (https://github.com/store-craft)",
|
@@ -35,7 +35,8 @@
|
|
35
35
|
"scripts": {
|
36
36
|
"database-turso:test": "node ./tests/runner.test.js",
|
37
37
|
"test": "npm run database-turso:test",
|
38
|
-
"prepublishOnly": "npm version patch --force"
|
38
|
+
"prepublishOnly": "npm version patch --force",
|
39
|
+
"sc-publish": "npm publish --access public"
|
39
40
|
},
|
40
41
|
"peerDependencies": {
|
41
42
|
"kysely": "*"
|
package/vector-store/index.js
CHANGED
@@ -92,12 +92,11 @@ export class LibSQLVectorStore {
|
|
92
92
|
|
93
93
|
/** @type {VectorStore["onInit"]} */
|
94
94
|
onInit = (app) => {
|
95
|
-
this.config.authToken ??= app.platform.env[
|
96
|
-
|
97
|
-
|
98
|
-
this.config.url ??= app.platform.env[
|
99
|
-
|
100
|
-
];
|
95
|
+
this.config.authToken ??= app.platform.env[LibSQLVectorStore.EnvConfig.authToken]
|
96
|
+
?? app.platform.env['LIBSQL_AUTH_TOKEN'];
|
97
|
+
|
98
|
+
this.config.url ??= app.platform.env[LibSQLVectorStore.EnvConfig.url]
|
99
|
+
?? app.platform.env['LIBSQL_URL'];
|
101
100
|
}
|
102
101
|
|
103
102
|
/** @type {VectorStore["embedder"]} */
|
@@ -191,10 +190,11 @@ export class LibSQLVectorStore {
|
|
191
190
|
);
|
192
191
|
}
|
193
192
|
|
193
|
+
aa;
|
194
194
|
/** @type {VectorStore["similaritySearch"]} */
|
195
195
|
similaritySearch = async (query, k, namespaces) => {
|
196
|
-
|
197
|
-
const embedding_result = await this.embedder.generateEmbeddings(
|
196
|
+
console.log({query,k,namespaces})
|
197
|
+
const embedding_result = this.aa = this.aa ? this.aa : await this.embedder.generateEmbeddings(
|
198
198
|
{
|
199
199
|
content: [
|
200
200
|
{
|
@@ -218,10 +218,12 @@ export class LibSQLVectorStore {
|
|
218
218
|
/** @type {InArgs} */
|
219
219
|
let args = [];
|
220
220
|
let sql = `
|
221
|
-
SELECT id, metadata, pageContent, updated_at, namespace, ${distance_fn}(embedding, vector(?)) AS score
|
222
|
-
FROM vector_top_k('${index_name}', vector(?), ?) as top_k_view
|
223
|
-
JOIN ${table} ON ${table}.rowid = top_k_view.
|
221
|
+
SELECT ${table}.id, metadata, pageContent, updated_at, namespace, ${distance_fn}(embedding, vector(?)) AS score
|
222
|
+
FROM vector_top_k('${index_name}', vector(?), CAST(? AS INTEGER)) as top_k_view
|
223
|
+
JOIN ${table} ON ${table}.rowid = top_k_view.rowid
|
224
224
|
`;
|
225
|
+
|
226
|
+
// console.log(typeof k)
|
225
227
|
args.push(vector_sql_value, vector_sql_value, k);
|
226
228
|
|
227
229
|
if(Array.isArray(namespaces) && namespaces.length) {
|
@@ -236,9 +238,10 @@ export class LibSQLVectorStore {
|
|
236
238
|
`
|
237
239
|
args.push(vector_sql_value);
|
238
240
|
|
239
|
-
|
240
241
|
const result = await this.client.execute({ sql, args });
|
241
242
|
|
243
|
+
// console.log({result})
|
244
|
+
|
242
245
|
return result.rows.map(
|
243
246
|
(row) => (
|
244
247
|
{
|