Memory for an AI Agent: From Complexity to 300 Lines of Code
Developer Nikolay Gusev explained how he found an optimal memory solution for AI agents. Instead of the complex MemPalace with 58k duplicates, he proposes a simple system built with 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
AI agent memory is one of the most complex problems when building autonomous systems. Developer Nikolay Gusev spent months searching for a working solution and shared how he achieved simplicity and scalability at the same time.
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 smart on paper, but in practice created 58 thousand duplicate fragments and turned into an impenetrable 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 simplified the stack to four components: MEMORY.md (main database), USER.md (user context), SQLite state.db (state), HippoRAG (search) and wiki files (structured data). But even this seemed excessive. The right move was writing `findings_to_wiki`, a simple 300-line Python script that automatically saves structured analyses (marked with headings like `## Findings`) into markdown files and transforms them into wiki pages. No frameworks, no ORM, just files and text.
Scaling: ClickHouse
When there's only one agent, file storage works perfectly. But if you need to support 100+ users simultaneously, you need a real database. This is where ClickHouse 24.x comes into play. Key features:
- Vector search via the `cosineDistance()` function — fast search for semantically similar memories
- Text search with `tokenbf_v1` index — full-text search across memory
- Partitioning by user_id — user data isolation built into the database
- TTL for automatic deletion — old records are deleted without manual intervention
ClickHouse performs analytics and search across millions of records in milliseconds. For agent memory, this is more than sufficient.
What this means
The key takeaway: don't start with scaling. Solve the problem simply (files, markdown, 300 lines of code), then scale only if needed. Nikolay demonstrated that the best engineering path is from complexity to simplicity, not the other way around.
- Oct 28, 2026AdaPRA lifts Qwen 80B by 24.5 points on data science leaderboards
- Oct 28, 2026AOS-Bench: Agents Separated by 0.6 Points in Isolation Deliver 54% and 68% of the Same Tasks
- Oct 28, 2026CuraLoc finds bugs in repositories with a single plan and uses 90% fewer tokens
- Oct 28, 2026Wired Tested 6 AI Agents in a Day: Dots Leads, Gemini Spark Fails at Lunch
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 smart on paper, but in practice created 58 thousand duplicate fragments and turned into an impenetrable 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 simplified the stack to four components: MEMORY.md (main database), USER.md (user context), SQLite state.db (state), HippoRAG (search) and wiki files (structured data). But even this seemed excessive. The right move was writing `findings_to_wiki`, a simple 300-line Python script that automatically saves structured analyses (marked with headings like `## Findings`) into markdown files and transforms them into wiki pages. No frameworks, no ORM, just files and text.
What are the key details on Scaling: ClickHouse?
When there's only one agent, file storage works perfectly. But if you need to support 100+ users simultaneously, you need a real database. This is where ClickHouse 24.x comes into play. Key features: Vector search via the `cosineDistance()` function — fast search for semantically similar memories Text search with `tokenbf_v1` index — full-text search across memory Partitioning by user_id — user data isolation built into the database TTL for automatic deletion — old records are deleted without manual intervention ClickHouse performs analytics and search across millions of re
Build & Ship Production AI Agents Without Boilerplate Code
Start your free 72-hour trial at Hamidun Academy (academy.hamidun.com) — interactive lessons on Claude Code & Cursor, live Tech Radar, and production agent templates.
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.