Skip to content

fix: division by zero error #201#244

Open
JettChenT wants to merge 1 commit intomainfrom
fix/bm25-division-by-zero
Open

fix: division by zero error #201#244
JettChenT wants to merge 1 commit intomainfrom
fix/bm25-division-by-zero

Conversation

@JettChenT
Copy link
Copy Markdown
Contributor

@JettChenT JettChenT commented Jan 17, 2026

Fixes #201

Summary by CodeRabbit

  • Bug Fixes
    • Improved search result ranking stability by addressing edge cases in the search scoring algorithm that could occur with certain document collections.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Review Updated (UTC)
cmumaps Skipped Skipped Jan 17, 2026 9:31pm
cmumaps-visualizer Skipped Skipped Jan 17, 2026 9:31pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 17, 2026

📝 Walkthrough

Walkthrough

Fixes a division by zero vulnerability in the BM25Term utility by applying Math.max(1, avgDl) to the denominator when calculating term frequency normalization, preventing invalid results when average document length approaches zero.

Changes

Cohort / File(s) Summary
BM25 Division by Zero Prevention
apps/server/src/utils/search/rank.ts
Modified tfPart calculation in BM25Term to guard against division by zero using Math.max(1, avgDl) in the denominator

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

🐰 A tiny math tweak saved the day,
When avgDl shrank away,
With Math.max, we stand tall,
No more zero division fall! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: fixing a division by zero error related to issue #201.
Linked Issues check ✅ Passed The PR implements a fix for the division by zero issue by using Math.max(1, avgDl) in the denominator, directly addressing issue #201's acceptance criteria to resolve the issue.
Out of Scope Changes check ✅ Passed All changes in rank.ts are focused on fixing the BM25Term division by zero issue specified in issue #201 with no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Fix division by zero in BM25Term when avgDl is 0.

1 participant