Skip to content
On this page

sqlite-vss with Node.js

npm

Node.js developers can use sqlite-vss with the sqlite-vss NPM package. It can be installed with:

bash
npm install sqlite-vss

Once installed, the sqlite-vss package can be used with SQLite clients like better-sqlite3 and node-sqlite3.

js
import Database from "better-sqlite3";
import * as sqlite_vss from "sqlite-vss";

const db = new Database(":memory:");
sqlite_vss.load(db);

const version = db.prepare("select vss_version()").pluck().get();
console.log(version);

Checkout the API Reference for all available SQL functions.

Also see Making SQLite extensions npm install-able (March 2023) for more information on how npm install'able SQLite extensions work.

Working with Vectors in Node.js

Vectors as JSON

If your vectors in Node.js are represented as an array of floats, you can insert them into a vss0 table as a JSON string with JSON.stringify().

js
const embedding = [0.1, 0.2, 0.3];
const stmt = db.prepare("INSERT INTO vss_demo VALUES (?)");
stmt.run(JSON.stringify(embedding));

Vectors as Bytes

Alternatively, if your vectors in Node.js are represented as a Float32Array, use the .buffer accessor to insert the underlying ArrayBuffer.

js
const embedding = new Float32Array([0.1, 0.2, 0.3]);
const stmt = db.prepare("INSERT INTO vss_demo VALUES (?)");
stmt.run(embedding.buffer);

MIT License