Skip to content

SQLite integration#6

Open
anhldbk wants to merge 11 commits intogarrytan:masterfrom
anhldbk:master
Open

SQLite integration#6
anhldbk wants to merge 11 commits intogarrytan:masterfrom
anhldbk:master

Conversation

@anhldbk
Copy link
Copy Markdown

@anhldbk anhldbk commented Apr 8, 2026

Overview

GBrain is a personal knowledge brain backed by Postgres + pgvector. This work adds SQLite as a zero-infrastructure alternative engine using bun:sqlite (built-in, no dependencies), FTS5 for full-text search, and vec0 for optional vector similarity — all behind the same BrainEngine interface so every command works identically regardless of backend.

What was built:

  • SQLiteEngine — full implementation of all 30 BrainEngine methods: pages, chunks, links, tags, timeline, raw data, versions, files, ingest log, config, stats, health, and graph traversal
  • SQLite schema — DDL with FTS5 virtual table and three sync triggers (insert/update/delete) to keep full-text search current automatically; WAL mode enabled at connect time
  • vec0 integration — loads the native extension at connect, creates a parallel chunks_vec vector table when available, degrades gracefully to keyword-only when not
  • gbrain init --sqlite — initializes a local brain at ~/.gbrain/brain.db (or a custom path)
  • Engine selection — CLI reads config.engine and routes to SQLite or Postgres transparently
  • Shared utilities — extracted validateSlug and contentHash from Postgres engine into src/core/utils.ts, fixing a slug validation regex bug along the way
  • File commands fix — gbrain files list/upload/sync/verify previously bypassed the engine entirely via a direct DB connection; refactored to use BrainEngine file methods that work with both backends
  • Hybrid search fix — hybridSearch unconditionally called embed() before keyword search; without an OpenAI API key this threw and skipped results entirely; now degrades gracefully to keyword-only
  • Docker fallback — Dockerfile.sqlite for environments where the vec0 native extension needs to be pre-installed
  • 39 new tests across utils.test.ts, sqlite-engine.test.ts, and fts5-query.test.ts

Disclaimer

I've built with Claude Opus

anhldbk and others added 11 commits April 8, 2026 06:55
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements the complete BrainEngine interface using bun:sqlite (no npm
deps). Includes FTS5 keyword search, optional vec0 vector search,
pages CRUD with upsert/slug validation, tags, links, graph traversal,
timeline, versions, raw data, ingest log, config, and stats/health.
All 12 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tion

files.ts was calling db.getConnection() directly, bypassing the engine
abstraction. This broke all files subcommands when using SQLiteEngine.

Added getFiles/upsertFile/findFileByHash to BrainEngine interface and
implemented in both PostgresEngine and SQLiteEngine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant