Expand description
Scalar Quantization (SQ8) and Binary Quantization for memory-efficient vector storage.
This module implements quantization strategies to reduce memory usage:
§Benefits
| Metric | f32 | SQ8 | Binary |
|---|---|---|---|
| RAM/vector (768d) | 3 KB | 770 bytes | 96 bytes |
| Cache efficiency | Baseline | ~4x better | ~32x better |
| Recall loss | 0% | ~0.5-1% | ~5-10% |
§Engine integration status
The figures above describe the quantization primitives themselves. In the
collection query path: RaBitQ (binary traversal backend), SQ8 (int8
traversal backend, Euclidean/Cosine) and PQ (ADC rescoring) are wired
end-to-end. Persistence across reopens covers TRAIN-QUANTIZER-produced
artifacts (rabitq.idx, sq8.idx, codebook.pq) plus lazily-trained
RaBitQ/SQ8 quantizers (persisted by the full flush); a PQ quantizer
trained lazily from inserts (no TRAIN statement) is in-memory only and
retrains after a restart. The Binary collection mode stays full-precision
f32 in the search path. See docs/guides/QUANTIZATION.md.
Structs§
- Binary
Quantized Vector - A binary quantized vector using 1-bit per dimension.
- PQCodebook
- Per-subspace centroid tables learned with k-means.
- PQVector
- Compressed representation of a vector: one centroid id per subspace.
- Prepared
Query - Preprocessed query data for
RaBitQdistance computation. - Product
Quantizer - Product quantizer model and helpers for train/encode/decode.
- Quantized
Vector - A quantized vector using 8-bit scalar quantization.
- RaBitQ
Correction - Scalar correction factors for a
RaBitQ-encoded vector. - RaBitQ
Index RaBitQindex holding the random rotation matrix and dataset centroid.- RaBitQ
Vector - Binary-quantized vector with scalar correction factors.
Enums§
- Storage
Mode - Storage mode for vectors.
Constants§
- STORAGE_
MODE_ NAMES - Canonical names of every
StorageModevariant, in declaration order.
Traits§
- Quantization
Codec - Trait for serializing and deserializing quantized vectors to/from bytes.
Functions§
- cosine_
similarity_ quantized - Computes approximate cosine similarity between a query (f32) and quantized vector.
- cosine_
similarity_ quantized_ simd - SIMD-optimized cosine similarity between f32 query and SQ8 vector.
- dot_
product_ quantized - Computes the approximate dot product between a query vector (f32) and a quantized vector.
- dot_
product_ quantized_ simd - Dot product between f32 query and SQ8 quantized vector with 8-wide unrolling.
- euclidean_
squared_ quantized - Computes the approximate squared Euclidean distance between a query (f32) and quantized vector.
- euclidean_
squared_ quantized_ simd - SIMD-optimized squared Euclidean distance between f32 query and SQ8 vector.
- train_
opq - Train a PQ codebook with optional PCA pre-rotation.