feat(vector/search): PQ → SQ → f32 three-stage rerank chain (#650 PR-3) - #937
Merged
Conversation
) Insert a cheap int8 (SQ) rerank stage ahead of the exact f32 stage on PQ-quantized HNSW fields, activated only when ef_search exceeds the exact-stage budget (top_k * rerank_factor) — the surplus candidates the graph traversal already computed are re-ranked by a much better proxy (int8) instead of being discarded on the noisier PQ ADC order. The int8 view is lazily derived from the existing f32 rerank sidecar (RerankStoragePool::int8_view), so this needs no new on-disk format, no new RerankStorageKind variant, and no new query parameter.
3 tasks
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
ef_searchexceeds the exact-stage budget (top_k * rerank_factor). Today that surplus — candidates the graph traversal already computed — is simply discarded on the noisier PQ ADC order; the SQ stage re-ranks it on a much better proxy (int8) before the narrow exact-stage budget is carved out.RerankStoragePool::int8_view,OnceLock-cached) instead of persisted separately. Net effect: no new on-disk format, no newRerankStorageKindvariant, no new query parameter, zero ripple into proto/bindings/CLI.Changes
ScalarQuantParams::train_from_slices(vector/core/quantization.rs): slice-iterator variant oftrain;train(&[Vector])now delegates to it.RerankStoragePool::int8_view()(vector/index/rerank_storage.rs): lazily derives aQuantizedVectorPoolfrom the pool's own f32 payload, encoded in the same position order soint8_view.record_at(pos)andf32_slice_at(pos)trivially agree onpos. Degrades toNoneon an empty pool or training failure.SqRerankStage(vector/search/rerank.rs): mirrorsF32SidecarStage, rescoring viadistance_quantized.HnswSearcher::finalize_graph_results: insertsSqRerankStageahead ofF32SidecarStageonly when segment=PQ/PQ-FastScan + sidecar loaded +rerank_factorset +effective_ef_search > top_k * rerank_factor.score_basisstamping (bug(vector/search): cross-segment scores are not comparable — out-of-range queries clamp to similarity 1.0 per segment #927) is unchanged — still keyed only on the final (still f32) stage.bench_hnsw_graph_search_pq_rerank_real_data_wide_ef(opt-in SIFT, not run in this session — no local fixture).vector_indexing.md;grpc_api.mdrerank_factorrow updated (also fixes a stale feat(vector/search): Stage-2 rerank for Flat/IVF via the shared pipeline (#650 PR-2) #932-era "Flat/IVF fall back" claim) + newef_searchrow.Tests
train_from_slices(2),int8_view(6: position-consistency, quantization-error bound, single-build-cached, degrade-to-None),SqRerankStage(2).vector_pq_three_stage_rerank_test.rs, new):pq_three_stage_rerank_end_to_end— wide-ef_search(SQ active) Recall@10 ≥ narrow/budget-exactef_search(SQ inactive) Recall@10 (measured 0.66 → 0.98 on a deliberately lossy PQ fixture);score_basisstays"f32-rerank"; narrow-ef_searchresults are bit-exact reproducible.ef_searchrecall dropped 0.98 → 0.9567, confirming the SQ stage's causal contribution.hnsw_pq_rerank_recall_at_10_meets_stage3_recall_gate+ opt-in SIFT variant) stay green.Verification
cargo fmt --check/cargo clippy --all-targets -D warnings: clean on stable, 1.97.0, and--features pq-fastscan.cargo test -p laurus --lib: 1270 passed.--tests: 68 binaries, all green.cargo check -p laurus-wasm --target wasm32-unknown-unknown: clean.cargo doc --no-deps -p laurus: 73 warnings (unchanged baseline).markdownlint-cli2EN+JA: 0 errors. Both mdBooks build.Test plan
score_basiscontract, and 2-stage-path determinism