-
Notifications
You must be signed in to change notification settings - Fork 639
[RFC] Proposal A & B Implementation Analysis #445
Description
Proposal A & B Analysis — Why C is Excluded
Context
Following up on #246. I've done a deep-dive analysis of the memory-lancedb-pro codebase to determine the best approach for implementing Proposal A and B.
Key Findings
Existing systems (already in place)
| Mechanism | File | What it does |
|---|---|---|
| Frequency reinforcement | access-tracker.ts |
High access count → longer half-life (up to 3x), via log1p(effectiveAccessCount) |
| Weibull decay | decay-engine.ts |
importance modulates half-life: effectiveHL = halfLife × exp(1.5 × importance) |
| Tier promotion | tier-manager.ts |
Core (β=0.8, slowest decay) / Working / Peripheral (β=1.3, fastest) |
| Importance weight in recall | retriever.ts |
applyImportanceWeight(): score *= (0.7 + 0.3 × importance) |
last_confirmed_use_at field |
smart-metadata.ts |
Field exists but NOT actively used in decay/boost calculations |
bad_recall_count field |
smart-metadata.ts |
Field exists but NOT actively triggered |
| Reflection quality weighting | reflection-store.ts |
quality × logistic(age) × baseWeight already implements dynamic decay |
Critical gap
The system has frequency-based reinforcement but no feedback-based importance adjustment. The importance field is written once at store time and never updated based on usage quality.
Proposal A — Dynamic Importance (Recommended)
Goal: Make importance dynamic — not a one-time write, but adjusted after each recall based on usage quality.
Recommended feedback signals
| Signal | When to capture | Adjustment |
|---|---|---|
| Memory was recalled AND used in response | agent_end — compare recall results vs final response |
importance += 0.05, cap at 1.0 |
| User explicitly confirmed correctness | User says "correct"/"yes"/"right" | importance += 0.15, cap at 1.0 |
| User explicitly marked as wrong | User says "no"/"wrong"/"not right" | importance -= 0.10, floor at 0.1 |
| Recalled but never used (2+ consecutive times) | Next recall cycle check | importance -= 0.03 |
| Long unused (>30 days) | Decay naturally handles this | No additional logic needed |
Why agent_end hook is the right place
before_agent_starthappens before the response, so it can't determine if memory was actually usedagent_endhas fullevent.messages— can compare recall results against the final response- No new lifecycle triggers needed; just add a post-processing step to the existing
agent_endflow
No changes needed to
decay-engine.ts— it already readsimportance; changes propagate automaticallytier-manager.ts— Core promotion requiresimportance >= 0.8; dynamic importance naturally triggers/deters promotionsaccess-tracker.ts— frequency tracking and importance adjustment are complementary, not conflicting
Proposal B — Attention-Like Neighbor Enrichment (Recommended)
Goal: When a memory is recalled, proactively find its "neighbor" memories and bring them into context too.
Recommended path: B-1 (Reflection-focused, lower risk)
Reflection already has a neighbor-modeling mechanism in loadAgentReflectionSlicesFromEntries(). Extend it:
loadAgentReflectionSlicesFromEntries() → N results
→ For each result: bm25Search(text, topK=2, scope=same)
→ Merge + deduplicate
→ Output (originals + neighbors)
Pros: Contained within reflection-store.ts, doesn't affect main retrieval latency.
Cons: Only affects reflection memories, not the main memories table.
B-2 (Full retrieval, if B-1 proves valuable)
In retriever.ts, after MMR diversity and before returning results:
- For each recalled memory, do one more
vectorSearch(text, topK=2, scope=same) - Merge neighbors, re-sort by similarity + importance
- Cap: max 2 neighbors per recalled memory, total output cap 20 entries
Note: MMR diversity and neighbor enrichment may conflict — MMR pushes similar items later, neighbor enrichment brings them in. Need to adjust MMR order if implementing B-2.
Why Proposal C is Excluded
| Concern | Reason |
|---|---|
| Classification accuracy | No session-level domain classifier exists; building one adds latency and can degrade results if wrong |
| Wrong classification cost | If the domain is misclassified, the wrong memories get boosted and right ones get diluted |
| A + B already covers the main need | A makes important memories last longer; B enriches context. C's benefit is unproven for this use case |
| Maturity | No user feedback indicating "context-aware recall is broken" |
Proposed Implementation Order
- Proposal A Phase 1 — Add
agent_endfeedback loop (lowest risk, highest clarity) - Proposal B Path B-1 — Neighbor enrichment in reflection recall
- Proposal A Phase 2 — Wire up
last_confirmed_use_atandbad_recall_counttriggers - Proposal B Path B-2 — Main retrieval neighbor enrichment (if B-1 proves valuable)
Questions for the Author
- Does the feedback signal design (recall → used in response → importance boost) match your intent in Feature Request: Dynamic Importance Learning & Memory Attention Network #246?
- For Proposal B — should neighbor enrichment be scoped to the same
scopefilter, or should it cross scopes? - Is there a specific use case driving Proposal C that we should reconsider for?
Related: #246