You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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_start happens before the response, so it can't determine if memory was actually used
agent_end has full event.messages — can compare recall results against the final response
No new lifecycle triggers needed; just add a post-processing step to the existing agent_end flow
No changes needed to
decay-engine.ts — it already reads importance; changes propagate automatically
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"
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)
access-tracker.tslog1p(effectiveAccessCount)decay-engine.tsimportancemodulates half-life:effectiveHL = halfLife × exp(1.5 × importance)tier-manager.tsretriever.tsapplyImportanceWeight():score *= (0.7 + 0.3 × importance)last_confirmed_use_atfieldsmart-metadata.tsbad_recall_countfieldsmart-metadata.tsreflection-store.tsquality × logistic(age) × baseWeightalready implements dynamic decayCritical gap
The system has frequency-based reinforcement but no feedback-based importance adjustment. The
importancefield is written once at store time and never updated based on usage quality.Proposal A — Dynamic Importance (Recommended)
Goal: Make
importancedynamic — not a one-time write, but adjusted after each recall based on usage quality.Recommended feedback signals
agent_end— compare recall results vs final responseimportance += 0.05, cap at 1.0importance += 0.15, cap at 1.0importance -= 0.10, floor at 0.1importance -= 0.03Why
agent_endhook is the right placebefore_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 responseagent_endflowNo 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 conflictingProposal 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: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:vectorSearch(text, topK=2, scope=same)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
Proposed Implementation Order
agent_endfeedback loop (lowest risk, highest clarity)last_confirmed_use_atandbad_recall_counttriggersQuestions for the Author
scopefilter, or should it cross scopes?Related: #246