pi-mempalace 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,303 @@
1
+ # 🧠 pi-mempalace
2
+
3
+ **Your AI forgot everything again. How delightful.**
4
+
5
+ Every conversation you've ever had with an AI — every architectural decision, every late-night debugging eureka, every "let's use Postgres because..." — *poof*. Gone the moment you close the tab. Your AI has the long-term memory of a goldfish at a rave.
6
+
7
+ **pi-mempalace fixes that.** It gives [pi](https://github.com/badlogic/pi-mono) agents persistent, cross-session memory. Store everything. Search it later. Never re-explain your life choices to a machine again.
8
+
9
+ ---
10
+
11
+ ## 🏰 Standing on the Shoulders of a Memory Palace
12
+
13
+ This project is directly inspired by the wonderful [MemPalace](https://www.mempalace.tech) — built by **Milla Jovovich** (yes, *that* Milla Jovovich — Leeloo from *The Fifth Element*, Alice from *Resident Evil*) and developer **Ben Sigman**.
14
+
15
+ Milla's origin story is painfully relatable: after thousands of conversations with AI, she realized every new session was a clean slate. All her decisions, reasoning, creative ideas — thrown into the void. Existing memory tools like Mem0 and Zep tried to help, but they had a fatal flaw: they used AI to decide what was worth remembering. The nuance, the "why," the reasoning behind decisions — exactly the stuff that matters — was the first to go.
16
+
17
+ So Milla and Ben spent months building MemPalace with Claude Code, and landed on a beautifully simple idea:
18
+
19
+ > **Don't let AI decide what to forget — store everything, then make it findable.**
20
+
21
+ Their MemPalace scored **96.6% on LongMemEval** (the standard benchmark for AI memory) in raw mode — the highest published result requiring zero API calls. The full system hit 100% with hybrid reranking, sparking a [glorious internet debate](https://www.mempalace.tech) about benchmarks and bragging rights. 7,000+ GitHub stars in 48 hours. Not bad for an actress and a developer with an idea.
22
+
23
+ pi-mempalace takes that core philosophy — **verbatim storage + semantic search** — and reimagines it as a native [pi](https://github.com/badlogic/pi-mono) extension. No Python. No ChromaDB. No pip install nightmares. Just pure TypeScript running in-process, fast enough to forget that forgetting was ever a problem.
24
+
25
+ ---
26
+
27
+ ## ✨ What It Does
28
+
29
+ - **🔄 Auto-capture** — Every conversation exchange is stored automatically after each turn. You don't have to remember to remember.
30
+ - **🌅 Wake-up context** — Each new session starts with a whisper of who you are and what you've been up to (~600-900 tokens of "previously on your life").
31
+ - **🔍 Semantic search** — Find past decisions by *meaning*, not keywords. "Why did we pick that database?" just works.
32
+ - **📁 Project-aware** — Memories are tagged by project (auto-detected from your directory) and topic. Your work stays organized even if you don't.
33
+ - **🏠 Fully local** — Embeddings computed in-process via `all-MiniLM-L6-v2`. No cloud calls. No API keys. No surveillance capitalism. Just you and your memories.
34
+ - **📊 Beautiful stats** — Sparkline activity charts, bar graphs by project/topic, and a TUI overlay that makes you feel like a hacker in a 90s movie.
35
+
36
+ ---
37
+
38
+ ## 🚀 Install
39
+
40
+ ```bash
41
+ # Install from GitHub
42
+ pi install https://github.com/Jabbslad/pi-mempalace
43
+
44
+ # Or from a local checkout
45
+ pi install /path/to/pi-mempalace
46
+ ```
47
+
48
+ That's it. `pi install` runs `npm install` automatically, which pulls in all three runtime dependencies:
49
+
50
+ | Dependency | What It Does | Native? |
51
+ |-----------|-------------|--------|
52
+ | `@huggingface/transformers` | Local embeddings (all-MiniLM-L6-v2, 384 dims) | No — pure JS, downloads model on first use (~80MB) |
53
+ | `better-sqlite3` | SQLite database access | Yes — compiles native addon via `node-gyp` |
54
+ | `sqlite-vec` | Vector similarity search for SQLite | Yes — ships prebuilt binary per platform |
55
+
56
+ No Python. No conda. No Docker. No ChromaDB server. No API keys. No sacrificial offerings to the dependency gods.
57
+
58
+ ### Prerequisites
59
+
60
+ - **Node.js** (required by pi)
61
+ - **C++ toolchain** for `better-sqlite3`'s native build:
62
+ - macOS: `xcode-select --install`
63
+ - Linux: `sudo apt install build-essential` (or equivalent)
64
+ - Windows: Visual Studio Build Tools
65
+
66
+ Most dev machines already have this. If `pi install` fails with gyp errors, that's the fix.
67
+
68
+ ---
69
+
70
+ ## 🎮 Quick Start
71
+
72
+ ```bash
73
+ # Set up your identity and verify everything works
74
+ /skill:memory-setup
75
+
76
+ # Explicitly save something important
77
+ memory_save("We chose PostgreSQL for concurrent write support", project: "myapp", topic: "database")
78
+
79
+ # Search later, when you've inevitably forgotten
80
+ memory_search("why did we pick the database?")
81
+
82
+ # Browse a project's collected wisdom
83
+ memory_recall(project: "myapp")
84
+
85
+ # Check on your growing brain
86
+ memory_status()
87
+ ```
88
+
89
+ ---
90
+
91
+ ## 🧰 Tools
92
+
93
+ ### Memory Tools
94
+ | Tool | What It Does |
95
+ |------|-------------|
96
+ | `memory_search` | Semantic search across all stored memories — find things by meaning |
97
+ | `memory_save` | Explicitly save important info — for those "remember this" moments |
98
+ | `memory_recall` | Browse memories by project/topic — like flipping through a journal |
99
+ | `memory_status` | Memory store overview — how big is your brain now? |
100
+
101
+ ### Palace Graph Tools
102
+ | Tool | What It Does |
103
+ |------|-------------|
104
+ | `memory_graph` | Visualize the palace — projects as wings, shared topics as tunnel connections |
105
+ | `memory_tunnel` | Traverse a tunnel between two projects via a shared topic |
106
+
107
+ ### Knowledge Graph Tools
108
+ | Tool | What It Does |
109
+ |------|-------------|
110
+ | `knowledge_add` | Add structured facts — "myapp uses PostgreSQL since 2025-01" |
111
+ | `knowledge_query` | Query facts about an entity, with temporal filtering — "what did we use in 2024?" |
112
+ | `knowledge_status` | Knowledge graph stats — entities, facts, predicates |
113
+
114
+ ## ⌨️ Commands
115
+
116
+ | Command | What It Does |
117
+ |---------|-------------|
118
+ | `/memory status` | Quick status overview |
119
+ | `/memory stats` | Full stats overlay with sparklines and bar charts |
120
+ | `/memory project <name>` | Set current project context |
121
+ | `/memory search <query>` | Quick search shortcut |
122
+ | `/memory graph` | Show palace graph with cross-project connections |
123
+ | `/memory knowledge <entity>` | Query knowledge graph for an entity |
124
+ | `/memory on` / `off` | Enable/disable memory (for those private moments) |
125
+
126
+ ---
127
+
128
+ ## 🏗️ Architecture
129
+
130
+ Following the [MemPalace](https://www.mempalace.tech) 4-layer memory stack:
131
+
132
+ ```
133
+ ┌─────────────────────────────────────────────────────────┐
134
+ │ L0: IDENTITY (~100 tokens) │
135
+ │ Always loaded. ~/.pi/agent/memory/identity.txt │
136
+ ├─────────────────────────────────────────────────────────┤
137
+ │ L1: ESSENTIAL STORY (~500-800 tokens) │
138
+ │ Top 15 memories by importance + recency. │
139
+ │ Grouped by project. Injected at session start. │
140
+ ├─────────────────────────────────────────────────────────┤
141
+ │ L2: ON-DEMAND PROJECT CONTEXT │
142
+ │ Filtered by project/topic via SQL indexes. │
143
+ │ Loaded only when you ask about a specific area. │
144
+ ├─────────────────────────────────────────────────────────┤
145
+ │ L3: DEEP SEMANTIC SEARCH │
146
+ │ Full vector similarity via sqlite-vec ANN index. │
147
+ │ Searches 100K+ memories in milliseconds. │
148
+ └─────────────────────────────────────────────────────────┘
149
+ ```
150
+
151
+ ```
152
+ pi (TypeScript — everything in-process)
153
+ ┌──────────────────────────────────────────────────┐
154
+ │ extensions/pi-mempalace/ │
155
+ │ │
156
+ │ index.ts memory_store.ts │
157
+ │ ┌──────────────────┐ ┌────────────────────┐ │
158
+ │ │ turn_end → │ │ MemoryStore │ │
159
+ │ │ auto-capture │───│ │ │
160
+ │ │ before_agent → │ │ SQLite + sqlite-vec│ │
161
+ │ │ L0+L1 inject │←──│ ANN vector search │ │
162
+ │ │ Tools + Commands │ │ Metadata indexes │ │
163
+ │ │ Stats TUI overlay │ │ WAL mode │ │
164
+ │ └──────────────────┘ │ │ │
165
+ │ │ ~/.pi/agent/ │ │
166
+ │ │ memory/ │ │
167
+ │ │ memories.db │ │
168
+ │ └────────────────────┘ │
169
+ │ │
170
+ │ @huggingface/transformers │
171
+ │ all-MiniLM-L6-v2 (384 dimensions) │
172
+ │ │
173
+ │ better-sqlite3 + sqlite-vec │
174
+ │ Indexed storage + vector similarity search │
175
+ └──────────────────────────────────────────────────┘
176
+ ```
177
+
178
+ ### ⚡ Performance
179
+
180
+ Benchmarked on Apple Silicon (M-series). Your mileage may vary, but it'll be fast.
181
+
182
+ | Operation | Time | Vibes |
183
+ |-----------|------|-------|
184
+ | Model load (first store) | ~200ms | ☕ One-time cost per session |
185
+ | Store 1 memory (warm) | ~1ms | ⚡ Blink and you'll miss it |
186
+ | Search 100 memories | ~1ms | 🚀 Faster than you can forget |
187
+ | Wakeup L0+L1 | <1ms | 🌅 Instant dawn |
188
+ | Recall L2 (filtered) | <1ms | 🎯 SQL indexes go brrr |
189
+ | Knowledge graph query | <1ms | 🧩 Basically free |
190
+ | Palace graph | <1ms | 🏰 All the tunnels, no waiting |
191
+
192
+ ### 💾 Storage
193
+
194
+ Memories live in a SQLite database at `~/.pi/agent/memory/memories.db`, powered by [sqlite-vec](https://github.com/asg017/sqlite-vec) for vector similarity search. Metadata is indexed (project, topic, timestamp) for fast pre-filtering before vector search kicks in. Deduplication via SHA-256 hash means you can't accidentally remember the same thing twice — unlike that embarrassing story you keep retelling at parties.
195
+
196
+ > **Migrating from v0.1?** If you have an existing `memories.jsonl` file, it's automatically migrated to SQLite on first load. Your old file is renamed to `.bak`. No data lost, no action needed.
197
+
198
+ ---
199
+
200
+ ## 🏰 The Full MemPalace Architecture
201
+
202
+ The original [MemPalace](https://www.mempalace.tech) uses a gorgeous metaphorical architecture — **Wings** (top-level containers), **Rooms** (topics), **Halls** (corridors by memory type), **Closets** (compressed summaries), and **Drawers** (verbatim source files). It runs on Python with ChromaDB and includes AAAK, a custom 30x compression dialect that any LLM can read natively.
203
+
204
+ pi-mempalace faithfully implements the core MemPalace architecture in TypeScript:
205
+
206
+ | MemPalace Concept | pi-mempalace Implementation |
207
+ |---|---|
208
+ | **Wings** (projects/people) | `project` field — auto-detected from git repo |
209
+ | **Rooms** (topics within wings) | `topic` field — set per memory |
210
+ | **Drawers** (verbatim chunks) | 800-char chunks with 100-char overlap, each with its own embedding |
211
+ | **Tunnels** (cross-wing connections) | `memory_graph` discovers shared topics across projects |
212
+ | **4-Layer Stack** | L0 Identity → L1 Essential Story → L2 On-Demand → L3 Deep Search |
213
+ | **Knowledge Graph** | Temporal triples with `valid_from`/`valid_to` — "what was true when?" |
214
+ | **ChromaDB** | SQLite + [sqlite-vec](https://github.com/asg017/sqlite-vec) — same HNSW indexing, no Python |
215
+
216
+ The one thing we deliberately skip is **AAAK compression** — MemPalace's own benchmarks show it drops accuracy from 96.6% to 84.2%. We'll take the storage cost over the precision loss.
217
+
218
+ The soul is the same: **your AI should remember you.**
219
+
220
+ If you want the full palace experience with all its wings and halls and drawers, go check out [mempalace.tech](https://www.mempalace.tech). Milla and Ben built something special.
221
+
222
+ ---
223
+
224
+ ## 📊 Benchmark Validation
225
+
226
+ We reproduce [LongMemEval](https://arxiv.org/abs/2410.10813) — the standard benchmark for AI memory systems — to validate that our implementation matches MemPalace's retrieval quality. The benchmark stores 500 questions, each with ~50 timestamped conversation sessions, and measures whether the correct session appears in the top-K search results.
227
+
228
+ ### Results (Raw Mode — Zero API, Fully Local)
229
+
230
+ | Metric | pi-mempalace | MemPalace (reference) | Delta |
231
+ |--------|-------------|----------------------|-------|
232
+ | **Recall@5** | **95.8%** (479/500) | 96.6% (483/500) | -0.8pp |
233
+ | **Recall@10** | **98.2%** (491/500) | 98.2% (491/500) | **identical** |
234
+ | **NDCG@10** | **0.884** | 0.889 | -0.005 |
235
+
236
+ ### Per Question Type
237
+
238
+ | Question Type | R@5 | R@10 | Questions |
239
+ |--------------|-----|------|-----------|
240
+ | knowledge-update | 🟢 100% | 100% | 78 |
241
+ | multi-session | 🟢 97.7% | 98.5% | 133 |
242
+ | temporal-reasoning | 🟡 94.7% | 99.2% | 133 |
243
+ | single-session-assistant | 🟡 94.6% | 96.4% | 56 |
244
+ | single-session-user | 🟡 92.9% | 95.7% | 70 |
245
+ | single-session-preference | 🟡 90.0% | 96.7% | 30 |
246
+
247
+ The 0.8pp R@5 gap comes from our 800-char chunking (MemPalace stores whole sessions in benchmark mode) and minor differences between sqlite-vec and ChromaDB's HNSW implementations. The weakest categories (temporal, preference) are exactly what MemPalace's hybrid modes address with keyword re-ranking and temporal boosting — features we haven't implemented.
248
+
249
+ ### Run It Yourself
250
+
251
+ ```bash
252
+ # Download the LongMemEval dataset (~277MB)
253
+ curl -fsSL -o benchmarks/data/longmemeval_s_cleaned.json \
254
+ https://huggingface.co/datasets/xiaowu0162/longmemeval-cleaned/resolve/main/longmemeval_s_cleaned.json
255
+
256
+ # Run full benchmark (500 questions, ~4 minutes)
257
+ npx tsx benchmarks/longmemeval_bench.mjs
258
+
259
+ # Quick smoke test (10 questions, ~5 seconds)
260
+ npx tsx benchmarks/longmemeval_bench.mjs --limit 10
261
+
262
+ # Save per-question results
263
+ npx tsx benchmarks/longmemeval_bench.mjs --out benchmarks/results/raw_500.jsonl
264
+ ```
265
+
266
+ ---
267
+
268
+ ## 🤔 Why Not Just Use MemPalace Directly?
269
+
270
+ You absolutely could! MemPalace is great. But if you're already living in the pi ecosystem:
271
+
272
+ - **No Python required** — pi-mempalace is pure TypeScript, runs in-process
273
+ - **Full MemPalace architecture** — 4-layer stack, chunking, palace graph, knowledge graph
274
+ - **SQLite instead of ChromaDB** — one file, no server, native Node.js via better-sqlite3
275
+ - **Palace graph with tunnels** — discover cross-project connections via shared topics
276
+ - **Temporal knowledge graph** — structured facts with time validity ("what was true when?")
277
+ - **Auto-chunking** — long content split into 800-char chunks with overlap, just like MemPalace
278
+ - **Native pi integration** — hooks into pi's extension system, session lifecycle, and TUI
279
+ - **Auto-capture built in** — no manual memory management needed
280
+ - **Wake-up context** — L0 identity + L1 essential story, injected before you even ask
281
+ - **Zero config** — install it and go. It just works.
282
+
283
+ ---
284
+
285
+ ## 📜 License
286
+
287
+ MIT — because memories should be free.
288
+
289
+ ---
290
+
291
+ <p align="center">
292
+ <i>
293
+ "I wanted my AI to remember the way I remember — not just the conclusions, but the journey."
294
+ <br/>
295
+ — The philosophy behind MemPalace, which inspired this project
296
+ </i>
297
+ </p>
298
+
299
+ <p align="center">
300
+ 🏰 Inspired by <a href="https://www.mempalace.tech">MemPalace</a> by Milla Jovovich & Ben Sigman
301
+ <br/>
302
+ 🧠 Built for <a href="https://github.com/badlogic/pi-mono">pi</a> with ❤️ and a fear of forgetting
303
+ </p>