feat(agent-memory): Phase 2 — recall() ranking#249
Open
jamby77 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 50a2011. Configure here.
50a2011 to
13a2279
Compare
- Pure compositeScore: weighted similarity + half-life recency + importance (true half-life: 0.5 at one halfLifeSeconds); add similarityFromDistance() - buildRecallQuery: KNN FT.SEARCH with scope + AND-tag TAG filters (escaped) - parseMemoryItem: FT.SEARCH hash -> MemoryItem - MemoryStore.recall(): embed query, widened KNN (k*4), distance-threshold filter, composite re-rank, sort desc, cap at k - Constructor recall defaults: threshold 0.25, weights .6/.25/.15, half-life 7d - Export recall types (MemoryItem, RecallOptions, MemoryHit, RecallWeights)
fe9da3d to
b433d60
Compare
13a2279 to
df17cbd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Agent Memory — Phase 2:
recall()rankingStacked on #248 (Phase 1). The highest-value TDD target — composite-score math first, then KNN wiring.
What's new
compositeScore=w.similarity·similarity + w.recency·recency + w.importance·importance, whererecency = exp(-ln2·age/halfLife)(true half-life: 0.5 at one half-life) andsimilarity = 1 − distance/2. Table-driven tests (decay-at-half-life, ranking, recency-promotion, importance tie-break).buildRecallQuery— KNNFT.SEARCHwith scope (threadId/agentId/namespace) + AND-tag TAG filters (escaped), or*when unfiltered.parseMemoryItem— FT.SEARCH hash →MemoryItem.MemoryStore.recall()— embed query → widened KNN (k*4) → distance-threshold filter → composite re-rank → sort desc → cap atk. Constructor recall defaults: threshold0.25, weights.6/.25/.15, half-life7d.Tests
20 unit tests;
tsc --noEmit+ prettier clean.Review-driven change
__scoreyieldedNaN, which bypassed the> thresholdguard and produced aNaNscore; now filtered withNumber.isFinite.Notes / deliberate divergences
MemoryHit.similarityholds the cosine distance (0..2, lower=closer) — per spec (§"same convention as semantic-cache"), not a 0..1 score.exp(-ln2·age/halfLife), 0.5 at one half-life) — the spec's literalexp(-age/halfLife)is inconsistent with thehalfLifeSecondsname and the plan's test; impl follows the plan + field name.reinforce(RecallOptions) is Phase 4; not implemented here.Next
Phase 3 (
forget/forgetByScope).Note
Medium Risk
New retrieval path depends on Valkey FT.SEARCH/KNN and embedding consistency; ranking defaults affect which memories agents see, but changes are localized to agent-memory with solid unit coverage.
Overview
Adds
MemoryStore.recall()so agents can retrieve stored memories by semantic query, with optional scope (threadId/agentId/namespace) and tag filters.The flow embeds the query, runs a widened KNN
FT.SEARCH(k×4), filters by cosine distance threshold, then re-ranks with a weighted composite score (similarity, half-life recency, importance). Constructor defaults cover threshold0.25, weights.6/.25/.15, and a 7-day half-life;RecallOptionscan overridek, threshold, tags, and weights.New helpers
buildRecallQuery,parseMemoryItem, andcompositeScore/similarityFromDistancewire Valkey search and ranking;MemoryItem,MemoryHit, andRecallOptionsare exported. Invalid or missing KNN__scorevalues and non-finite composite scores are dropped so bad index rows do not leak into results.MemoryHit.similaritykeeps raw cosine distance (lower = closer), not a 0–1 score.Reviewed by Cursor Bugbot for commit df17cbd. Bugbot is set up for automated code reviews on this repo. Configure here.