Skip to content

Conversation

@Sicheng-Pan
Copy link
Contributor

@Sicheng-Pan Sicheng-Pan commented Nov 11, 2025

Description of changes

Summarize the changes made by this PR.

  • Improvements & Bug fixes
    • RecordMeasure should sort by offset id as well to break ties deterministically
    • SparseIndexKnn output should sort by offset id to maintain overall order
  • New functionality
    • N/A

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Migration plan

Are there any migrations, or any forwards/backwards compatibility changes needed in order to make sure this change deploys reliably?

Observability plan

What is the plan to instrument and monitor this change?

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs section?

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@Sicheng-Pan Sicheng-Pan marked this pull request as ready for review November 11, 2025 20:49
@propel-code-bot
Copy link
Contributor

Deterministic ordering for sparse-KNN results via tie-break on offset_id

Small fix to guarantee deterministic ordering when multiple sparse-KNN matches share the same distance. The PR augments the Ord implementation of RecordMeasure to compare offset_id as a secondary key and explicitly sorts the result vector returned by SparseIndexKnn::run() before it is consumed by downstream merge logic.

Key Changes

• Updated RecordMeasure::cmp() in rust/types/src/execution/operator.rs to call then_with(|| self.offset_id.cmp(&other.offset_id)) after measure.total_cmp
• Refactored rust/worker/src/execution/operators/sparse_index_knn.rs to collect wand results into Vec<RecordMeasure> and call records.sort_unstable() before wrapping in SparseIndexKnnOutput

Affected Areas

RecordMeasure ordering semantics
SparseIndexKnn operator output
• Any downstream logic that relies on sorted KNN results (e.g., KnnMerge, ranking)

This summary was automatically generated by @propel-code-bot

@Sicheng-Pan Sicheng-Pan merged commit 9aec7c7 into main Nov 11, 2025
64 checks passed
@Sicheng-Pan Sicheng-Pan deleted the 11-11-_bug_sparse_index_does_not_sort_offset_id branch November 11, 2025 21:12
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