feat(store): support Bun runtime via bun:sqlite (vec0 + FTS5)#436
feat(store): support Bun runtime via bun:sqlite (vec0 + FTS5)#436Guihal wants to merge 2 commits into
Conversation
VectorStore and the read-local-memory diagnostic CLI hard-wired node:sqlite, which is unavailable in Bun — the gateway booted in degraded mode (no vector store, no FTS5). Detect the runtime and open the database via bun:sqlite when running under Bun. Bun's Database.loadExtension() loads sqlite-vec directly, so the Node-only enableLoadExtension(true) step is skipped under Bun. Verified: bun src/gateway/server.ts boots with vectorStore=true and FTS5 tables initialized; node path unchanged.
|
Review note after local verification: this currently fails build, so I cannot approve it yet. What passed:
What failed:
The immediate cause appears to be the new Please fix the constructor typing / Bun adapter shape so |
|
Thanks for your attention! We will review this as soon as possible. Meanwhile, we suggest you link the corresponding issue related to this matter. |
The earlier Bun shim narrowed requireNodeSqlite()'s return type to a 1-arg
constructor, breaking openSqliteReadonly()'s `new DbSync(dbPath, { open: false })`
(TS2554). Revert requireNodeSqlite to node-only and make openSqliteReadonly
runtime-aware instead: under Bun open natively with { readonly: true } (bun has
no lazy-open/.open()), under Node keep the {open:false} + .open() + query_only
pragma path. Fixes `pnpm build` (build:read-local-memory tsc) while keeping the
Bun path correct at runtime.
|
Thanks for the review! 🙏 Fixed in Reverted
|
|
As an aside for this Bun-support PR — memory footprint of the standalone gateway under each runtime (idle baseline, identical code path, fresh empty
Bun settles at ~2.5× lower resident memory than node on the same gateway (native extensions loaded in both: sqlite-vec, Methodology: each instance booted against a fresh empty data dir; Not a correctness claim, just context on why running this as a long-lived daemon under Bun is appealing. |
|
Thanks! No existing issue covered this, so I opened #454 and linked it here ( |
Closes #454
Summary
The standalone
TdaiGateway(and theread-local-memorydiagnostic CLI) hard-wired Node'snode:sqlite. Bun does not implementnode:sqlite, so running the gateway under Bun (bun src/gateway/server.ts) booted in degraded mode: the vector store never initialised (No such built-in module: node:sqlite), disabling vector/FTS recall and dedup.This adds runtime detection: under Bun the SQLite handle is opened via the built-in
bun:sqlite; under Node behaviour is unchanged (node:sqlite).bun:sqlite'sDatabase.loadExtension()loadssqlite-vecdirectly, so the Node-onlyenableLoadExtension(true)step is skipped under Bun.Why
Bun is a common runtime for this kind of sidecar (and pi, which embeds TDAI via the gateway, runs on Bun). Making the gateway runtime-agnostic lets it run under either without code changes.
Changes
src/core/store/sqlite.ts—openSqliteHandle(path)picksbun:sqlite(globalThis.Bun) ornode:sqlite;enableLoadExtension(true)guarded (Node-only). Sameexec/prepare/run/all/get/close+Bufferblob surface — no query changes.scripts/read-local-memory/read-local-memory.ts— same runtime detection for the diagnostic CLI.Verification
bun src/gateway/server.ts→GET /health→{"status":"ok","stores":{"vectorStore":true,"embeddingService":false}}; boot log showsFTS5 tables initialized (l1_fts, l0_fts).bm25()confirmed working underbun:sqlitevia direct probe (extension loaded withvec0.so, cosine MATCH query returns correct rows).node --import tsx src/gateway/server.tsstillstatus:ok,vectorStore:true.Notes
embedding.providerstill defaults to"none"(BM25 keyword recall). Semantic vector recall still requires a remote/embedding provider as before — orthogonal to this change.