Repository navigation
fix(recall): report similarity for memories in unified search, not RRF rank - #831
Merged
ajianaz merged 1 commit intoAug 3, 2026
Conversation
themiguelamador
force-pushed
the
fix/unified-recall-reports-rrf-rank-as-score
branch
from
August 2, 2026 23:55
1b35228 to
24255aa
Compare
…F rank
`recall_unified_all` merges memory and document hits with RRF, then reports
`rrf_sum / (1/(k+1))` as the result score. When a result appears in only one of
the two lists — every result in any store without documents — that sum is
`1/(k+1+rank)`, so the reported score collapses to `(k+1)/(k+1+rank)`: a pure
function of rank, with the cosine similarity discarded.
Every query therefore returns the identical score sequence 1.000, 0.9839,
0.9683, 0.9531 … regardless of what it matched, or whether it matched anything:
uteke recall "purple giraffe tax law sonata"
1. (score: 1.000) <arbitrary memory>
2. (score: 0.984) <arbitrary memory>
Two consequences:
1. `min_score` cannot filter. It is applied to the rank number, so at the
documented 0.30 default a result must rank ~140th to be excluded. This
silently defeats the configurable similarity threshold added in codecoradev#252 — the
"I don't know" behavior — for every consumer on the unified path, which is
the default path for the CLI, the MCP server, and the HTTP server.
2. There is no way to tell a good match from a bad one. Recall always returns
`limit` results at maximum apparent confidence, so an agent consuming
`uteke_recall` has no signal that nothing relevant was found.
Fix: keep RRF for ordering, report the memory's real cosine for scoring.
Ordering is unchanged; only the reported number differs.
Documents deliberately keep the normalized RRF. `DocumentSearchResult::score`
means three different things by mode — cosine from `doc_search_semantic`,
`1/(i+1)` rank from `doc_search_fts`, an RRF sum from `doc_search_hybrid` — and
an FTS-only hit has no similarity to report at all. Putting documents on the
same scale requires unifying that first, which is a larger change than this one;
happy to follow up if you want it.
Measured over 67 real memories after the fix: unrelated queries top out at
~0.38, genuine matches land at 0.48–0.62, and `min_score = 0.45` correctly
returns "No matching results found." for the nonsense query above.
Note this lowers reported memory scores from ~1.0 to real similarity, so any
config carrying a `min_score` tuned against the old numbers becomes meaningfully
stricter. The 0.30 default is below the noise floor measured here; 0.45 was a
better fit on that corpus, but the right default depends on the embedding model
and is left unchanged in this PR.
Adds a regression test asserting a matching query outscores an unrelated one and
that the top score is not the RRF constant. It fails on develop with
"top score 1 is the normalized RRF constant, not a similarity" and passes here.
The test uses a `tempfile` store rather than `:memory:`. The usearch index path
is derived from the SQLite path, so `Uteke::open(":memory:")` has no vector index
and every recall returns empty — worth knowing, since the existing `#[ignore]`d
recall tests around it are written that way and cannot pass as written.
themiguelamador
force-pushed
the
fix/unified-recall-reports-rrf-rank-as-score
branch
from
August 3, 2026 00:13
24255aa to
66cfcbf
Compare
ajianaz
approved these changes
Aug 3, 2026
ajianaz
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. RRF rank was leaking into reported similarity score — this correctly surfaces the real cosine similarity for memory results while keeping normalized RRF for documents (which have mixed score semantics). Good test coverage with the ignored integration test.
This was referenced Aug 3, 2026
ajianaz
added a commit
that referenced
this pull request
Aug 5, 2026
- v0.12.0: add @KazamiHazaki (Windows installer #779) + @dependabot - v0.11.0: add @themiguelamador (#830 #831) + @tomatotomata (#829) - v0.12.0: add install.ps1 to Added section Co-authored-by: ajianaz <[email protected]>
ajianaz
added a commit
that referenced
this pull request
Aug 13, 2026
- v0.12.0: add @KazamiHazaki (Windows installer #779) + @dependabot - v0.11.0: add @themiguelamador (#830 #831) + @tomatotomata (#829) - v0.12.0: add install.ps1 to Added section 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.
The bug
recall_unified_allmerges memory and document hits with RRF, then reportsrrf_sum / (1/(k+1))as the score. When a result appears in only one of the two lists — every result in any store without documents — that sum is1/(k+1+rank), so the reported score collapses to(k+1)/(k+1+rank): a pure function of rank, with the cosine similarity discarded.Every query returns the same score sequence regardless of what it matched, or whether it matched anything:
Those are exactly
61/61, 61/62, 61/63.Two consequences
1.
min_scorecannot filter. It's applied to the rank number, so at the documented0.30default a result must rank ~140th to be excluded. This silently defeats the configurable similarity threshold from #252 — the "I don't know" behavior — for every consumer on the unified path, which is the default for the CLI (commands/recall.rs:113), the MCP server (uteke-mcp/src/lib.rs:765), and the HTTP server (handlers.rs:292).2. No way to distinguish a good match from a bad one. Recall always returns
limitresults at maximum apparent confidence. An agent consuminguteke_recallgets no signal that nothing relevant was found — the nonsense query above looks identical to a perfect hit.The fix
Keep RRF for ordering; report the memory's real cosine for scoring. Result order is unchanged; only the reported number differs.
Measured over 67 real memories after the fix:
git branch naming(direct hit)my safety copy vanished after rewriting history(pure synonym match)purple giraffe tax law sonata(nonsense)With
min_score = 0.45the nonsense query correctly returnsNo matching results found.Scope: memories only
Documents deliberately keep the normalized RRF.
DocumentSearchResult::scoremeans three different things depending on mode — cosine fromdoc_search_semantic,1/(i+1)rank fromdoc_search_fts, an RRF sum fromdoc_search_hybrid— and an FTS-only hit has no similarity to report at all. Putting documents on the same scale means unifying that first, which is a larger change than this one. I'd rather not smuggle it in here; happy to follow up if you want it.This does leave memory and document scores on different scales within one result set. That's pre-existing, not introduced here — but worth being explicit about.
Compatibility
This lowers reported memory scores from ~1.0 to real similarity, so any config with a
min_scoretuned against the old numbers becomes meaningfully stricter. Worth a release-note line.The
0.30default sits below the noise floor measured here (~0.38);0.45fit that corpus better. The right default depends on the embedding model, so I've left it unchanged rather than guess for other setups.Test
Adds
test_unified_recall_reports_similarity_not_rrf_rank, asserting a matching query outscores an unrelated one and that the top score isn't the RRF constant. It fails ondevelopwithtop score 1 is the normalized RRF constant, not a similarity, and passes here.One note that may be useful beyond this PR: the test uses a
tempfilestore rather than:memory:. The usearch index path is derived from the SQLite path, soUteke::open(":memory:")gets no vector index and every recall returns empty. The existing#[ignore]d recall tests around it (test_recall_threshold_filters_low_scores,test_recall_threshold_zero_returns_all,test_recall_threshold_specific_score) are written that way and cannot pass as written — theirassert!(!results.is_empty())will always fail. I've left them alone here.cargo fmt --checkandcargo clippy --workspace --all-targets -- -D warningsboth clean.