How burttwang/mempalace works
1. This is a local-first Python memory system.
The core package is mempalace/, exposed as both a CLI (cli.py, __main__.py) and an MCP server (mcp_server.py). The architecture is centered on ingesting local data, organizing it into a “palace” model, and retrieving it later through search or AI tools.
2. There are two main ingest paths: projects and conversations.
miner.py handles project/file ingestion, while convo_miner.py handles conversation exports and chunks them into exchange-based memory units. normalize.py standardizes multiple chat formats into a common transcript shape, and split_mega_files.py preprocesses concatenated transcript exports into per-session files.
3. The storage layer is split between verbatim memory and structured metadata.
The README makes the primary store explicit: raw memories are kept in ChromaDB as “drawers” with no default summarization. Wing/room metadata acts as an organization layer on top of that raw content. Configuration and user identity live locally in files under ~/.mempalace/.
4. Search is semantic, filtered, and local.
searcher.py is the retrieval entry point, likely querying ChromaDB and applying optional wing/room constraints. The retrieval model is not just keyword search; it uses the palace taxonomy to narrow scope before semantic matching.
5. The “palace” graph is the main navigation abstraction.
palace_graph.py models the structural relationships described in the README: wings, rooms, halls, and tunnels. This graph is used for taxonomy, connectivity, traversal, and cross-wing discovery rather than as the primary content store.
6. There is a separate temporal knowledge graph for facts.
knowledge_graph.py stores entity relationships with validity windows, and the README says it uses SQLite locally. This graph supports time-aware queries, invalidation of obsolete facts, and timeline reconstruction. entity_registry.py and entity_detector.py support entity normalization and extraction around this graph.
7. AAAK is a compression/representation layer, not the base store.
dialect.py and layers.py define the “memory stack” and the AAAK dialect used for compact context loading or diary-style output. The key architectural boundary is that AAAK is separate from raw storage: it is used to compress or present memory, not to replace the verbatim source data.
8. Onboarding and configuration shape the whole system.
onboarding.py generates the initial palace setup, wing mappings, and identity bootstrap. config.py centralizes global settings such as palace path, collection name, and people/project mappings. This config is what lets the same ingestion/search pipeline adapt to different local datasets.
9. The MCP server is the integration boundary to external AI clients.
mcp_server.py exposes the memory system as tools for Claude, Cursor, Gemini, and other MCP-compatible clients. The tool surface covers read operations, write operations, graph queries, traversal, and agent diary access. Architecturally, this is the “AI-facing API” over the local storage and graph subsystems.
10. There is automation around capture, not just retrieval.
The shell hooks in hooks/ are designed to save memory automatically during AI work sessions, including a pre-compact save. This makes memory capture event-driven: messages or context pressure trigger writes into the palace instead of relying on manual ingestion only.
11. Benchmarks, examples, and tests are first-class support systems.
benchmarks/ contains reproducible runners for LongMemEval, LoCoMo, and related evaluations. examples/ shows mining, MCP setup, and integration patterns. tests/ covers config, normalization, search, graph behavior, mining, MCP server behavior, and version consistency, indicating the main architectural seams are intentionally unit-tested.
12. The repo is packaged as a standard Python distribution.
pyproject.toml, uv.lock, and py.typed show this is a typed Python package intended for installation as a CLI/library. The surrounding docs, issue templates, and CI workflow support that packaging model rather than a monolithic application deployment.
13. A useful way to diagram it is as three planes:
- Ingest plane: files/transcripts → normalization/splitting → mining
- Memory plane: ChromaDB drawers + palace graph + knowledge graph + AAAK/layers
- Access plane: CLI, search API, MCP server, hooks, and benchmark/test harnesses
Those are the main architectural boundaries that matter most when drawing the system.
Main entry points: mcp_server.py MCP server · searcher.py Search · knowledge_graph.py Knowledge graph · test_mcp_server.py Tests
Components 20
Ingest plane
Normalize local data, split exports, and mine memories into the system.
- Normalize · Converts different chat export formats into a common transcript shape.
mempalace/normalize.py - Split exports · Breaks concatenated transcript dumps into per-session files before mining.
mempalace/split_mega_files.py - Conversation miner · Chunks conversation exports into exchange-based memory units.
mempalace/convo_miner.py - Project miner · Ingests local project and file data into memory drawers.
mempalace/miner.py
Memory plane
Core storage and graph structures for verbatim memories, palace layout, and facts.
- Drawers · Primary verbatim memory store in ChromaDB; keeps raw memories without default summarization.
- Palace graph · Represents wings, rooms, halls, and tunnels for organization and traversal.
mempalace/palace_graph.py - Knowledge graph · Stores entity relationships with validity windows in local SQLite.
mempalace/knowledge_graph.py - Entity registry · Resolves and normalizes entities used by the temporal knowledge graph.
mempalace/entity_registry.py - Entity detector · Extracts entities and relationship signals from local content for the knowledge graph.
mempalace/entity_detector.py - Memory layers · Defines the memory stack used to assemble compact context views.
mempalace/layers.py - AAAK dialect · Encodes compact, diary-style memory representations for loading or display.
mempalace/dialect.py
Access plane
CLI, MCP, and search interfaces that read and write the local memory system.
- Search · Queries local memories with optional palace-scope filters.
mempalace/searcher.py - MCP server · Exposes read/write, graph traversal, and diary tools to MCP-compatible clients.
mempalace/mcp_server.py - CLI · Local command-line entry point for mining, search, and system operations.
mempalace/cli.py
Support plane
Onboarding, automation, packaging, examples, benchmarks, and tests around the core system.
- Onboarding · Creates the initial palace setup, wing mappings, and identity bootstrap.
mempalace/onboarding.py - Config · Centralizes palace path, collection name, and user/project mappings.
mempalace/config.py - Shell hooks · Auto-save and pre-compact hooks that capture memory during AI work sessions.
hooks/mempal_save_hook.sh - Benchmarks · Reproducible runners for LongMemEval, LoCoMo, and related evaluations.
benchmarks/README.md - Tests · Covers config, normalization, search, graphs, mining, MCP, and version consistency.
tests/test_mcp_server.py - Package · Typed Python package and standard distribution metadata.
pyproject.toml
Connections 26
- Split exports → Normalize: prepares · Splits large exports into session files before normalization.
- Normalize → Conversation miner: feeds · Standardized transcripts are consumed by conversation mining.
- Conversation miner → Drawers: stores · Writes chunked conversation memories into the raw memory store.
- Project miner → Drawers: stores · Indexes project and file memories as verbatim drawers.
- Project miner → Palace graph: organizes · Assigns mined content into the palace structure for navigation.
- Entity detector → Entity registry: normalizes · Detected entities are resolved through the registry.
- Entity registry → Knowledge graph: updates · Canonical entities anchor temporal relationships in the graph.
- Entity detector → Knowledge graph: extracts · Entity and relationship signals populate the fact graph.
- Memory layers → AAAK dialect: renders · Compression layers produce compact AAAK output.
- Drawers → Search: queries · Semantic retrieval reads from the raw memory store.
- Palace graph → Search: filters · Wing and room scope constrains retrieval.
- Knowledge graph → Search: augments · Temporal facts can support search and reconstruction.
- Search → MCP server: exposes · Retrieval is surfaced as AI tools through the MCP server.
- Palace graph → MCP server: traverses · Graph traversal and navigation tools use the palace model.
- Knowledge graph → MCP server: queries · MCP tools can read time-aware entity facts.
- AAAK dialect → MCP server: formats · Compact memory views are exposed to clients.
- Config → CLI: configures · CLI behavior depends on local settings and mappings.
- Config → MCP server: configures · Server paths and collection settings come from local config.
- Onboarding → Config: bootstraps · Initial setup populates the core local configuration.
- Shell hooks → Project miner: automates · Hooks trigger capture and save flows during AI sessions.
- Benchmarks → Search: evaluates · Benchmark runners measure retrieval behavior.
- Tests → Normalize: verifies · Tests cover transcript normalization behavior.
- Tests → Search: verifies · Tests cover retrieval and filtering behavior.
- Tests → MCP server: verifies · Tests cover the AI-facing tool boundary.
- Package → CLI: packages · The distribution exposes the CLI entry point.
- Package → MCP server: packages · The distribution includes the server runtime.