mempalace-rs
A high-performance, local, offline-first AI memory system built in Rust. Gives AI agents long-term retention by mining local codebases and conversations into a structured, searchable, and symbolic "palace."
Features
- 4-Layer Memory Stack (L0-L3): Hierarchical context from identity to deep semantic search
- AAAK V:3.2 Compression: ~30x token reduction with adaptive density, importance scoring, and delta encoding
- Temporal Knowledge Graph: Entity relationships with valid_from/valid_to tracking
- 20 MCP Tools: Full Model Context Protocol integration for AI agent interaction
- SQLite + VectorStorage: Native embedding storage for structured and vector data
- 197 Tests: All passing, production-ready
Installation
From Source
Requires Rust 1.70+ and the cargo build system.
From Crates.io (Coming Soon)
Once stable, you can install the binary directly:
π Insta-Setup (Top 3 AI Clients)
Connect your palace to your favorite agent in seconds. For all 15+ supported platforms, see SKILLS_GUIDE.md.
1. Claude Code
Open your terminal in the project root and run:
2. Cursor
Go to Settings > Features > MCP > Add New MCP Server:
- Name:
mempalace - Type:
command - Command:
cargo run -- mcp-server - CWD: Full path to this repository
3. Windsurf
Simply drag and drop the mempalace-rs.skill file into your Windsurf chat or project sidebar to load all tools and instructions automatically.
Performance
| Operation | Throughput | Latency |
|---|---|---|
| AAAK Compression | ~1793 ops/sec | 557 Β΅s |
| Entity Detection | ~257567 ops/sec | 4 Β΅s |
| Token Counting | ~3575680 ops/sec | 280 ns |
| Compression Stats | ~1266871 ops/sec | 789 ns |
AAAK v3.2 Evolution Metrics
Measured against the internal LongMemEval-CI benchmark suite
| Mode | Recall@5 | Recall@10 | Latency/Query |
|---|---|---|---|
| RAW | 100.0% | 100.0% | 518.0ms |
| AAAK | 100.0% | 100.0% | 432.5ms |
Benchmarked on Apple Silicon M4, 16GB RAM. Performance may vary by hardware.
Binary Size: 7.9 MB (release build) Cold Start: ~300 ms Memory Usage: ~50 MB baseline
Quick Start
# Build
# Run tests
# Start MCP server (for AI integration)
# Mine a project
# Search your palace
# Get wakeup context
# Semantic Pruning
Requirements
- Rust 1.70+ (edition 2021)
- (Vector storage is fully embedded and zero-network)
- Optional:
cargo-llvm-covfor coverage reports
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MEMORY STACK (L0-L3) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β L0: IDENTITY β Core persona (~100 tokens) β
β L1: ESSENTIAL β Recency-biased events (~500-800 tokens) β
β L2: ON-DEMAND β Similarity-searched context β
β L3: SEARCH β Raw semantic search β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββ
β β β
ββββββΌβββββ ββββββΌβββββ ββββββΌβββββ
βStorage β βSearcher β βDialect β
β(SQLite) β β(Search) β β(AAAK) β
ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ
β β β
ββββββΌββββββββββββββββββββββΌββββββββββββββββββββββΌβββββ
β Knowledge Graph (SQLite) β
β entities βββΊ triples (temporal) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Storage Backends
- VectorStorage (usearch): Documents with embeddings + metadata (wing/room/source_file)
- SQLite (relational): Wings, diary entries, knowledge graph triples
AAAK Dialect
~30x token compression using entity codes, emotion codes, and zettel format:
WING|ROOM|DATE|SOURCE
0:ENTITIES|TOPICS|"QUOTE"|EMOTIONS|FLAGS
CLI Commands
| Command | Description |
|---|---|
init <dir> |
Guided onboarding with room detection |
mine <dir> |
Ingest projects or conversations |
search <query> |
Semantic search over ingested data |
wakeup |
Get L0+L1 context (~600-900 tokens) |
compress |
AAAK compress drawers |
split <dir> |
Split mega-files into per-session files |
prune |
Semantic deduplication (clustering/merging) |
mcp-server |
Run MCP server over stdio |
MCP Tools
The project exposes 20 tools via Model Context Protocol:
Palace Overview
tool_status- Returns total drawers, wings, rooms, protocol, AAAK spectool_list_wings- Returns all wings with countstool_list_rooms- Returns rooms within a wingtool_get_taxonomy- Returns full wing β room β count treetool_graph_stats- Graph overview
Search & Retrieval
tool_search- Semantic search with wing/room filterstool_check_duplicate- Similarity check for deduplicationtool_prune- Semantic memory pruning and merging
Graph Navigation
tool_traverse_graph- BFS walk from start_roomtool_find_tunnels- Find bridge rooms
Content Management
tool_add_drawer- Add verbatim contenttool_delete_drawer- Remove drawer by IDtool_get_aaak_spec- Returns AAAK spec
Knowledge Graph
tool_kg_add- Add triple (subject, predicate, object)tool_kg_query- Query entity relationshipstool_kg_invalidate- Mark triple as invalidtool_kg_timeline- Get chronological timelinetool_kg_stats- KG statistics
Agent Diary
tool_diary_write- Persist agent journal entrytool_diary_read- Retrieve last N diary entries
Project Structure
mempalace-rs/
βββ src/
β βββ main.rs # CLI entry point
β βββ lib.rs # Module exports
β βββ storage.rs # MemoryStack (L0-L3)
β βββ searcher.rs # Vector semantic search
β βββ mcp_server.rs # 20 MCP tools
β βββ dialect.rs # AAAK compression (V:3.2)
β βββ knowledge_graph.rs # Temporal triples
β βββ diary.rs # SQLite-backed agent journal
β βββ miner.rs # File chunking, room detection
β βββ entity_detector.rs # NER with signal scoring
β βββ ... # Additional modules
βββ tests/ # 7 integration test suites
βββ .github/workflows/ # CI configuration
βββ mempalace-rs.skill # Agent skill file
Key Modules
| Module | Purpose |
|---|---|
storage.rs |
MemoryStack (L0-L3) implementation |
searcher.rs |
Vector semantic search |
dialect.rs |
AAAK compression (~30x token reduction) |
knowledge_graph.rs |
Temporal triples with valid_from/valid_to |
mcp_server.rs |
20 MCP tools for agent integration |
diary.rs |
SQLite-backed agent journal |
miner.rs |
File chunking, room detection |
entity_detector.rs |
Heuristic NER (People/Projects/Terms) |
palace_graph.rs |
Room navigation graph (BFS, tunnels) |
Development
# Build
# Run tests
# Run with coverage
# Lint
# Format
Test Mode
Set MEMPALACE_TEST_MODE=1 to skip DB initialization in tests:
MEMPALACE_TEST_MODE=1
Configuration
- Diary:
~/.mempalace/diary.db(SQLite with indexed timestamps) - Knowledge Graph:
knowledge.db(SQLite with temporal triples) - Palace Data:
~/.mempalace/(usearch + SQLite) - Identity:
~/.mempalace/identity.txt(L0 persona)
Contributing
See CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE file.
Acknowledgments
This is a Rust port of the original MemPalace Python project by Milla Jovovich & Ben Sigman.
Agent Integration
Load mempalace-rs.skill for comprehensive documentation of all 20 MCP tools, architecture details, and best practices for AI agents interacting with the palace.