memgarden

Architecture and the case for the rebuild

Split out of the README on 2026-08-27 to keep the front page to overview, headline numbers and usage. Nothing here is abridged.

Architecture

Claude Code hooks (Rust subcommands, measured 0.85ms per turn — budget 10ms)
        │ raw transcript / query
        ▼
memgardend (axum, :9100) ──────────── web UI (dashboard + graph viewer, Phase E)
 ├─ retain: caps → <private> stripped → chunk → Ollama extraction → facts + links
 ├─ recall: FTS5 BM25 + sqlite-vec KNN → RRF fusion → token budget
 │          (retracted / expired facts dropped once, in `hydrate`)
 ├─ consolidate / reflect / reranker (off by default — see below)
 ├─ in-binary embeddings (fastembed, bge-small 384-dim, CPU)
 └─ metrics: lock-free atomics (74ns/op) + benefit ledger
        ▼
 single SQLite file (WAL, STRICT) — vec0 vectors + FTS5 + graph tables
Decision Choice Why
Storage SQLite + sqlite-vec (=0.1.9) + FTS5, external processes: zero No restart races, one-file backup, and brute-force KNN keeps whole-recall p95 under 10ms at 3k nodes
Extraction LLM Ollama HTTP (default qwen3-14b-nothink), swappable GPU belongs to the big model; the daemon never competes for it
Embeddings / rerank In-binary, CPU-forced Measured 2.4ms embed p50 / 10.4ms per rerank call on CPU; VRAM contention was the #1 legacy latency bug
Korean search FTS5 unicode61 + prefix='2 3 4' + *-suffixed query terms CJK has no word boundaries; guard-tested so recall can’t silently degrade
Concurrency One Ollama permit, background/interactive acquire split, hard deadlines A 14B model on one GPU must be queued for, never raced for
Metrics Static atomics, no LLM calls, /metrics.json + benefit_ledger table Zero added latency on hot paths is an acceptance gate, not a hope
Fact lifecycle superseded_by / expires_at as columns, filtered once in search::hydrate Every reader has to know whether a fact is live, so the answer travels with the row recall already selects. As a graph edge it would be a join on the hot path, and any caller that forgot the join would serve retracted facts. Automatic detection was built and measured off — docs/evidence/supersession-detection.md
Migration Legacy’s own transfer archive, frozen to disk, re-embedded and re-linked here Legacy exports facts without vectors, ids or derived links by design — carrying them and re-deriving is the supported path, not a compromise. The frozen archive is what makes the AC-3 evidence outlive the daemon it came from

What makes it different

Why rebuild

The legacy stack (hindsight daemon + embedded Postgres + Python hooks) works, but every operational lesson it taught pointed the same direction: