Skip to content

Commit d4fec9e

Browse files
Grivnclaude
andcommitted
docs: align section numbers with file numbers across all design docs
Renumber all headings so file 0N uses section N.x consistently: - 03: 4.x → 3.4-3.6 - 04: 5.x → 4.x, # Graph-LLM → ## 4.6 with ### subsections - 05: 6/7/8 → 5.1/5.2/5.3, remove sub-numbering on ### - 06: 9/10 → 6.1-6.5, remove sub-numbering on ### - 07: 11.x → 7.x - 08: 12/13 → 8.1/8.2 - ZH: fix ### → ## heading levels for 01/02/06/07 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7d0501d commit d4fec9e

14 files changed

Lines changed: 105 additions & 109 deletions

docs/design/03-concepts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ oplog (
9393

9494
---
9595

96-
## 4. System Architecture
96+
## 3.4 System Architecture
9797

9898
Mnemon's architecture is divided into five layers:
9999

@@ -178,7 +178,7 @@ mnemon/
178178
└── Makefile # Build, install, test
179179
```
180180

181-
## 4.1 Data Directory Layout
181+
## 3.5 Data Directory Layout
182182

183183
```
184184
~/.mnemon/
@@ -197,7 +197,7 @@ mnemon/
197197

198198
**Isolation boundary**: Each store contains an independent `mnemon.db` — insights, edges, and oplog are fully isolated. Prompt files (`guide.md`, `skill.md`) are shared — behavioral rules are universal, memory data is private.
199199

200-
## 4.2 Store Isolation
200+
## 3.6 Store Isolation
201201

202202
Mnemon supports named stores for lightweight data isolation between different agents, projects, or scenarios.
203203

docs/design/04-graph-model.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Mnemon implements four graphs, each capturing one dimension of relationships:
1010

1111
![MAGMA Four-Graph Model](../diagrams/04-magma-four-graph.jpg)
1212

13-
## 5.1 Temporal Graph
13+
## 4.1 Temporal Graph
1414

1515
**Purpose**: Capture the chronological order of memories, building a temporal skeleton of the knowledge flow.
1616

@@ -30,7 +30,7 @@ Insight A (2h ago) ←── backbone ──→ Insight B (1h ago) ←── bac
3030

3131
**Metadata**: `{"sub_type": "backbone"|"proximity", "hours_diff": "2.34"}`
3232

33-
## 5.2 Entity Graph
33+
## 4.2 Entity Graph
3434

3535
**Purpose**: Link insights that mention the same entities.
3636

@@ -50,7 +50,7 @@ Insight A ←── entity ──→ Insight B ←── entity ──→ Insigh
5050

5151
**Metadata**: `{"entity": "Qdrant"}`
5252

53-
## 5.3 Causal Graph
53+
## 4.3 Causal Graph
5454

5555
**Purpose**: Capture the reasons behind decisions and cause-effect relationships.
5656

@@ -73,7 +73,7 @@ Insight A ──── causal ────→ Insight B
7373

7474
This is a quintessential example of the LLM-Supervised philosophy: Binary handles low-cost candidate discovery (regex + token overlap), while the LLM handles high-value causal judgment.
7575

76-
## 5.4 Semantic Graph
76+
## 4.4 Semantic Graph
7777

7878
**Purpose**: Connect semantically similar insights based on meaning.
7979

@@ -94,7 +94,7 @@ Insight C ←── semantic (LLM review) ──→ Insight D
9494
cos=0.65, manually linked after LLM judged "related"
9595
```
9696

97-
## 5.5 Four-Graph Synergy: Intent-Adaptive Weighting
97+
## 4.5 Four-Graph Synergy: Intent-Adaptive Weighting
9898

9999
Different query intents activate different graph traversal weights:
100100

@@ -109,11 +109,11 @@ When asking "why was SQLite chosen," the causal edge weight is highest, so the s
109109

110110
---
111111

112-
# Graph-LLM Theoretical Foundations
112+
## 4.6 Graph-LLM Theoretical Foundations
113113

114114
The following sections establish the theoretical basis for why graph databases are the native storage model for LLMs, and why `remember / link / recall` constitutes a universal protocol for agent memory systems.
115115

116-
## Structural Isomorphism
116+
### Structural Isomorphism
117117

118118
LLM attention, graph data models, and natural language all describe the same thing: weighted associations between entities.
119119

@@ -125,7 +125,7 @@ Natural Language: subject ←predicate→ object
125125

126126
Relational databases force network relationships into tables. Vector databases retain only one relationship type (similarity). Only graphs preserve full relational semantics.
127127

128-
## The Three-Step Paradigm: Extract → Candidate → Associate
128+
### The Three-Step Paradigm: Extract → Candidate → Associate
129129

130130
Graph construction engines universally decompose into three steps:
131131

@@ -147,7 +147,7 @@ The three-step model is a spectrum — the more semantically rich the data model
147147
| **Vector** | Text → embedding | ANN dedup | Metadata only (single relation type) |
148148
| **KV** | Key:value | Key existence check | _(nearly none)_ |
149149

150-
## Read-Write Symmetry (Unique to Graphs)
150+
### Read-Write Symmetry (Unique to Graphs)
151151

152152
On graph databases, the read and write paths mirror each other using the same three-step model:
153153

@@ -169,7 +169,7 @@ This symmetry does NOT hold for other database types — relational write is sch
169169

170170
**Implication**: An LLM needs to master only one cognitive pattern to handle both graph reads and writes.
171171

172-
## From the LLM Perspective: Query → Reason
172+
### From the LLM Perspective: Query → Reason
173173

174174
Regardless of the underlying database, LLM interactions on the read side collapse to two steps:
175175

@@ -183,7 +183,7 @@ This is the RAG paradigm applied to any data store. The variation lies in the tr
183183
- **Text-to-Cypher**: must understand graph structure
184184
- **Text-to-Vector**: encode only, near-zero translation
185185

186-
## Other Storage Types as Degenerate Graphs
186+
### Other Storage Types as Degenerate Graphs
187187

188188
| Storage Type | What's Lost Compared to Graph |
189189
|-------------|------------------------------|
@@ -194,7 +194,7 @@ This is the RAG paradigm applied to any data store. The variation lies in the tr
194194

195195
A vector database can answer "what is **similar** to what" but cannot answer "what **caused** what" or "what **belongs to** what". Graphs can.
196196

197-
## remember / link / recall as Universal Algebra
197+
### remember / link / recall as Universal Algebra
198198

199199
The three-step paradigm (Extract → Candidate → Associate) maps directly to three primitive operations: **remember**, **link**, **recall**. This is not an implementation detail of mnemon — it is the minimal complete interface for any agent memory system.
200200

@@ -238,7 +238,7 @@ Native RAG link absent entirely
238238

239239
The more degenerate the `link` operation, the more burden falls on the LLM at recall time to infer associations that were never stored.
240240

241-
## The Protocol Gap: LLM ↔ Database
241+
### The Protocol Gap: LLM ↔ Database
242242

243243
### The Missing Layer
244244

@@ -349,7 +349,7 @@ MemGPT──┘ │── SQLite adapter (mnemon current
349349
- **Not competing with Mem0** on product features (it is a product bound to its implementation)
350350
- **Analogous to MCP** — MCP connected LLMs to the tool ecosystem; this protocol connects LLMs to the database ecosystem
351351

352-
## Academic Landscape and Positioning
352+
### Academic Landscape and Positioning
353353

354354
### Prior Art Assessment
355355

@@ -401,7 +401,7 @@ Original contributions (no prior formulation found)
401401
- Transformers are Graph Neural Networks (arXiv 2506.22084, Jun 2025)
402402
- A Generalization of Transformer Networks to Graphs (arXiv 2012.09699, 2020)
403403

404-
## Validation: mnemon Architecture
404+
### Validation: mnemon Architecture
405405

406406
mnemon's design directly reflects these insights:
407407

@@ -413,7 +413,7 @@ recall → Extract + Candidate + Associate (intent detection → multi-signal
413413

414414
Five edge types preserve five distinct relational semantics. Degenerating to pure vector retrieval would retain only `semantic` — losing ~80% of relational information. MAGMA ablation studies confirm: removing causal edges drops accuracy 3-5%, removing temporal edges drops it further.
415415

416-
## Summary
416+
### Summary
417417

418418
- **Extract → Candidate → Associate** is the universal paradigm for graph construction engines
419419
- This three-step model achieves its **most complete expression** on graphs and degenerates toward KV

docs/design/05-pipelines.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
---
66

7-
## 6. Write Pipeline: Remember
7+
## 5.1 Write Pipeline: Remember
88

99
`mnemon remember` is the core command for writing memories. It includes a built-in diff step that automatically detects duplicates and conflicts before storage. The write transaction executes atomically within a single SQLite transaction.
1010

1111
![Remember Pipeline](../diagrams/02-remember-pipeline.jpg)
1212

13-
### 6.1 Detailed Flow
13+
### Detailed Flow
1414

1515
```
1616
mnemon remember "Chose Qdrant as the vector database" \
@@ -84,13 +84,13 @@ After receiving this output, the LLM can evaluate candidates and establish edges
8484

8585
---
8686

87-
## 7. Read Pipeline: Smart Recall (Default)
87+
## 5.2 Read Pipeline: Smart Recall
8888

8989
`mnemon recall` is Mnemon's core retrieval algorithm. Smart recall is the default mode for all queries. It combines intent detection, multi-signal anchor selection, Beam Search graph traversal, and multi-factor re-ranking to achieve intent-aware graph-enhanced retrieval. Use `--basic` for legacy SQL LIKE fallback.
9090

9191
![Smart Recall Pipeline](../diagrams/03-smart-recall-pipeline.jpg)
9292

93-
### 7.1 Step 1: Intent Detection
93+
### Step 1: Intent Detection
9494

9595
Query intent is automatically identified via regex matching:
9696

@@ -103,7 +103,7 @@ Query intent is automatically identified via regex matching:
103103

104104
Supports the `--intent` flag to manually override automatic detection.
105105

106-
### 7.2 Step 2: Multi-Signal Anchor Selection (RRF Fusion)
106+
### Step 2: Multi-Signal Anchor Selection (RRF Fusion)
107107

108108
Multiple signals run in parallel and are merged via Reciprocal Rank Fusion:
109109

@@ -119,7 +119,7 @@ RRF Score = Σ 1 / (k + rank_i + 1) (k = 60)
119119

120120
Each insight may rank differently across signals; RRF fusion produces a robust composite ranking.
121121

122-
### 7.3 Step 3: Beam Search Graph Traversal
122+
### Step 3: Beam Search Graph Traversal
123123

124124
Starting from each anchor, Beam Search is performed across the four graphs:
125125

@@ -153,7 +153,7 @@ for each anchor:
153153

154154
WHY queries use a wider beam and deeper traversal because causal chains typically span multiple hops.
155155

156-
### 7.4 Step 4: Multi-Factor Re-Ranking
156+
### Step 4: Multi-Factor Re-Ranking
157157

158158
For all collected candidates, a four-dimensional score is computed and combined via weighted sum:
159159

@@ -175,11 +175,11 @@ Weights vary by intent:
175175
| ENTITY | 0.20 | **0.40** | 0.20 | 0.20 |
176176
| GENERAL | 0.25 | 0.25 | 0.25 | 0.25 |
177177

178-
### 7.5 Step 5: WHY Post-Processing — Causal Topological Sort
178+
### Step 5: WHY Post-Processing — Causal Topological Sort
179179

180180
If the intent is WHY, an additional topological sort using Kahn's algorithm is performed: results are arranged along causal edges so that **causes come first, effects follow**.
181181

182-
### 7.6 Signal Transparency
182+
### Signal Transparency
183183

184184
Each retrieval result includes a detailed signal breakdown:
185185

@@ -202,7 +202,7 @@ This is a unique innovation in Mnemon: **exposing the retrieval pipeline's inter
202202

203203
---
204204

205-
## 8. Deduplication & Conflict Detection: Diff
205+
## 5.3 Deduplication & Conflict Detection: Diff
206206

207207
![Diff & Dedup Pipeline](../diagrams/07-diff-dedup-pipeline.jpg)
208208

@@ -221,7 +221,7 @@ When `remember` is called, the built-in diff runs before the transaction:
221221

222222
The `--no-diff` flag disables this check for cases where the caller wants unconditional insertion.
223223

224-
### 8.1 Typical Workflow
224+
### Typical Workflow
225225

226226
A single `remember` call handles everything:
227227

docs/design/06-lifecycle.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Mnemon is not an append-only system. Effective memory management requires import
88

99
![Lifecycle & Retention](../diagrams/06-lifecycle-retention.jpg)
1010

11-
## 9.1 Effective Importance (EI)
11+
## 6.1 Effective Importance (EI)
1212

1313
EI combines base importance, access frequency, time decay, and graph connectivity:
1414

@@ -27,13 +27,13 @@ Interpretation:
2727
- **Long period without access** -> exponential decay (halves every 30 days)
2828
- **Rich graph connections** -> indicates relevance to other knowledge, bonus applied
2929

30-
## 9.2 Immunity Rules
30+
## 6.2 Immunity Rules
3131

3232
The following insights are exempt from automatic cleanup:
3333
- `importance >= 4` (high-value memories)
3434
- `access_count >= 3` (frequently retrieved)
3535

36-
## 9.3 Auto-Pruning
36+
## 6.3 Auto-Pruning
3737

3838
Triggered when the total number of active insights exceeds **1000**:
3939

@@ -43,7 +43,7 @@ Triggered when the total number of active insights exceeds **1000**:
4343
4. Soft-delete (set `deleted_at`)
4444
5. Cascade-delete related edges
4545

46-
## 9.4 GC Command
46+
## 6.4 GC Command
4747

4848
Manual lifecycle management tool:
4949

@@ -57,11 +57,11 @@ mnemon gc --keep <id>
5757

5858
---
5959

60-
## 10. Embedding Support
60+
## 6.5 Embedding Support
6161

6262
Embedding vectors are an optional enhancement. Without embeddings, Mnemon operates entirely on keywords and graph structure; with embeddings, semantic retrieval capabilities are significantly enhanced.
6363

64-
### 10.1 Ollama Integration
64+
### Ollama Integration
6565

6666
Via the local Ollama service (no external API required):
6767

@@ -75,11 +75,11 @@ Mnemon ──HTTP──→ Ollama (localhost:11434)
7575
- **Graceful degradation**: Automatically falls back to token overlap when Ollama is unavailable
7676
- **Zero new dependencies**: Pure stdlib `net/http`
7777

78-
### 10.2 Vector Storage
78+
### Vector Storage
7979

8080
Vectors are serialized as little-endian float64 BLOBs stored in the `insights.embedding` column (768 x 8 = 6144 bytes/insight).
8181

82-
### 10.3 Usage Scenarios
82+
### Usage Scenarios
8383

8484
| Scenario | Without Embedding | With Embedding |
8585
|----------|------------------|----------------|
@@ -88,7 +88,7 @@ Vectors are serialized as little-endian float64 BLOBs stored in the `insights.em
8888
| recall -> traversal | Pure structural score | Structural + semantic similarity |
8989
| recall -> re-ranking | KW + Entity + Graph | KW + Entity + Similarity + Graph |
9090

91-
### 10.4 Management Commands
91+
### Management Commands
9292

9393
```bash
9494
ollama pull nomic-embed-text # Install the model

docs/design/07-integration.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Mnemon integrates with LLM CLIs through lifecycle hooks, a skill file, and a behavioral guide. Claude Code's [hook system](https://docs.anthropic.com/en/docs/claude-code/hooks) is the reference implementation — all components are deployed automatically via `mnemon setup`.
1010

11-
## 11.1 Integration Architecture
11+
## 7.1 Integration Architecture
1212

1313
Four hooks drive the memory lifecycle:
1414

@@ -46,7 +46,7 @@ Three layers work together:
4646
| **Skill** | `SKILL.md` — command reference in Claude Code skill format | `.claude/skills/mnemon/` | Teaches the LLM *how* to use mnemon commands |
4747
| **Guide** | `guide.md` — detailed execution manual for recall, remember, and delegation | `~/.mnemon/prompt/` | Teaches the LLM *when* to recall, *what* to remember, and *how* to delegate |
4848

49-
## 11.2 Hook Details
49+
## 7.2 Hook Details
5050

5151
Claude Code fires hooks at specific lifecycle events. Mnemon registers up to four, each with a distinct role in the memory lifecycle:
5252

@@ -97,7 +97,7 @@ Fires before context window compression. Instructs the agent to extract the most
9797
echo "[mnemon] Context compaction starting. Review this session and remember the most valuable insights (up to 5) before context is compressed. Delegate to Task sub-agents now."
9898
```
9999

100-
## 11.3 Automated Setup
100+
## 7.3 Automated Setup
101101

102102
`mnemon setup` handles all deployment automatically:
103103

@@ -142,7 +142,7 @@ Key setup options:
142142

143143
The Prime hook is always installed. Remind, Nudge, and Compact hooks are optional (Remind and Nudge enabled by default).
144144

145-
## 11.4 Sub-Agent Delegation
145+
## 7.4 Sub-Agent Delegation
146146

147147
Memory writes don't happen in the main conversation. Instead, the host LLM delegates to a lightweight sub-agent:
148148

@@ -174,7 +174,7 @@ This separation means:
174174
- **Context isolation**: Memory processing doesn't pollute the main conversation context
175175
- **Model efficiency**: Sonnet handles routine execution while Opus focuses on high-level decisions
176176

177-
## 11.5 Adapting to Other LLM CLIs
177+
## 7.5 Adapting to Other LLM CLIs
178178

179179
For CLIs with hook support, replicate the Claude Code pattern: register lifecycle hooks that call mnemon commands, deploy the skill file, and provide the behavioral guide.
180180

docs/design/08-decisions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
---
66

7-
## 12. Design Decisions & Trade-offs
7+
## 8.1 Design Decisions & Trade-offs
88

99
### Why LLM-Supervised Instead of an Embedded LLM?
1010

@@ -51,7 +51,7 @@ Mnemon retains MAGMA's **architectural skeleton** (four-graph separation, intent
5151

5252
---
5353

54-
## 13. Future Direction
54+
## 8.2 Future Direction
5555

5656
The [two-layer architecture](02-philosophy.md#23-memory-gateway-protocol-not-database) has achieved agent-side pluggability — any LLM CLI can interact with Mnemon through the protocol surface today. The remaining work is on the other side.
5757

0 commit comments

Comments
 (0)