Skip to content

[BUG] search.rs Uses partial_cmp with unwrap_or for Score Sorting #183

@xyz080125

Description

@xyz080125

Project

vgrep

Description

In search.rs line 82-85, the sorting uses partial_cmp with unwrap_or(std::cmp::Ordering::Equal). If scores contain NaN values (which can propagate from the embedding engine), this leads to non-deterministic sorting behavior since NaN comparisons return None.

Error Message

Debug Logs

System Information

OS: Any
Rust Version: 1.75+

Screenshots

No response

Steps to Reproduce

  1. Cause the embedding engine to produce NaN values (e.g., through numerical overflow)
  2. Perform a search
  3. Observe the ordering of results across multiple runs

Expected Behavior

Results should be consistently sorted, and NaN scores should be handled explicitly (e.g., placed at the end)

Actual Behavior

Results with NaN scores may appear in random positions due to unstable sorting behavior

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingvalidValid issuevgrep

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions