-
Notifications
You must be signed in to change notification settings - Fork 546
Open
Description
Problem
When running qmd under Bun on macOS, vector embedding fails at startup with:
sqlite-vec is not available. Vector operations require a SQLite build with extension loading support.
at ensureVecTableInternal (store.js:608)
Root cause: Bun on macOS uses Apple's system SQLite for performance, but Apple's build sets SQLITE_OMIT_LOAD_EXTENSION, which disables sqlite3_load_extension(). The sqlite-vec npm packages are installed and the native vec0.dylib is present, but db.loadExtension() is rejected by the runtime.
Environment
- qmd 1.0.7
- Bun 1.3.9
- macOS arm64 (Darwin 23.1.0)
- sqlite-vec 0.1.7 + sqlite-vec-darwin-arm64 (vec0.dylib present)
- Homebrew SQLite installed at
/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib
Fix
Bun exposes Database.setCustomSQLite(path) to swap out Apple's restricted SQLite for a vanilla build that supports extension loading. The Bun branch in db.ts needs to call this before creating any Database instances.
Workaround patch applied to dist/db.js:
if (isBun) {
const bunSqlite = "bun:" + "sqlite";
_Database = (await import(bunSqlite)).Database;
// macOS: Apple's SQLite has SQLITE_OMIT_LOAD_EXTENSION; swap in Homebrew's vanilla build
if (process.platform === "darwin") {
const brewPrefix = process.env.BREW_PREFIX || (process.arch === "arm64" ? "/opt/homebrew" : "/usr/local");
const customPath = `${brewPrefix}/opt/sqlite/lib/libsqlite3.dylib`;
try {
_Database.setCustomSQLite(customPath);
} catch (e) {
console.warn(`[qmd] failed to load Homebrew SQLite from ${customPath}: ${e.message}`);
}
}
const { getLoadablePath } = await import("sqlite-vec");
_sqliteVecLoad = (db) => db.loadExtension(getLoadablePath());
}After applying this patch, qmd embed completes successfully and vector search works.
References
- Bun SQLite docs:
Database.setCustomSQLite() - sqlite-vec Bun usage guide
- The error message in
store.tsline ~474 already hints at Homebrew SQLite but the code path indb.tsnever uses it
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels