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_v1index: 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.
- Dec 2, 2026Ai2 Releases MolmoWeb2 Web Agents: 27B Model Solves 75.3% of Tasks
- Dec 2, 2026Amazon Releases Ergo Open Weights for Coding: 1.1 Trillion Parameters and 2,200 Tokens per Second
- Dec 2, 2026OpenAI Opens Dots Agent to ChatGPT Plus Subscribers With 10,000+ Plugins
- Dec 2, 2026FSK Group Has Launched 395 AI Agents in Six Months, with a 97.7% Success Rate
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…
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.
Daily 60-sec AI Voice Brief + Weekly Production AI Agent Playbook
Listen to a 60-second AI news brief every morning and get a weekly hands-on playbook for shipping AI agents to production — tools, MCP servers and patterns that work. Curated by Jemal Hamidun, Head of AI at Alpina Digital.
