refactor(vector/search): extract RerankStage/RerankPipeline, port HNSW Stage-2 (#650 PR-1) - #935
Merged
Merged
Conversation
…W Stage-2 (closes #931)
This was referenced Aug 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR-1 of the #650 rerank-pipeline campaign: extracts Stage-2 rerank (Issue #481) from its inline match arm in the HNSW searcher into a shared, composable abstraction — with zero behavior change, proven bit-for-bit by a frozen oracle.
vector/search/rerank.rs(crate-private): the object-safeRerankStagetrait (a stage's per-query preparation coincides with its single per-query invocation, so it folds intorescore— the object-safety deviation from the perf(vector/search): two-stage rerank exists only for HNSW; pipeline is hard-coded #650 sketch, recorded on refactor(vector/search): RerankStage/RerankPipeline abstraction, port HNSW Stage-2 (#650 PR-1) #931), the SoARerankCandidatesbuffer (paralleldoc_ids/distances, crate-wide distance-ascending + doc-id-tiebreak sort per bug(vector/search): cross-segment scores are not comparable — out-of-range queries clamp to similarity 1.0 per segment #927/bug(vector/search): per-searcher similarity sort underflows at long range — top-k membership becomes arbitrary #933), and theRerankPipelinedriver: stageiconsumes the toptop_k * factors[i]of the previous basis, andrunreports whether the FINAL stage applied — exactly thescore_basis = "f32-rerank"condition the multi-segment fan-out keys on (bug(vector/search): cross-segment scores are not comparable — out-of-range queries clamp to similarity 1.0 per segment #927).F32SidecarStage: the former inline arm as a stage — field position index resolved at construction, query prepared once, rescoring againstpool.f32_slice_at, docs absent from the sidecar dropped (pre-refactorcontinuesemantics).finalize_graph_resultsbuilds a one-stage pipeline from(rerank_factor, reader.rerank_storage()), feeds it the ascending int8 candidates (matching the pre-refactorinto_sorted_vec().take(widened)prefix), takesrerank_appliedfrom the pipeline's return, and the inline arm is deleted. No public API change.Zero-behavior-change evidence
rerank_pipeline_oracle_test.rs, captured against the pre-refactor implementation on the post-bug(vector/search): per-searcher similarity sort underflows at long range — top-k membership becomes arbitrary #933 baseline): rerank-on results equal an independently-computed exact-f32 expectation bit-for-bit (doc ids + similarity bits); rerank-off stays exact-ordered and bit-deterministic; single-segment and multi-segment-with-stale-duplicate fixtures. Green after the port. (Writing this oracle is what exposed bug(vector/search): per-searcher similarity sort underflows at long range — top-k membership becomes arbitrary #933, fixed first in PR fix(vector/search): select per-searcher top-k by distance, not underflow-prone similarity (#933) #934.)vector_rerank_engine_test(Stage-2 applied + silent Stage-1 fallback), the bug(vector/search): cross-segment scores are not comparable — out-of-range queries clamp to similarity 1.0 per segment #927 comparability suite, and the bug(vector/search): per-searcher similarity sort underflows at long range — top-k membership becomes arbitrary #933 distance-sort suite: green unchanged.Verification
cargo fmt --checkandcargo clippy --all-targets -- -D warningsclean on stable and 1.97.0cargo test -p laurus --lib: 1261 passed;--tests: all 66 binaries okcargo check -p laurus-wasm: clean;cargo doc --no-deps -p laurus: 73 warnings (baseline)Closes #931. Part of #650; unblocks #932 (Flat/IVF adoption) and keeps #673's 3-stage chain expressible.