feat: SQ-HNSW scalar-quantized HNSW with online calibration and rerank (nightly 2026-07-07)#649
Draft
ruvnet wants to merge 2 commits into
Draft
feat: SQ-HNSW scalar-quantized HNSW with online calibration and rerank (nightly 2026-07-07)#649ruvnet wants to merge 2 commits into
ruvnet wants to merge 2 commits into
Conversation
Implements three HNSW index variants with different distance precision: - F32Index: full float32 baseline - Sq8Index: int8 scalar-quantized traversal (4× memory, 1.5× faster) - Sq8RerankIndex: int8 graph walk + float32 exact rerank on candidates Calibration fits per-dimension min/max statistics over the corpus; the quantizer is frozen before graph construction and shared across all three variants. Key design fix: insert_node takes a two-argument dist_fn(i,j) so reverse-link pruning uses real distances from the affected node (not the inserting node), preventing graph degradation. Benchmark results (n=10k, 128-dim, ef_s=64, M=16, release build): F32 recall@10=0.770 mean=396μs QPS=2521 mem/vec=512B SQ8 recall@10=0.768 mean=257μs QPS=3897 mem/vec=128B Rerank recall@10=0.769 mean=271μs QPS=3696 mem/vec=640B All acceptance tests pass. Co-Authored-By: claude-flow <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01QwG2TymHzK9LapMySKWsRU
- docs/research/nightly/2026-07-07-sq-hnsw-calibrated-search/README.md Full research document: background, architecture, benchmark analysis, practical and exotic applications, ecosystem integration notes. - docs/adr/ADR-272-sq-hnsw-calibrated-search.md Architecture decision record covering: context, decision rationale, two-arg dist_fn correctness requirement, benchmark evidence, failure modes, security considerations, migration path, open questions. - docs/research/nightly/2026-07-07-sq-hnsw-calibrated-search/gist.md Public-facing gist explaining the implementation, the neighbor-pruning bug fix, and real benchmark numbers. Co-Authored-By: claude-flow <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01QwG2TymHzK9LapMySKWsRU
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
crates/ruvector-sq-hnswimplementing three HNSW index variants all behind a commonAnnIndextrait: F32 baseline, SQ8 (int8 graph traversal), and SQ8+Rerank (int8 traversal + f32 exact rerank of top candidates).ScalarQuantizerthat maps each dimension linearly to[-127, 127]using per-dimension min/max statistics collected from the first N vectors.dist_fn) that silently degraded recall from 0.77 to 0.03.cargo run --release); no placeholder numbers.Benchmark results (n=10k, dims=128, k=10, rustc 1.94.1, x86_64 linux)
SQ8 vs F32: −35% latency, 4× less memory, −0.3% recall. All acceptance tests PASS.
New files
crates/ruvector-sq-hnsw/Cargo.tomlcrates/ruvector-sq-hnsw/src/lib.rsAnnIndextrait,HnswConfig,SearchResult,exact_knncrates/ruvector-sq-hnsw/src/quantizer.rsScalarQuantizer: calibrate, encode, decode,sq8_l2_sqcrates/ruvector-sq-hnsw/src/hnsw.rsHnswGraph: two-arg dist_fn, insert_node, beam searchcrates/ruvector-sq-hnsw/src/index.rsF32Index,Sq8Index,Sq8RerankIndexwith unit testscrates/ruvector-sq-hnsw/src/main.rsdocs/adr/ADR-272-sq-hnsw-calibrated-search.mddocs/research/nightly/2026-07-07-sq-hnsw-calibrated-search/README.mddocs/research/nightly/2026-07-07-sq-hnsw-calibrated-search/gist.mdTest plan
cargo test -p ruvector-sq-hnsw— 8 unit tests + 1 doc test, all passcargo run --release -p ruvector-sq-hnsw— benchmark binary prints RESULT: PASScargo build --workspace— no new warnings or errorsruvector-corebehindsq8feature flag (future milestone M1)🤖 Generated with claude-flow
https://claude.ai/code/session_01QwG2TymHzK9LapMySKWsRU
Generated by Claude Code