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 & Integrity
MemPalace-rs is validated against the 2026 Gold Standards for AI memory. Our methodology prioritizes high-integrity reasoning and ultra-long context persistence over synthetic "recall-only" metrics.
2026 Gold Standard Validation
Verified multi-hop reasoning, 1M+ token persistence, and structural integrity.
| Benchmark | Score | Metric | Latency |
|---|---|---|---|
| **RULER ** | 1.000 | nDCG | 120.0 ms |
| **STRUCTMEM ** | 1.000 | Structural | 33.0 ms |
| **BABILONG ** | 1.000 | Reasoning | 529.0 ms |
| **BEAM ** | 1.000 | Nugget | 24.0 ms |
[!TIP] For a full technical breakdown of our anti-fraud methodologyβincluding strict
top_k <= 10limits and end-to-end reasoning validationβplease see the Detailed Benchmarking Report.
Low-Level Micro-Benchmarks
Raw throughput measured on local hardware.
| Operation | Throughput | Latency |
|---|
Benchmarks performed on Apple Silicon M4. Results are generated autonomously by CI on every release.
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 (supports --limit, --dry-run, --no-gitignore) |
search <query> |
Semantic search over ingested data (supports --wing, --room, --results) |
repair |
Recover/re-index vector storage from SQLite metadata |
instructions |
Output system prompts for AI agent onboarding |
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 (all prefixed with mempalace_):
Palace Overview
mempalace_status- Returns total drawers, wings, rooms, protocol, and AAAK specmempalace_list_wings- Returns all wings with countsmempalace_list_rooms- Returns rooms within a wingmempalace_get_taxonomy- Returns full wing β room β count treemempalace_graph_stats- Graph overview
Search & Retrieval
mempalace_search- Semantic search with wing/room filtersmempalace_check_duplicate- Similarity check for deduplicationmempalace_prune- Semantic memory pruning and merging
Graph Navigation
mempalace_traverse_graph- BFS walk from start_roommempalace_find_tunnels- Find bridge rooms
Content Management
mempalace_add_drawer- Add verbatim contentmempalace_delete_drawer- Remove drawer by IDmempalace_get_aaak_spec- Returns AAAK spec
Knowledge Graph
mempalace_kg_add- Add triple (subject, predicate, object)mempalace_kg_query- Query entity relationshipsmempalace_kg_invalidate- Mark triple as invalidmempalace_kg_timeline- Get chronological timelinemempalace_kg_stats- KG statistics
Agent Diary
mempalace_diary_write- Persist agent journal entrymempalace_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.
Extended Platform Support
Android (Termux)
MemPalace-RS is optimized for ARM64 mobile environments. To set up your environment in Termux:
This will install the native onnxruntime and patch ort-sys for local compatibility.
Parity with Python Original
This project is a 100% functional port of the original Python mempalace implementation. For a detailed breakdown of feature parity, compatibility status, and Rust-exclusive enhancements, see the Full Parity Report.
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.