node:sqlite sample

This commit is contained in:
Alex Garcia 2025-01-24 13:30:14 -08:00
parent d1d1ed7a57
commit dbc5098114
4 changed files with 81 additions and 0 deletions

View file

@ -0,0 +1,12 @@
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