MemPalace: Redefining AI Memory with the Method of Loci -- A Deep Dive into the 42K-Star Open Source Project
On April 5, 2026, a Python package called MemPalace quietly appeared on GitHub. One week later, it had accumulated over 42,000 stars, making it one of the fastest-growing AI open source projects in recent memory.
The problem it solves is intuitive: LLMs have no memory. Every conversation starts from scratch. But its solution challenges the mainstream assumptions of the entire AI memory field.
The Problem with Current Solutions
Existing AI memory solutions (Mem0, Mastra, Supermemory) almost all follow the same pattern: use an LLM to extract structured facts from conversations, then store them in a vector database.
This approach has three fundamental problems:
- Expensive -- every write requires an LLM API call
- Lossy -- the extraction process inevitably loses context and nuance
- API-dependent -- nothing works without an API key
MemPalace's core thesis: the field is over-engineering the memory extraction step. Raw verbatim text with good embeddings is a stronger baseline than anyone realized -- because it doesn't lose information.
The numbers speak for themselves: MemPalace achieves 96.6% R@5 on LongMemEval with zero API calls, beating every system that requires a paid LLM API. With optional Claude Haiku reranking (~$0.001/query), it hits 100%.
The Memory Palace: More Than a Metaphor
MemPalace's data structure directly borrows from the ancient Greek "Method of Loci" mnemonic technique. This isn't just marketing -- it genuinely shapes how data is organized:
| Level | Concept | Purpose |
|---|---|---|
| Wing | Palace wing | Top-level domains: projects, people, teams |
| Room | Room within a wing | Topics: backend, decisions, planning |
| Hall | Hall within a room | Memory types: facts, events, discoveries, preferences, advice |
| Drawer | Drawer within a hall | Atomic memory unit: a specific chunk of text |
| Closet | Compressed storage | AAAK-compressed summaries (experimental) |
This hierarchy lets semantic search operate at different granularities: you can search the entire palace, or constrain to a specific Wing or Room.
4-Layer Memory Stack: 600-Token Wake-Up Cost
This is one of MemPalace's most elegant designs. It splits memory into four layers, each with different loading triggers and token costs:
| Layer | Name | Token Cost | When Loaded |
|---|---|---|---|
| L0 | Identity | ~100 | Always |
| L1 | Essential Story | ~500-800 | Always |
| L2 | On-Demand | ~200-500/call | Topic-relevant |
| L3 | Deep Search | Unlimited | Explicit query |
L0 -- Identity loads "who am I" basics from ~/.mempalace/identity.txt, about 100 tokens.
L1 -- Essential Story auto-generates a summary from highest-importance Drawers, about 500-800 tokens. Together, these two layers represent the AI's "wake-up" cost: 600-900 tokens, leaving 95%+ of the context window free for actual conversation.
L2 -- On-Demand retrieves filtered results by Wing/Room when the conversation touches a specific topic.
L3 -- Deep Search performs full semantic search across all Drawers -- the most complete but most token-expensive layer.
The API is straightforward:
from mempalace.layers import MemoryStack
stack = MemoryStack()
# Wake up: L0 + L1, ~600-900 tokens
print(stack.wake_up())
# On-demand retrieval: L2
print(stack.recall(wing="my_app"))
# Deep search: L3
print(stack.search("why did we switch to GraphQL"))
Temporal Knowledge Graph: Memory Isn't Just "What" -- It's "When"
Pure vector search has a fundamental blind spot: it can't distinguish "Max is learning to swim" from "Max was learning to swim last year." MemPalace solves this with a SQLite-backed triple store where every entity and relationship has valid_from / valid_to timestamps.
kg = KnowledgeGraph()
# Add time-stamped triples
kg.add_triple("Max", "child_of", "Alice", valid_from="2015-04-01")
kg.add_triple("Max", "does", "swimming", valid_from="2025-01-01")
# When facts change, invalidate old ones
kg.invalidate("Max", "has_injury", "ankle", ended="2026-02-15")
# Query facts at a specific point in time
kg.query_entity("Max", as_of="2026-03-01", direction="both")
# View timeline
kg.timeline("Max") # chronological fact history
This enables temporal reasoning that pure RAG systems simply cannot do.
19 MCP Tools: A Complete Memory Operations Interface
MemPalace exposes 19 tools via MCP (Model Context Protocol), letting any MCP-compatible AI client directly operate on memory:
Read
status/list_wings/list_rooms/get_taxonomy-- browse palace structuresearch/get_drawer/list_drawers-- search and read memoriescheck_duplicate-- deduplication check (cosine similarity threshold 0.9)
Write
add_drawer/update_drawer/delete_drawer-- CRUD operations
Knowledge Graph
kg_query/kg_add/kg_invalidate/kg_timeline/kg_stats
Graph Navigation
traverse-- BFS room walking, discover related memoriesfind_tunnels-- cross-Wing bridges, find unexpected connections
Agent Diary
diary_write/diary_read-- cross-session AI agent journal
Integration with Claude Code takes one line:
claude mcp add mempalace -- python -m mempalace.mcp_server --palace /path/to/palace
Palace Protocol: Making AI Proactively Use Memory
Infrastructure alone isn't enough. MemPalace also defines a behavioral protocol embedded in the MCP server that guides how AI should use memory:
- On wake-up: call
mempalace_statusto load overview - Before answering about people/projects/events: search first, never guess
- When unsure about a fact: say "let me check" and query
- After each session: write a diary entry
- When facts change: invalidate old, add new
This "search before answering" protocol shifts AI behavior from "might hallucinate" to "verifiably grounded."
Two Data Mining Modes
Project mining (miner.py): reads source files, respects .gitignore, chunks by paragraphs (800 chars with 100 overlap), auto-detects Rooms from folder structure and keyword scoring.
Conversation mining (convo_miner.py): ingests chat exports (Claude Code, ChatGPT, Slack), chunks by exchange pairs (Q+A = one unit), supports 5 format normalizations.
# Mine project files
mempalace mine ~/projects/myapp
# Mine conversations
mempalace mine ~/exports/claude-chats --mode convos
Benchmarks: Admirably Honest
MemPalace's BENCHMARKS.md has a rare quality: radical transparency.
| System | LongMemEval R@5 | API Required | Cost |
|---|---|---|---|
| MemPalace (raw) | 96.6% | No | $0 |
| MemPalace (hybrid v4 + Haiku) | 100% | Optional | ~$0.001/query |
| Supermemory ASMR | ~99% | Yes | Paid |
| Mastra | 94.87% | Yes | Paid |
| Hindsight | 91.4% | Yes | Paid |
| Mem0 RAG | 30-45% | Yes | Paid |
The authors explicitly flag which scores involved "teaching to the test" (hybrid v4 fixes were developed by examining specific failed questions), provide held-out validation numbers, and note the top-50 LoCoMo caveat. This level of self-correction is remarkably rare in open source.
Current limitations worth noting:
- AAAK compression mode only achieves 84.2% R@5 (vs 96.6% raw)
- MemBench "noisy" category scores only 43.4% (weak against adversarial noise)
- No multilingual embedding support yet
Minimalist Tech Choices
MemPalace's dependency list is strikingly short:
- Only 2 core dependencies --
chromadbandpyyaml - Vector DB -- ChromaDB (local, cosine similarity, HNSW index)
- Knowledge Graph -- SQLite3 + WAL mode
- Build system -- Hatchling
- No LLM SDK, no external APIs, no heavy infrastructure
This isn't accidental -- it's a deliberate design choice. When your memory layer doesn't depend on any LLM API, you eliminate latency, cost, and vendor lock-in in one stroke.
AAAK Dialect: Experimental Symbolic Compression
MemPalace also ships an experimental feature: the AAAK dialect (dialect.py), a lossy symbolic compression format:
FAM: ALC->JOR | 2D(kids): RIL(18,sports) MAX(11,chess+swimming) | BEN(contributor)
- 3-letter entity codes (ALC=Alice, JOR=Jordan)
- Emotion markers (warm, fierce, raw)
- Pipe-separated fields, ISO dates
- Importance scale: 1-5 stars
Currently AAAK mode regresses to 84.2% R@5, so it's marked experimental. But the direction is worth watching: if a better balance between compression ratio and accuracy can be found, the token cost of long-term memory could drop further.
Why This Project Matters
MemPalace's value isn't just in its technical implementation -- it's in the core question it poses:
Do we actually need LLMs for memory extraction?
When 96.6% accuracy can be achieved with zero API calls, and most systems requiring paid APIs can't even match that, the answer becomes clear.
This echoes a broader trend in AI engineering: before reaching for more AI, ask whether a simple engineering solution is good enough. ChromaDB's default embeddings plus raw text is an extraordinarily strong baseline -- many complex architectures may only be making marginal improvements on top of it.
MemPalace's roadmap is also worth following: v4.0-alpha will support swappable storage backends (PostgreSQL, LanceDB), local NLP entity extraction without APIs, and keyword matching search fallback. They also plan to publish an arXiv paper.
Getting Started
# Install
pip install mempalace
# Initialize (creates mempalace.yaml config)
mempalace init ~/projects/myapp
# Mine project files
mempalace mine ~/projects/myapp
# Search
mempalace search "why did we switch to GraphQL"
# Integrate with Claude Code
claude mcp add mempalace -- python -m mempalace.mcp_server --palace ~/projects/myapp
For those who want to go deeper, read the source code directly: layers.py (4-layer stack), knowledge_graph.py (temporal triples), and mcp_server.py (19 MCP tool definitions). These three files are the soul of MemPalace.
GitHub: github.com/MemPalace/mempalace | License: MIT | Stars: 42K+ | Language: Python


