diff --git a/site/using/js.md b/site/using/js.md index ca05f52..12e8074 100644 --- a/site/using/js.md +++ b/site/using/js.md @@ -50,7 +50,7 @@ The `load()` function is compatible with if your vectors are represented as an array of numbers, wrap it in a [`Float32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array), -and use +and use the [`.buffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/buffer) accessor to bind as a parameter to `sqlite-vec` SQL functions. @@ -62,8 +62,32 @@ console.log(stmt.run(embedding.buffer)); // 4 ## Node.js -Here's a quick recipe of using `sqlite-vec` with -[`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3) in Node.js. +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: + +```js +import { DatabaseSync } from "node:sqlite"; +import * as sqliteVec from "sqlite-vec"; + +const db = new DatabaseSync(":memory:", { allowExtension: true }); +sqliteVec.load(db); + +const embedding = new Float32Array([0.1, 0.2, 0.3, 0.4]); +const { result } = db + .prepare("select vec_length(?) as result") + .get(new Uint8Array(embedding.buffer)); + +console.log(result); // 4 +``` + + +See +[`simple-node2/demo.mjs`](https://github.com/asg017/sqlite-vec/blob/main/examples/simple-node2/demo.mjs) +for a complete `node:sqlite` + `sqlite-vec` demo. + + +Alternatively, you can use the +[`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3) +NPM package with `sqlite-vec` in Node as well. ```js import * as sqliteVec from "sqlite-vec"; @@ -83,7 +107,7 @@ console.log(result); // 4 See [`simple-node/demo.mjs`](https://github.com/asg017/sqlite-vec/blob/main/examples/simple-node/demo.mjs) -for a more complete Node.js demo. +for a more complete demo. ## Deno @@ -91,13 +115,11 @@ Here's a quick recipe of using `sqlite-vec` with [`jsr:@db/sqlite`](https://jsr.io/@db/sqlite) in Deno. It will only work on Deno version `1.44` or greater, because of a bug in previous Deno versions. -Keep in mind, the `better-sqlite3` example above also works in Deno, you just -need to prefix the `better-sqlite3` import with `npm:`, like -`import * from "npm:better-sqlite3"`. + ```ts -import { Database } from "jsr:@db/sqlite@0.11"; -import * as sqliteVec from "npm:sqlite-vec@0.0.1-alpha.9"; +import { Database } from "jsr:@db/sqlite"; +import * as sqliteVec from "npm:sqlite-vec"; const db = new Database(":memory:"); db.enableLoadExtension = true; @@ -115,11 +137,17 @@ See [`simple-deno/demo.ts`](https://github.com/asg017/sqlite-vec/blob/main/examples/simple-deno/demo.ts) for a more complete Deno demo. +The `better-sqlite3` example above also works in Deno, when the `better-sqlite3` import is prefixed with `npm:`: + +```js +import * from "better-sqlite3"; // [!code --] +import * from "npm:better-sqlite3"; // [!code ++] +``` + ## Bun Here's a quick recipe of using `sqlite-vec` with -[`bun:sqlite`](https://bun.sh/docs/api/sqlite) in Bun. The `better-sqlite3` -example above also works with Bun. +[`bun:sqlite`](https://bun.sh/docs/api/sqlite) in Bun. ```ts import { Database } from "bun:sqlite"; @@ -143,3 +171,6 @@ console.log(result); // 4 See [`simple-bun/demo.ts`](https://github.com/asg017/sqlite-vec/blob/main/examples/simple-bun/demo.ts) for a more complete Bun demo. + +The `better-sqlite3` +example above also works with Bun. \ No newline at end of file diff --git a/site/using/python.md b/site/using/python.md index 7de1aba..177a507 100644 --- a/site/using/python.md +++ b/site/using/python.md @@ -40,7 +40,7 @@ for a more complete Python demo. If your vectors in Python are provided as a list of floats, you can convert them into the compact BLOB format that `sqlite-vec` uses with -`serialize_float32()`. This will internally call [`struct.pack()`](https://docs.python.org/3/library/struct.html#struct.pack). +`serialize_float32()`. This internally calls [`struct.pack()`](https://docs.python.org/3/library/struct.html#struct.pack). ```python from sqlite_vec import serialize_float32