#213 — Stop over-engineering AI agent memory
December 6, 2026·4 min read

Letting an AI agent run SQL and full-text search over its own raw event logs beats specialized memory startups on both accuracy and cost.
Why it matters
Founders building AI agents are burning engineering cycles and token budgets on complex memory pipelines: vector stores, temporal graphs, and background "dreaming" loops. Those systems try to guess what an agent will need later, compressing conversations at ingest time and permanently throwing away details that turn out to matter.
As models get smarter, simple search over raw logs scales automatically with model intelligence, while handcrafted memory architectures become technical debt.
By the numbers
- 85.7% at $4.73: What raw-log search scores on DolphinBench (600 tasks, GPT-5.6 Luna), beating Graphon (84.0% at $11.84) at less than half the cost and crushing Mem0 (70.7% at $96.21) at one-twentieth the cost.
- 8x to 10x cheaper: Raw-log search outperforms bare 500K-token in-context learning at every model tier on DolphinBench, hitting 93.8% ($36.38) with GPT-6.1 Sol versus 91.7% ($309.15) for raw context stuffing.
- +13.8 points: The accuracy jump on 10M-token BEAM histories when upgrading from GPT-6 Luna (53.2%) to GPT-6.1 Sol (67.0%), because stronger models write better SQL queries. It also leads LongMemEval V1 (94.6% on S, 92.2% on M) and hits 79.8% on LongMemEval V2.
- 2x the baseline: On Continual Learning Bench (40 stateful SQL episodes with a mid-run schema migration), raw logs roughly double stateless frontier performance, lifting Opus 5.5 from 0.422 to 0.768 and GPT-6.1 Terra from 0.282 to 0.727.
- -0.011 reward: The impact of adding sleep-time wiki consolidation ("dreaming") on Opus 5.5 in Continual Learning Bench. Reflection wikis act as a crutch for weaker models (+0.227 on Sonnet 5.5, +0.134 on Haiku 5.5, +0.118 on GPT-6 Luna), but frontier models reconstruct answers better directly from raw logs.
How it works
Traditional memory tools like Mem0, Supermemory, and Mastra run open-loop extraction: they distill every turn into atomic facts or summaries upfront, then inject top-k matches later. If a future task depends on an exact post-migration database column name (like choosing between prc, prc_usd, and prc_v2) or a passing remark from two years ago, that lossy compression fails and forces the agent to guess.
Agentic search flips the model by deferring compression until query time. Every turn is appended verbatim to an immutable SQLite event log with FTS5 indexing. When a task arrives, the agent runs closed-loop SQL queries and text searches until it finds the exact evidence it needs. Pre-computed memory only pays off when future queries are highly predictable or when you are locked into smaller models.
| Approach | Store | Loop type | Tradeoff for founders |
|---|---|---|---|
| Compaction | Context-limit summaries | Open-loop | Drops raw wording at window boundaries hatchery |
| Mem0 / Supermemory / Mastra | Fact vectors, graphs, summaries | Open-loop | Lossy ingest-time extraction misses unpredictable queries hatchery |
| Codex | Summaries + raw transcripts | Hybrid | Good index, still relies on idle summary generation hatchery |
| Letta / Claude | Git files or linked wiki | Closed-loop + idle dreaming | High flexibility, but dreaming adds overhead hatchery |
| Raw logs | Immutable SQLite + FTS5 | Pure closed-loop | Zero ingest cost, lossless, scales with model intelligence hatchery |
What to build
Searching raw logs from scratch on every turn can still add latency in user-facing products. Instead of building a lossy fact extractor, treat agent memory like a computer's memory hierarchy (CPU cache, RAM, disk) built over an immutable log:
- L0 (Hot Cache): Pin frequently accessed facts (like a user's timezone or location) directly in context for zero-hop access. Always link cached values back to the exact log sequence IDs that created them so you can invalidate them automatically on contradiction (the user moves cities) or after a set time period.
- L1 (Index): Maintain lightweight, high-scent pointers (like session summaries, table names, or FTS5 snippets) that guide the agent to the right spot in one hop and keep it from giving up search too early.
- L2 (Event Log): Keep the complete, lossless history in durable SQLite with FTS5 as the unlimited source of truth. For single-session agents, expose three read-only tools:
describe(schemas and sample records),search(FTS5 snippets), andquery(SQL). For multi-session agents, expose four:sessions_list(IDs, dates, turn counts),sessions_search(global FTS5),sessions_read(verbatim turn windows), andsessions_query(SQL oversessionsandturns).
The bottom line
Human brains compress memories because biological storage is scarce and raw sensory input disappears. Software agents do not have that constraint: disk space is practically free, so stop over-engineering how your agent remembers and start optimizing how fast it searches.
Frequently asked questions
Is SQLite FTS5 fast enough for AI agent memory in production at scale?
Yes, especially when you isolate memory per user or per tenant instead of stuffing everyone into one giant database. A single SQLite database with FTS5 and WAL mode easily handles millions of rows with sub-10ms full-text search. In production, teams using per-tenant SQLite architectures (like Turso or Cloudflare Durable Objects) get near-zero network latency and clean horizontal scaling without managing a centralized vector cluster.
How do you prevent SQL injection when giving an AI agent a SQL query tool?
Never give an agent write access or shared-table access. Open the SQLite connection in strict read-only mode (?mode=ro or PRAGMA query_only = ON), enforce a hard query timeout and row limit, and isolate each user into their own database file. Because the agent can only read a single tenant's immutable log, even a prompt injection cannot leak another customer's data or corrupt your application state.
When should I still use a vector database instead of SQLite FTS5 for agent memory?
Use vector search when your agent needs fuzzy conceptual matching across large, unstructured knowledge bases (like matching a vague support complaint to a help doc written with different terminology). Use SQLite FTS5 when exactness matters: user preferences, past tool calls, IDs, code snippets, dates, and database schemas. Many production teams run FTS5 for episodic agent logs and keep vectors strictly for static RAG documentation.
How do you keep latency low in user-facing AI apps if the agent searches logs at query time?
Do not force the agent to search on every turn. Pin high-frequency context (user profile, active workspace, timezone) in your L0 hot cache directly inside the system prompt so 80% of routine turns require zero tool calls. For example, coding agents like Codex load a lightweight summary index on startup and only trigger file reads or grep queries when the summary misses a specific detail.
Is it cheaper to run a smaller model with sleep-time dreaming or a frontier model with raw logs?
It depends on how predictable your user queries are. On benchmarks like Continual Learning Bench, adding sleep-time wiki consolidation boosts mid-tier models like Sonnet 5.5 by +0.227 reward, making them competitive on repetitive workflows. However, if your users ask unpredictable, high-stakes questions (like debugging a schema migration), a frontier model querying raw logs avoids silent hallucinations and usually costs less than maintaining a background reflection pipeline.
How do you handle GDPR deletion and PII compliance with immutable agent event logs?
Immutability applies to the agent's read path, not your compliance layer. The cleanest pattern is per-user SQLite files: when a customer requests deletion under GDPR or CCPA, you simply drop their file and purge backups on schedule. For sensitive fields like API keys or credit card numbers, run a lightweight redaction middleware before appending turns to the log so raw secrets never hit disk.
Can you build raw-log AI agent memory with PostgreSQL instead of SQLite?
Yes. If your stack already runs on Postgres or Supabase, you can replicate the exact same pattern using tsvector with GIN indexes or BM25 extensions like pg_search. The key requirement is not SQLite itself, but deferred compression: storing every turn verbatim and giving the agent a read-only SQL and full-text search interface scoped strictly to that user's tenant_id via Row Level Security.
How do you migrate from Mem0 or vector memory stores to raw event logs?
Start by dual-writing: keep your existing vector store running while appending every raw conversation turn and tool call into an immutable log table. Run your production traces through both retrieval paths in shadow mode to compare accuracy and token cost. Once raw-log search matches or beats your current store, turn off the background extraction pipeline and immediately reclaim those ingest-time LLM costs.
Why does context window compaction fail for long-running AI agents?
Compaction triggers when a conversation hits the context limit and asks an LLM to summarize older turns into a checkpoint. Because the model cannot predict which detail will matter 50 turns later, compaction acts as lossy compression that silently drops exact IDs, column names, or user constraints. Keeping an immutable log underneath lets you compact the active window for speed while still allowing the agent to query the exact verbatim history on demand.
How do you stop an AI agent from burning tokens on infinite search loops?
Cap the agent's search budget with a hard limit of 3 to 5 tool calls per turn, and never return full raw payloads from a search tool. Instead, return ranked FTS5 snippets with sequence IDs (your L1 index) so the agent only reads the exact 5 to 10 turns it needs. Strong information scent prevents the model from wandering across irrelevant sessions and keeps per-turn token spend predictable.
How do you share raw-log memory across multiple AI agents?
Tag every row in your immutable event log with session_id, agent_role, and timestamp columns. Instead of passing bloated summaries between a planner agent, a coding agent, and a QA agent, give all of them read-only access to the same shared event log. Each specialist agent can query the exact tool outputs and decisions made by previous agents without losing fidelity during handoffs.
How do you benchmark and evaluate AI agent memory for your own product?
Do not just measure retrieval precision; measure end-to-end task completion and total run cost across two distinct categories: recall (retrieving a verbatim fact from months ago) and transfer (applying a rule learned in an earlier session to a new problem). Pull 50 to 100 real production trajectories where your agent previously failed or forgot context, and grade your raw-log setup against your current memory stack on pass rate per dollar.
Keep reading

#212 — The great AI capital drain
There has never been more capital chasing so few names but this moment in time is stranger than it looks and founders must survive it.

#211 — Harvey and the future of fine-tuning for other vertical AI firms
Harvey has expanded into post-training open-source models (based on Kimi 3) and the results are mixed.

#210 — The AI credit crunch
If you build on rented compute or sell to AI startups, your costs and your customers' budgets both depend on a financing market that is tightening fast.