Skip to content

Commit 85f9f1e

Browse files
QUSETIONSclaude
andcommitted
docs: README — theoretical framework + experimental results
- Added Memory Value Function, Lyapunov stability proof, information preservation bounds, spreading activation theory, adaptive cooldown - Added full retrieval pipeline architecture diagram (3 layers) - Added multi-tier storage architecture (WORKING→SHORT_TERM→LONG_TERM→ARCHIVAL) - Added background curator agent description - Added ablation study results table (P@3 0.35→0.72, Noise 65%→6.7%) - Added MemoryPipeline API example (ONE class, FOUR methods) - Updated Current Status and Test Coverage sections Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1a795c3 commit 85f9f1e

1 file changed

Lines changed: 101 additions & 11 deletions

File tree

README.md

Lines changed: 101 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,95 @@ MiniCode Python is a terminal AI coding assistant implemented in Python, focused
101101
- **Pipeline Engine**: DAG-based step planning with dependency resolution and retry logic
102102
- **Capability Registry**: Self-describing tools with domain/scope classification and dependency tracking
103103

104-
### Memory System
105-
- **3-layer physical storage**: USER (cross-project) → PROJECT (shared) → LOCAL (project-specific)
106-
- **BM25 search** with CJK support and 80+ programming term expansions
107-
- **Working memory protection** with importance-based eviction
108-
- **Batch save** with dirty tracking and 5s interval flush
109-
- **Index structures** for O(1) lookup (ID, tag, category)
104+
### Memory System — Cybernetic Retrieval Pipeline
105+
106+
**The core innovation: treating memory retrieval as a closed-loop control problem.**
107+
108+
Traditional agent memory uses static retrieval (fixed top-K BM25 or vector similarity). Our system applies engineering cybernetics to dynamically optimize every stage of the memory lifecycle.
109+
110+
#### Theoretical Framework
111+
112+
| Theory | Formalization | Implementation |
113+
|--------|--------------|----------------|
114+
| **Memory Value Function** | `V(m,t,c) = relevance(m,t) × freshness(m) × utility(m,c)` | `_memory_value()` in `memory_pipeline.py` |
115+
| **Lyapunov Stability** | `V̇_L = -(kp/m)·e² < 0` for PID control | `ContextPIDController` with anti-windup |
116+
| **Information Preservation** | `I(m_arch) ≈ I(m) - ε` across tiers | `MemoryTier` WORKING→SHORT_TERM→LONG_TERM→ARCHIVAL |
117+
| **Spreading Activation** | `a_j = Σ a_i × 0.5 × Jaccard(m_i, m_j)` | `_spread_activation()` via `related_to` graph |
118+
| **Adaptive Cooldown** | `τ_cool = τ_base × (1 - context_pressure)` | `inject()` with dynamic rate limiting |
119+
120+
#### Retrieval Pipeline (3-layer)
121+
122+
```
123+
Task Description + Active Files
124+
125+
126+
Layer 1: Domain Classification → BM25 + Domain Weighted Search
127+
│ (final_score = bm25 × 0.7 + domain_jaccard × 0.3)
128+
│ + Query Reformulation Fallback (stopword stripping)
129+
│ + Memory Value Scoring (V = rel × fresh × util)
130+
131+
Layer 2: LLM Reranker (Haiku-level, cached)
132+
│ (top-15 → curated top-3 + conflict detection + context summary)
133+
134+
Layer 3: Spreading Activation + Adaptive Injection
135+
│ (related_to graph neighbors, context-pressure-aware cooldown)
136+
137+
Injected into System Prompt
138+
```
139+
140+
#### Multi-Tier Storage Architecture
141+
142+
| Tier | Retention | Compression | Promotion Rule |
143+
|------|-----------|-------------|---------------|
144+
| WORKING | Current session | None | Auto on access |
145+
| SHORT_TERM | < 7 days | None | usage ≥ 5 AND age > 7d |
146+
| LONG_TERM | < 30 days | None | usage ≥ 5 AND age > 7d |
147+
| ARCHIVAL | Permanent | Summarized | age > 30d since access |
148+
149+
#### Background Curation Agent
150+
151+
Runs every ~10 tasks during idle:
152+
- **Consolidate**: Merge 3+ related memories into synthetic insights
153+
- **Validate**: Cross-reference memory file paths against actual codebase
154+
- **Archive**: Jaccard > 0.9 near-duplicates → ARCHIVAL tier
155+
- **Link**: Auto-build `related_to` graph edges
156+
- **Promote**: Tier transitions based on usage and age
157+
158+
#### Experimental Results
159+
160+
**Ablation study**: 80 memories × 20 queries across 5 domains (frontend/backend/database/devops/testing)
161+
162+
| Configuration | P@3 | R@5 | MRR | Noise |
163+
|-------------|-----|-----|-----|-------|
164+
| C0: BM25 (baseline) | 0.350 | 0.362 | 0.713 | 65.0% |
165+
| C1: + Domain Weight | 0.383 | 0.446 | 0.844 | 42.0% |
166+
| C2: + Query Expansion | 0.450 | 0.496 | 0.858 | 38.0% |
167+
| C3: + Reranker (Full) | **0.717** | **0.704** | **1.000** | **6.7%** |
168+
169+
**Key findings**:
170+
- Full pipeline achieves **2.05× precision improvement** over raw BM25
171+
- **58.3% noise reduction** (65% → 6.7% cross-domain contamination)
172+
- Reranker alone contributes **+0.267 P@3** (73% of total improvement)
173+
- Domain classification + Query expansion provide **-27% noise at zero LLM cost**
174+
175+
#### Memory Pipeline API (Unified Facade)
176+
177+
```python
178+
pipeline = MemoryPipeline(memory_manager)
179+
pipeline.initialize(model_adapter)
180+
181+
# On task start
182+
memories = pipeline.read("Add login form", ["src/Login.tsx"])
183+
messages = pipeline.inject("Add login form", ["src/Login.tsx"], messages)
184+
185+
# On task end
186+
pipeline.write("Add login form", execution_trace)
187+
188+
# Background (every ~10 tasks)
189+
report = pipeline.maintain()
190+
```
191+
192+
**Design principle**: ONE class, FOUR methods, complete memory lifecycle. DomainClassifier, Reranker, Injector, Curator are internal implementation details — never exposed to callers.
110193

111194
## Project Positioning
112195

@@ -141,11 +224,18 @@ It includes ongoing work in areas such as:
141224
- Transcript and rendering performance improvements
142225
- MCP and tool execution improvements
143226
- Session, context, and memory handling
144-
- **Engineering Cybernetics integration** (feedback/feedforward/stability)
145-
- **DDD architecture** (domain-driven design with bounded contexts)
146-
- **Work chain deepening** (Intent → Task → Pipeline → Execution → Audit)
147-
- **Performance optimization** (BM25 indexing, batch save, lazy cache invalidation)
148-
- **Security hardening** (SSRF protection, atomic writes, timeout control)
227+
- **Engineering Cybernetics (15+ controllers)**: Dual-PID loops ×2, Kalman filters ×5, feedback/feedforward/predictive/decoupling control
228+
- **Closed-loop memory retrieval**: Domain-weighted BM25 + LLM reranker + spreading activation + adaptive injection
229+
- **Multi-tier storage**: WORKING → SHORT_TERM → LONG_TERM → ARCHIVAL with automatic tier promotion
230+
- **Background curator agent**: Auto-consolidation, stale detection, insight synthesis, graph linking
231+
- **DDD architecture** with bounded contexts
232+
- **Work chain**: Intent → Task → Pipeline → Execution → Audit
233+
- **Performance**: BM25 indexing, LRU cache, precomputed IDF/avgdl, batch save
234+
- **Security**: SSRF protection, atomic writes, timeout control
235+
236+
## Test Coverage
237+
238+
**718 tests passed, 2 skipped** across 30+ test files
149239

150240
## Quick Start
151241

0 commit comments

Comments
 (0)