feat: TurboQuant 4-bit vector quantization#46
Draft
damahua wants to merge 1 commit into
Draft
Conversation
Integrate TurboQuant (Zandieh et al. 2025) 4-bit scalar quantization to reduce per-vector memory from 3072 to 384 bytes (8x for 768-dim). How it works: - Random sign rotation decorrelates dimensions - 4-bit Lloyd-Max codebook (16 centroids) encodes each dimension - Symmetric distance: dequantize both vectors for exact L2/IP/cosine Files: - turbo_quant.h: TurboQuantizer, TurboQuantL2Space, TurboQuantIPSpace - hnswalg.h: quantizer_ field, quantized addPoint/searchKnn/getDataByLabel - bindings.cpp: create_index_quantized() FFI, set_quantizer() wiring - hnsw.rs: quantization_bits config field Enabled via quantization_bits=4 parameter. Default (0) = unchanged. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 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
quantization_bits=4parameter inHnswIndexInitConfig(default 0 = unchanged)Changes (5 files)
hnswlib/turbo_quant.h(new):TurboQuantizerclass — random sign rotation + 4-bit Lloyd-Max codebook + symmetric distance;TurboQuantL2SpaceandTurboQuantIPSpacewrappers compatible withSpaceInterfacehnswlib/hnswalg.h:quantizer_field,set_quantizer(), quantized storage inaddPoint, quantized query insearchKnn, dequantize ingetDataByLabelhnswlib/hnswlib.h: Includeturbo_quant.hsrc/bindings.cpp:create_index_quantized()FFI entry point,set_quantizer()wiring after index initsrc/hnsw.rs:quantization_bitsfield inHnswIndexInitConfig, conditionalcreate_index_quantizedcallHow it works
addPoint) and search (searchKnn)getDataByLabel: dequantizes stored codes back to float32 for Chroma's brute-force fallback pathA/B Test Results (N=3, 50K × 768-dim, Chroma single-node)
39.7% peak RSS reduction. Zero errors across all API requests.
Test plan
quantization_bits=0quantization_bits=4🤖 Generated with Claude Code