Skip to content

Commit a2dd24f

Browse files
committed
docs
1 parent dbc5098 commit a2dd24f

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

site/using/js.md

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The `load()` function is compatible with
5050

5151
if your vectors are represented as an array of numbers, wrap it in a
5252
[`Float32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array),
53-
and use
53+
and use the
5454
[`.buffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/buffer)
5555
accessor to bind as a parameter to `sqlite-vec` SQL functions.
5656

@@ -62,8 +62,32 @@ console.log(stmt.run(embedding.buffer)); // 4
6262

6363
## Node.js
6464

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.
6791

6892
```js
6993
import * as sqliteVec from "sqlite-vec";
@@ -83,21 +107,19 @@ console.log(result); // 4
83107

84108
See
85109
[`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.
87111

88112
## Deno
89113

90114
Here's a quick recipe of using `sqlite-vec` with
91115
[`jsr:@db/sqlite`](https://jsr.io/@db/sqlite) in Deno. It will only work on Deno
92116
version `1.44` or greater, because of a bug in previous Deno versions.
93117

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+
97119

98120
```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";
101123

102124
const db = new Database(":memory:");
103125
db.enableLoadExtension = true;
@@ -115,11 +137,17 @@ See
115137
[`simple-deno/demo.ts`](https://github.com/asg017/sqlite-vec/blob/main/examples/simple-deno/demo.ts)
116138
for a more complete Deno demo.
117139

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+
118147
## Bun
119148

120149
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.
123151

124152
```ts
125153
import { Database } from "bun:sqlite";
@@ -143,3 +171,6 @@ console.log(result); // 4
143171
See
144172
[`simple-bun/demo.ts`](https://github.com/asg017/sqlite-vec/blob/main/examples/simple-bun/demo.ts)
145173
for a more complete Bun demo.
174+
175+
The `better-sqlite3`
176+
example above also works with Bun.

site/using/python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ for a more complete Python demo.
4040

4141
If your vectors in Python are provided as a list of floats, you can
4242
convert them into the compact BLOB format that `sqlite-vec` uses with
43-
`serialize_float32()`. This will internally call [`struct.pack()`](https://docs.python.org/3/library/struct.html#struct.pack).
43+
`serialize_float32()`. This internally calls [`struct.pack()`](https://docs.python.org/3/library/struct.html#struct.pack).
4444

4545
```python
4646
from sqlite_vec import serialize_float32

0 commit comments

Comments
 (0)