Memory for an AI Agent: From Overengineering to 300 Lines of Code
Developer Nikolay Gusev described how he found the best solution for AI agent memory. Instead of the convoluted MemPalace, which produced 58k duplicates, he built a simple system of 300 lines of code and markdown files. For scaling, he suggests ClickHouse with vector search and partitioning.
AI-processed from Habr AI; edited by Hamidun News
Memory is one of the hardest problems in building autonomous AI agents. Developer Nikolay Gusev spent months looking for a workable solution and explains how he arrived at something both simple and scalable.
MemPalace and the first mistake
It all started with an ambitious idea: MemPalace, a memory system inspired by the architecture of medieval palaces. It looked clever on paper, but in practice it produced 58 thousand duplicate fragments and turned into an impassable maze. Too many layers of abstraction, too much magic. The agent got lost in its own memory.
The path to simplicity
After MemPalace, the author cut the stack down to four components: MEMORY.md (the main store), USER.md (user context), SQLite state.db (state), HippoRAG (search) and wiki files (structured data). But even that felt excessive. The right move was to write `findings_to_wiki`, a simple 300-line Python script that automatically saves structured analyses (marked with headings such as `## Findings`) to markdown files and converts them into wiki pages. No frameworks, no ORMs, just files and text.
Scaling: ClickHouse
When there is a single agent, file storage works perfectly. But supporting 100+ users at once calls for a real database. This is where ClickHouse 24.x comes in. Key features:
- Vector search via the `cosineDistance()` function: fast lookup of semantically similar memories
- Text search with the `tokenbf_v1` index: full-text search across memory
- Partitioning by user_id: user data isolation is built into the database
- TTL for automatic deletion: old records are removed without manual intervention
ClickHouse runs analytics and search across millions of records in milliseconds. For agent memory, that is more than enough.
What this means
The main takeaway: don't start with scaling. Solve the problem simply (files, markdown, 300 lines of code), then scale only if you need to. Nikolay showed that the best engineering path runs from complexity to simplicity, not the other way around.
- Nov 1, 2026Local models lose to Opus and Codex: 0.21 on a MacBook versus 1.00 for Codex
- Nov 1, 2026Adobe's EditAgent judge picks a usable edit 81.3% of the time, versus 74.8% for EditScore
- Nov 1, 202616 models tested on 7 search tools: Exa averaged 10.5 out of 14, SearXNG about 3
- Nov 1, 2026Google's StreamVibe video agent beats other models by 10.7% on response timing and quality
Key Questions Answered
What are the key details on MemPalace and the first mistake?
It all started with an ambitious idea: MemPalace, a memory system inspired by the architecture of medieval palaces. It looked clever on paper, but in practice it produced 58 thousand duplicate fragments and turned into an impassable maze. Too many layers of abstraction, too much magic. The agent got lost in its own memory.
What are the key details on The path to simplicity?
After MemPalace, the author cut the stack down to four components: MEMORY.md (the main store), USER.md (user context), SQLite state.db (state), HippoRAG (search) and wiki files (structured data). But even that felt excessive. The right move was to write `findings_to_wiki`, a simple 300-line Python script that automatically saves structured analyses (marked with headings such as `## Findings`) to markdown files and converts them into wiki pages. No frameworks, no ORMs, just files and text.
What are the key details on Scaling: ClickHouse?
When there is a single agent, file storage works perfectly. But supporting 100+ users at once calls for a real database. This is where ClickHouse 24.x comes in. Key features: Vector search via the `cosineDistance()` function: fast lookup of semantically similar memories Text search with the `tokenbf_v1` index: full-text search across memory Partitioning by user_id: user data isolation is built into the database TTL for automatic deletion: old records are removed without manual intervention ClickHouse runs analytics and search across millions of records in milliseconds. For
Test Frontier LLMs & Autonomous Agents in One Workspace
Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.
The AI world, distilled — once a week
Seven stories that actually mattered, hand-picked. No noise, no reposts, no press releases.
Done! Check your inbox for a confirmation.