research(nightly): residual-vector-quantization — pure-Rust RVQ for ANN search#451
Draft
research(nightly): residual-vector-quantization — pure-Rust RVQ for ANN search#451
Conversation
…ANN search Multi-stage residual codebook compression (RVQ) achieving same recall as flat PQ at half the per-vector byte cost. Pure-Rust, no unsafe, no BLAS. Key results (cargo run --release -p ruvector-rvq --bin rvq-demo): - RVQ S=4 (4 bytes/vec): 6.4% R@10 at 1,656 QPS n=20K D=128 - PQ M=8 (8 bytes/vec): 6.3% R@10 at 2,918 QPS n=20K D=128 - RVQ S=8 +rerank×4: 43.4% R@10 at 4,489 QPS n=5K D=128 - 19.2% distortion reduction over 8 stages (no codebook collapse) New items: Codebook (Lloyd k-means++), ProductQuantizer, RvqEncoder, AnnIndex trait, FlatF32/PQ/RVQ/RVQRerank indices, rvq-demo binary. All 7 tests pass (6 unit + 1 doc). cargo build --release succeeds. https://claude.ai/code/session_01G4YPX6B9nQPKDfkn9J1vdR
docs/research/nightly/2026-05-09-residual-vector-quantization/README.md: SOTA survey (arXiv:2011.10952, 2107.03312, 2306.06546), design notes, benchmark methodology, all results tables, blog walkthrough, failure modes, roadmap, production crate layout proposal. docs/adr/ADR-193-residual-vector-quantization.md: Decision to add RVQ crate, ADC formula, codebook dropout justification, consequences, and three rejected alternatives (core PQ extension, FAISS FFI, MRL search, ScaNN AVQ). https://claude.ai/code/session_01G4YPX6B9nQPKDfkn9J1vdR
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.
Nightly Research: Residual Vector Quantization (RVQ)
Topic: Multi-stage residual codebook compression for ANN search
ADR: ADR-193
Research doc:
docs/research/nightly/2026-05-09-residual-vector-quantization/README.mdCrate:
crates/ruvector-rvq/What This Adds
A new workspace crate
ruvector-rvqimplementing Residual Vector Quantization — a multi-stage encoding scheme where each codebook stage quantizes only the residual error from the previous stage. First pure-Rust, no-unsafe, no-BLAS RVQ in the ecosystem.4 index types sharing the
AnnIndextrait:FlatF32Index— exact brute-force baselinePqIndex— standard flat product quantization (comparison)RvqIndex— residual vector quantization with ADC searchRvqRerankIndex— RVQ + exact rerank (high-recall production path)Real Benchmark Numbers
Hardware: x86-64 Linux, rustc release, no external SIMD or BLAS.
Suite: n=20K, D=128, K=64 centroids, 25 Lloyd iterations
Key insight: RVQ S=4 matches PQ M=8 recall (6.4% vs 6.3%) at half the per-vector byte cost.
At D=256: RVQ S=4 (9.4%) outperforms PQ M=8 (8.1%) at half the bytes.
Distortion convergence (8 stages, K=64):
All 8 stages active — no codebook collapse under 10% dropout regularisation.
Tests
Files
crates/ruvector-rvq/src/codebook.rscrates/ruvector-rvq/src/rvq.rscrates/ruvector-rvq/src/index.rscrates/ruvector-rvq/src/main.rsdocs/adr/ADR-193-residual-vector-quantization.mddocs/research/nightly/2026-05-09-residual-vector-quantization/README.mdGist
Next Steps (roadmap from research doc)
ruvector-diskannhttps://claude.ai/code/session_01G4YPX6B9nQPKDfkn9J1vdR
Generated by Claude Code