mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-04-26 01:06:27 +02:00
1.5 KiB
1.5 KiB
Using sqlite-vec in Node.js, Deno, and Bun
To use sqlite-vec in Node.js, Deno or Bun, install the
sqlite-vec NPM package using your
favorite package manager:
::: code-group
npm install sqlite-vec
bun install sqlite-vec
deno add npm:sqlite-vec
:::
Once installed, use the sqliteVec.load() function to load sqlite-vec SQL
functions into a SQLite connection.
import * as sqliteVec from "sqlite-vec";
import Database from "better-sqlite3";
const db = new Database(":memory:");
sqliteVec.load(db);
const { vec_version } = db
.prepare("select vec_version() as vec_version;")
.get();
console.log(`vec_version=${vec_version}`);
The load() function is compatable with
better-sqlite3,
node-sqlite3,
js:@db/sqlite (Deno), and
bun:sqlite.
Working with vectors in JavaScript
if your vectors are represented as an array of numbers, use
Float32Array,
use the
.buffer
accessor to insert the underlying ArrayBuffer.
const embedding = new Float32Array([0.1, 0.2, 0.3]);
const stmt = db.prepare("INSERT INTO vss_demo VALUES (?)");
stmt.run(embedding.buffer);
## Node.js
## Deno
## Bun