Skip to main content

normalize_scores

Function normalize_scores 

Source
fn normalize_scores(results: &mut [SearchHit])
Expand description

Normalizes search result scores to the 0.0-1.0 range.

§Algorithm

The maximum score in the result set becomes 1.0, and all other scores are scaled proportionally. This ensures:

  • Scores are always in [0.0, 1.0] range
  • The top result always has score 1.0 (if results exist)
  • Relative score proportions are preserved

§Arguments

  • results - Mutable slice of search hits to normalize

§Notes

  • Empty results are handled safely (no division by zero)
  • Sets raw_score to preserve the original score before normalization
  • If all scores are 0, they remain 0 after normalization

§Example

Before: [0.033, 0.020, 0.016]  (RRF scores)
After:  [1.0,   0.606, 0.485]  (normalized)