Skip to content

[2.8] MOD-12223: Fix underflow in BM25STD#7259

Merged
raz-mon merged 2 commits into2.8from
razmon-cp_2.8_fix_bm25std_underflow
Nov 9, 2025
Merged

[2.8] MOD-12223: Fix underflow in BM25STD#7259
raz-mon merged 2 commits into2.8from
razmon-cp_2.8_fix_bm25std_underflow

Conversation

@raz-mon
Copy link
Copy Markdown
Collaborator

@raz-mon raz-mon commented Nov 9, 2025

Backport #7223 to 2.8


Note

Prevents underflow in BM25STD IDF calculation by clamping totalDocs and adds a regression test validating stable scoring after updates/deletes.

  • Scoring/Core:
    • Adjust CalculateIDF_BM25 in src/inverted_index.h to clamp totalDocs to MAX(totalDocs, termDocs) to avoid underflow in IDF computation.
  • Tests:
    • Add testBM25STDUnderflow in tests/pytests/test_scorers.py to validate BM25STD scoring does not spike after update/delete flows and remains consistent until GC.

Written by Cursor Bugbot for commit c023bc0. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an underflow issue in the BM25STD scoring algorithm that could cause scores to jump unexpectedly during specific update/delete flows (MOD-12223).

  • Added a guard in CalculateIDF_BM25 to prevent underflow when totalDocs < termDocs
  • Added a comprehensive test case to verify the underflow fix and document the scoring behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/inverted_index.h Added MAX guard to prevent underflow in BM25STD IDF calculation when totalDocs < termDocs
tests/pytests/test_scorers.py Added test case verifying that BM25STD scores don't jump unexpectedly during update/delete operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/inverted_index.h
@codecov
Copy link
Copy Markdown

codecov bot commented Nov 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.44%. Comparing base (f8b2cec) to head (c023bc0).
⚠️ Report is 1 commits behind head on 2.8.

Additional details and impacted files
@@           Coverage Diff           @@
##              2.8    #7259   +/-   ##
=======================================
  Coverage   87.44%   87.44%           
=======================================
  Files         203      203           
  Lines       34783    34784    +1     
=======================================
+ Hits        30416    30418    +2     
+ Misses       4367     4366    -1     
Flag Coverage Δ
flow 81.82% <100.00%> (-0.21%) ⬇️
unit 42.48% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@raz-mon raz-mon added this pull request to the merge queue Nov 9, 2025
Merged via the queue into 2.8 with commit ed845b3 Nov 9, 2025
13 checks passed
@raz-mon raz-mon deleted the razmon-cp_2.8_fix_bm25std_underflow branch November 9, 2025 13:22
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.

3 participants