DEV Community

Cover image for I built an AI memory that fact-checks itself while you sleep
Fex Beck
Fex Beck

Posted on

I built an AI memory that fact-checks itself while you sleep

The Problem

AI agents forget everything between sessions. Claude Code uses MEMORY.md files — a 200-line limit, no search, no validation. After months of manually maintaining memory files, I built something better.

What is BrainDB?

BrainDB is a local-first AI memory system built on SQLite. No cloud, no vector database, no subscriptions. One SQLite file, 110 REST endpoints, 51 MCP tools.

Why SQLite instead of Pinecone/Weaviate?

SQLite with FTS5 gives you sub-millisecond full-text search with BM25 ranking. Combined with embedding vectors (stored as BLOBs), you get hybrid search — keyword precision + semantic understanding. For <100k memories, this beats any managed vector DB in latency and simplicity.

The killer features nobody else has

1. Inception — Nightly fact-checking

Every night, BrainDB picks high-importance memories, generates search queries, searches the web via SearXNG, and fact-checks them with an LLM. Last run found 26 outdated facts automatically.

[inception] Processing: "PostgreSQL default port is 5433"
[inception] Web search: 3 results confirm port 5432
[inception] Result: CONTRADICTION — stored fact is wrong
Enter fullscreen mode Exit fullscreen mode

2. autoDream — Knowledge consolidation

While you sleep, BrainDB merges duplicate memories, archives stale ones, and adjusts importance scores. Like defragmenting your AI's brain.

3. Multi-agent coordination

Multiple AI agents can share the same memory with pessimistic locking (claims), context handovers, heartbeat monitoring, and a signal protocol. No conflicts, no data races.

Architecture

MCP Client (Claude/Cursor) → MCP Server → REST API → SQLite+FTS5
                                              ↓
                                    Ollama (local embeddings)
Enter fullscreen mode Exit fullscreen mode

7 route modules: Memory, Search, Agents, Graph, Orchestrator, System, Inception.

Relevance Scoring

Custom SQLite function with type-aware ranking:

  • Decisions get +0.3 boost (authoritative)
  • Issues get -0.1 (often resolved)
  • Superseded memories return 0 (replaced by newer version)
  • Exponential time decay with type-specific half-lives

Quick Start

git clone https://github.com/beckfexx/BrainDB.git
cd BrainDB && cp .env.example .env
bun install && bun run start
# → http://localhost:3197/health
Enter fullscreen mode Exit fullscreen mode

Or with Docker:

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

Numbers

  • 4,300+ memories in production
  • 110 REST endpoints across 7 domain modules
  • 51 MCP tools for Claude Code / Cursor
  • 0 TypeScript errors
  • AGPL-3.0 — free for self-hosting

Compared to alternatives

Feature BrainDB MemPalace LangChain Memory
Hybrid search (FTS5+embeddings)
Self-learning (Inception)
Multi-agent coordination ⚠️ Basic
Local-first (no cloud)
Knowledge graph
Production-tested ✅ 4.3k memories Demo only Framework

GitHub: beckfexx/BrainDB

Feedback welcome. This is a solo project — every star, issue, or PR helps.

Top comments (0)