@@ -50,7 +50,7 @@ The `load()` function is compatible with
50
50
51
51
if your vectors are represented as an array of numbers, wrap it in a
52
52
[ ` Float32Array ` ] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array ) ,
53
- and use
53
+ and use the
54
54
[ ` .buffer ` ] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/buffer )
55
55
accessor to bind as a parameter to ` sqlite-vec ` SQL functions.
56
56
@@ -62,8 +62,32 @@ console.log(stmt.run(embedding.buffer)); // 4
62
62
63
63
## Node.js
64
64
65
- Here's a quick recipe of using ` sqlite-vec ` with
66
- [ ` better-sqlite3 ` ] ( https://github.com/WiseLibs/better-sqlite3 ) in Node.js.
65
+ If you're on Node.js ` 23.5.0 ` or above, you can use [ the builtin ` node:sqlite ` module] ( https://nodejs.org/api/sqlite.html ) with ` sqlite-vec ` like so:
66
+
67
+ ``` js
68
+ import { DatabaseSync } from " node:sqlite" ;
69
+ import * as sqliteVec from " sqlite-vec" ;
70
+
71
+ const db = new DatabaseSync (" :memory:" , { allowExtension: true });
72
+ sqliteVec .load (db);
73
+
74
+ const embedding = new Float32Array ([0.1 , 0.2 , 0.3 , 0.4 ]);
75
+ const { result } = db
76
+ .prepare (" select vec_length(?) as result" )
77
+ .get (new Uint8Array (embedding .buffer ));
78
+
79
+ console .log (result); // 4
80
+ ```
81
+
82
+
83
+ See
84
+ [ ` simple-node2/demo.mjs ` ] ( https://github.com/asg017/sqlite-vec/blob/main/examples/simple-node2/demo.mjs )
85
+ for a complete ` node:sqlite ` + ` sqlite-vec ` demo.
86
+
87
+
88
+ Alternatively, you can use the
89
+ [ ` better-sqlite3 ` ] ( https://github.com/WiseLibs/better-sqlite3 )
90
+ NPM package with ` sqlite-vec ` in Node as well.
67
91
68
92
``` js
69
93
import * as sqliteVec from " sqlite-vec" ;
@@ -83,21 +107,19 @@ console.log(result); // 4
83
107
84
108
See
85
109
[ ` simple-node/demo.mjs ` ] ( https://github.com/asg017/sqlite-vec/blob/main/examples/simple-node/demo.mjs )
86
- for a more complete Node.js demo.
110
+ for a more complete demo.
87
111
88
112
## Deno
89
113
90
114
Here's a quick recipe of using ` sqlite-vec ` with
91
115
[ ` jsr:@db/sqlite ` ] ( https://jsr.io/@db/sqlite ) in Deno. It will only work on Deno
92
116
version ` 1.44 ` or greater, because of a bug in previous Deno versions.
93
117
94
- Keep in mind, the ` better-sqlite3 ` example above also works in Deno, you just
95
- need to prefix the ` better-sqlite3 ` import with ` npm: ` , like
96
- ` import * from "npm:better-sqlite3" ` .
118
+
97
119
98
120
``` ts
99
- import { Database } from " jsr:@db/sqlite@0.11 " ;
100
- import * as sqliteVec from " npm:sqlite-vec@0.0.1-alpha.9 " ;
121
+ import { Database } from " jsr:@db/sqlite" ;
122
+ import * as sqliteVec from " npm:sqlite-vec" ;
101
123
102
124
const db = new Database (" :memory:" );
103
125
db .enableLoadExtension = true ;
@@ -115,11 +137,17 @@ See
115
137
[ ` simple-deno/demo.ts ` ] ( https://github.com/asg017/sqlite-vec/blob/main/examples/simple-deno/demo.ts )
116
138
for a more complete Deno demo.
117
139
140
+ The ` better-sqlite3 ` example above also works in Deno, when the ` better-sqlite3 ` import is prefixed with ` npm: ` :
141
+
142
+ ``` js
143
+ import * from " better-sqlite3" ; // [!code --]
144
+ import * from " npm:better-sqlite3" ; // [!code ++]
145
+ ```
146
+
118
147
## Bun
119
148
120
149
Here's a quick recipe of using ` sqlite-vec ` with
121
- [ ` bun:sqlite ` ] ( https://bun.sh/docs/api/sqlite ) in Bun. The ` better-sqlite3 `
122
- example above also works with Bun.
150
+ [ ` bun:sqlite ` ] ( https://bun.sh/docs/api/sqlite ) in Bun.
123
151
124
152
``` ts
125
153
import { Database } from " bun:sqlite" ;
@@ -143,3 +171,6 @@ console.log(result); // 4
143
171
See
144
172
[ ` simple-bun/demo.ts ` ] ( https://github.com/asg017/sqlite-vec/blob/main/examples/simple-bun/demo.ts )
145
173
for a more complete Bun demo.
174
+
175
+ The ` better-sqlite3 `
176
+ example above also works with Bun.
0 commit comments