Repository navigation
fix(recall): comprehensive cache invalidation + FTS5 scoring - #854
Merged
Merged
Conversation
Bug #1 (Major): invalidate_namespace() did not flush 'all' namespace entries, causing stale results for cross-namespace queries after any namespace-scoped mutation (remember, forget, delete_tag). Bug #2 (Major): rename_tag() missing cache invalidation entirely. Bug #3 (Major): recall_fts5_only() hardcoded score=1.0 for ALL results, making min_score filter useless. Replaced with min-max normalization of BM25 ranks (0.0..1.0). Bug #4 (Minor): pin/unpin/set_importance/feedback missing invalidation. Added invalidate_cache_for_id() helper. Bug #5 (Minor): consolidate() and dream() delete memories but did not invalidate cache. Added post-mutation flush. Bug #6 (Minor): recompute_importance() did not flush cache. Tests: 432 passed, 0 failed, 24 ignored. Clippy: 0 warnings.
🔍 Cora AI Code ReviewReview powered by cora-code · BYOK · MIT |
3 tasks done
ajianaz
added a commit
that referenced
this pull request
Aug 5, 2026
* fix(recall): normalize FTS5 scores AFTER filtering, not before (#854) Cora review caught: min-max normalization was computed from ALL fts_results before namespace/tag filtering. If the best/worst items get filtered out, surviving scores no longer span 0.0..1.0 correctly. Restructured: filter → collect → compute range → map → take. Tests: 432 passed, 0 failed. * style: cargo fmt --------- Co-authored-by: ajianaz <[email protected]>
This was referenced Aug 5, 2026
ajianaz
added a commit
that referenced
this pull request
Aug 13, 2026
Bug #1 (Major): invalidate_namespace() did not flush 'all' namespace entries, causing stale results for cross-namespace queries after any namespace-scoped mutation (remember, forget, delete_tag). Bug #2 (Major): rename_tag() missing cache invalidation entirely. Bug #3 (Major): recall_fts5_only() hardcoded score=1.0 for ALL results, making min_score filter useless. Replaced with min-max normalization of BM25 ranks (0.0..1.0). Bug #4 (Minor): pin/unpin/set_importance/feedback missing invalidation. Added invalidate_cache_for_id() helper. Bug #5 (Minor): consolidate() and dream() delete memories but did not invalidate cache. Added post-mutation flush. Bug #6 (Minor): recompute_importance() did not flush cache. Tests: 432 passed, 0 failed, 24 ignored. Clippy: 0 warnings. Co-authored-by: ajianaz <[email protected]>
ajianaz
added a commit
that referenced
this pull request
Aug 13, 2026
* fix(recall): normalize FTS5 scores AFTER filtering, not before (#854) Cora review caught: min-max normalization was computed from ALL fts_results before namespace/tag filtering. If the best/worst items get filtered out, surviving scores no longer span 0.0..1.0 correctly. Restructured: filter → collect → compute range → map → take. Tests: 432 passed, 0 failed. * style: cargo fmt --------- Co-authored-by: ajianaz <[email protected]>
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.
What
Comprehensive fix for 6 cache invalidation bugs + FTS5 scoring bug found during audit round 2.
Why
The RecallCache (introduced for performance) had incomplete invalidation coverage — 7 out of 10 mutation operations either skipped cache invalidation entirely or failed to flush cross-namespace ("all") entries. Additionally,
recall_fts5_only()hardcodedscore=1.0for all results, makingmin_scorefiltering useless.Root cause: 67% of bugs stem from incomplete cache invalidation when RecallCache was introduced. The
invalidate_namespace()function itself had a blind spot for "all" entries.How
Bug #1 (Major) —
invalidate_namespaceblind spotrecall_cache.rs:invalidate_namespace("ns1")flushed entries wherenamespace == "ns1"but NOT entries wherenamespace == "all". Any namespace-scoped mutation (remember, forget, delete_tag) left stale cross-namespace query results.Fix: Also flush entries with
namespace == "all".Bug #2 (Major) —
rename_tagmissing invalidationoperations.rs:rename_tag()updated the DB but never invalidated the cache. Renamed tags would show stale FTS5 results indefinitely.Fix: Add
invalidate_namespace()orclear()after rename.Bug #3 (Major) — FTS5 score=1.0
operations.rs:recall_fts5_only()ignored the BM25 rank fromsearch_fts5()and hardcodedscore = 1.0f32for all results. This mademin_scorefiltering completely non-functional and destroyed relevance ranking.Fix: Min-max normalization of BM25 ranks →
((rank - max_rank) / (min_rank - max_rank)).clamp(0.0, 1.0). Single result or tied ranks → 1.0 (guard withEPSILON).Bug #4 (Minor) — pin/unpin/set_importance/feedback
lib.rs: These single-memory mutations affect ranking but did not flush cache.Fix: Added
invalidate_cache_for_id()helper that looks up namespace viaget_by_id(), then callsinvalidate_namespace(). Falls back toclear()on lookup failure.Bug #5 (Minor) — consolidate/dream
consolidate.rs+dream.rs: These operations delete memories but did not invalidate cache.Fix: Post-mutation flush (skip on dry_run for dream).
Bug #6 (Minor) — recompute_importance
lib.rs: Updates all memories but did not flush cache.Fix:
clear()whenupdated > 0.Testing
cargo test --workspacepasses — 432 passed, 0 failed, 24 ignoredcargo clippy --workspace --all-targets -- -D warningspasses — 0 warningsAffected subsystem: RecallCache (load-bearing), FTS5 search scoring
Related Issues
Closes #849
Checklist