Skip to content

fix: handle NaN scores in sort_by comparison#58

Open
echobt wants to merge 1 commit intomainfrom
fix/issue-183
Open

fix: handle NaN scores in sort_by comparison#58
echobt wants to merge 1 commit intomainfrom
fix/issue-183

Conversation

@echobt
Copy link
Copy Markdown
Contributor

@echobt echobt commented Jan 21, 2026

Description

This PR fixes a bug where scores (potentially from embedding engine or numerical issues) would cause non-deterministic sorting behavior in search results due to the use of with .

Changes

  • Updated logic in to explicitly handle values by treating them as smaller than any other number (pushing them to the end of the sorted list).
  • Applied the same fix to where similarity scores are sorted.

Verification

  • Created a reproduction test case demonstrating that the old sort was unstable with NaNs.
  • Verified that the new sort correctly orders real numbers descending and pushes NaNs to the end.
  • Ran existing test suite to ensure no regressions.

This fixes a non-deterministic sorting behavior where NaN scores from the embedding engine (or database queries) would cause unstable result ordering. NaNs are now explicitly handled and pushed to the end of the results.
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