What you'll learn
- Why SQLite is the ideal sovereign brain database
- The key-value brain schema: categories, keys, values, and timestamps
- Building search and retrieval into your brain
- Boot sequences that give your AI instant context
Why SQLite for a Sovereign Brain
SQLite is the most deployed database in the world. It is a single file on your disk -- no server process, no network port, no configuration. Your entire brain lives in one file that you can copy, backup, and move between machines.
Zero dependencies. No database server to install, configure, or maintain. No Docker containers. No cloud services. The database is a file. Your application reads and writes it directly.
Zero latency. Reads from a local SQLite file take microseconds. No network round-trip. No connection pooling. Your AI's boot sequence that reads 50 keys completes in under 10 milliseconds.
Zero cost. No monthly bill. No storage fees. No bandwidth charges. A brain with 10,000 entries takes a few megabytes of disk space. You will never outgrow a single machine for brain storage.
Full portability. Copy the file to another machine and your brain moves with it. Backup to a USB drive. Sync between machines with rsync. No vendor lock-in. No export/import headaches.
The Brain Schema
A sovereign brain needs a simple, flexible schema that supports fast reads, hierarchical organization, and full-text search:
-- Create the brain table
CREATE TABLE IF NOT EXISTS brain (
key TEXT PRIMARY KEY, -- Hierarchical key: "identity.user"
value TEXT NOT NULL, -- The actual content (JSON or plain text)
category TEXT NOT NULL, -- Top-level grouping: identity, directive, system
tags TEXT DEFAULT '', -- Comma-separated tags for flexible querying
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Index for fast category lookups
CREATE INDEX IF NOT EXISTS idx_brain_category ON brain(category);
-- Full-text search index
CREATE VIRTUAL TABLE IF NOT EXISTS brain_fts USING fts5(
key, value, category, tags,
content='brain',
content_rowid='rowid'
);
-- Example entries
INSERT INTO brain (key, value, category) VALUES
('identity.user', 'Business owner, runs an AI consulting firm', 'identity'),
('identity.preferences', 'Concise responses, no jargon, action-oriented', 'identity'),
('directive.autonomy', 'L4: Act within guardrails, surface for spending and legal', 'directive'),
('directive.voice', 'Professional but warm, direct, no corporate speak', 'directive'),
('system.infrastructure', 'M3 Mac, Ollama, SQLite brain, Vercel for web', 'system'),
('session.active_work', 'Building email automation agent', 'session'),
('session.next_steps', '1. Test email sending 2. Add template system', 'session');Read and Write Operations
The brain API is deliberately simple -- read a key, write a key, search by text, list by category:
// brain.js -- Sovereign brain operations
import Database from 'better-sqlite3';
const db = new Database('./brain.db');
// Read a single key
function read(key) {
const row = db.prepare('SELECT value FROM brain WHERE key = ?').get(key);
return row ? row.value : null;
}
// Write or update a key
function write(key, value, category) {
db.prepare(`
INSERT INTO brain (key, value, category, updated_at)
VALUES (?, ?, ?, CURRENT_TIMESTAMP)
ON CONFLICT(key) DO UPDATE SET
value = excluded.value,
updated_at = CURRENT_TIMESTAMP
`).run(key, value, category);
}
// Search by text (full-text search)
function search(query) {
return db.prepare(`
SELECT key, value, category FROM brain_fts
WHERE brain_fts MATCH ?
ORDER BY rank LIMIT 10
`).all(query);
}
// List all keys in a category
function listCategory(category) {
return db.prepare(
'SELECT key, value FROM brain WHERE category = ?'
).all(category);
}
// Boot: read all critical context
function boot() {
const identity = listCategory('identity');
const directives = listCategory('directive');
const session = listCategory('session');
const system = listCategory('system');
return { identity, directives, session, system };
}Brain Categories
Organize your brain into clear categories so the AI can efficiently load what it needs:
identity.* -- Who you are, your preferences, your voice, your background. Read on every boot. Examples: identity.user, identity.preferences, identity.voice.
directive.* -- Rules the AI must follow. Non-negotiable. Read on every boot. Examples: directive.autonomy, directive.privacy, directive.spending_limit.
system.* -- Infrastructure and tool configuration. Read on boot when relevant. Examples: system.infrastructure, system.api_keys, system.active_services.
session.* -- Current work state. Read on boot to resume. Written at every checkpoint. Examples: session.active_work, session.next_steps, session.blockers.
project.* -- Ongoing project details. Read when working on that project. Examples: project.website_redesign, project.client_proposal, project.product_launch.
episode.* -- Historical records. Searched when context is needed. Examples: episode.2026-04-15_deploy, episode.client_meeting_notes.
The Boot Sequence
The boot sequence is the most important moment in every AI session. In under 50 milliseconds, your AI loads its full identity, rules, and current context from the local brain:
// Boot sequence -- runs at the start of every session
async function bootAgent() {
const brain = boot(); // Read all categories in parallel
// Build the system prompt from brain contents
const systemPrompt = `
You are an AI assistant for ${brain.identity[0].value}.
Your preferences: ${brain.identity[1].value}.
RULES:
${brain.directives.map(d => `- ${d.value}`).join('\n')}
CURRENT STATE:
Active work: ${brain.session.find(s => s.key === 'session.active_work')?.value}
Next steps: ${brain.session.find(s => s.key === 'session.next_steps')?.value}
INFRASTRUCTURE:
${brain.system.map(s => `${s.key}: ${s.value}`).join('\n')}
`;
return systemPrompt;
}
// The AI starts every session with full context
// No re-explaining. No lost history. Just continuity.This is the sovereign advantage. Cloud-based memory systems take 200-500ms for API calls. Your local brain takes 10ms. The AI has its full context before the user finishes typing their first message.
Brain Architecture Mistakes
No backup strategy. Your brain is a single file. If your hard drive fails, it is gone. Set up automated daily backups -- rsync to an external drive, copy to a second machine, or version with git. The brain is the most valuable file you own.
Writing but never reading. Carefully logging every decision to the brain but never building read operations into the agent loop. Memory that is written but never consulted is just a log file. Build reads into the boot sequence and decision-making process.
Giant value blobs. Storing an entire project plan as one massive value under a single key. When the AI reads it, the entire blob consumes context. Break it up: project.plan.goals, project.plan.timeline, project.plan.budget. Read only what is needed.
Try It Yourself
Build your sovereign brain:
1. Create a brain.db file using SQLite
sqlite3 brain.db < schema.sql
2. Populate it with your identity (3-5 keys):
- identity.user: who you are
- identity.preferences: how you want AI to respond
- directive.rules: what the AI must always do
- system.tools: what infrastructure you have
3. Write a boot function that reads all categories
4. Time it: how fast does your boot complete?
(Target: under 50ms for 50 keys)
5. Write a session checkpoint:
- session.active_work: what you are doing now
- session.next_steps: what comes next
You now have a sovereign brain. It runs forever,
costs nothing, and YOU own every byte.Key concepts.
Brain Architecture
Why SQLite for Sovereign Brain
Brain Schema
Brain Categories
The Boot Sequence
Sovereign Advantage: Speed
Backup Rule
Brain architecture quiz.
Brain Architecture
1Why is SQLite ideal for a sovereign brain?
2What is the purpose of brain categories like identity.* and directive.*?
3What is the most important anti-pattern to avoid with a sovereign brain?