Skip to content

fix(recall): normalize FTS5 scores AFTER filtering, not before - #855

Merged
ajianaz merged 2 commits into
developfrom
fix/fts5-normalization-after-filter
Aug 5, 2026
Merged

ajianaz merged 2 commits into
developfrom
fix/fts5-normalization-after-filter

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 5, 2026 •

Copy link
Copy Markdown
Collaborator

What

Follow-up fix to PR #854 — FTS5 min-max normalization order bug caught by cora review.

Why

PR #854 introduced min-max BM25 normalization but computed the range (best/worst) from ALL fts_results before the namespace/tag filter step. If the best or worst-ranked items get filtered out, the surviving scores no longer span the full 0.0..1.0 range.

How

Restructured the pipeline:

  1. Filter first, collect surviving (Memory, rank) pairs
  2. Compute min-max from surviving results only
  3. Map to scores using the correct range
  4. Take limit

Before: compute_range(all) then filter then map
After: filter then compute_range(filtered) then map

Testing

  • cargo test --workspace — 432 passed, 0 failed, 24 ignored
  • cargo clippy — 0 warnings
  • Cora review (bifrost provider) — clean

Related Issues

Follow-up to #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.
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

⚠️ Review could not complete. Cora was unable to reach the LLM API after retries. Check the workflow logs for errors.


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit e6fcf73 into develop Aug 5, 2026
12 checks passed
@ajianaz
ajianaz deleted the fix/fts5-normalization-after-filter branch August 5, 2026 00:30
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant