qntz
Vector quantization.
Quickstart
[]
= "0.2"
use ;
// Two 8-bit binary vectors (as 0/1 bytes).
let a_bits = ;
let b_bits = ;
let mut a_packed = ;
let mut b_packed = ;
pack_binary_fast.unwrap;
pack_binary_fast.unwrap;
let d = hamming_distance;
assert_eq!;
Features
All quantization modules are feature-gated. The default build provides only the
core bit-packing helpers in simd_ops.
| Feature | What it adds |
|---|---|
simd |
dispatches supported bit operations through innr |
serde |
derives for serializing trained quantizers and codebooks |
rabitq |
RaBitQ quantizer with 1-8 bit scalar codes and L2 correction terms |
ternary |
ternary quantizer with configurable thresholds and adaptive sparsity |
distquant |
distribution-aware scalar quantization utilities |
adaptive |
per-vector adaptive scalar quantization |
binary |
rotation-based binary quantization |
matryoshka |
scalar codes that can be scanned at multiple precisions |
Enable selected modules:
[]
= { = "0.2", = ["rabitq", "ternary"] }
API overview
Fallible operations return qntz::Result<T> (wrapping VQuantError) for
dimension mismatches and invalid configs. Pure distance helpers that take
pre-validated inputs return scalar values directly.
Batch scan helpers expose _into variants for reusing caller-owned output
buffers across repeated queries. Adaptive packed batches also expose scan plans
for caching per-vector code statistics when one batch is searched by many
queries.
Examples
Runnable examples live in examples/:
rabitq_error_budget.rscompares RaBitQ bit widths using the quantizer's error proxy and packed code size.adaptive_scan.rscompares per-vector adaptive quantization against exact scan distances.matryoshka_precision_scan.rsscans one stored scalar code at multiple bit precisions.additive_codebook_refinement.rsscans ordered additive codebook stages.entropy_coded_quantization.rsentropy-codes RaBitQ scalar codes with ANS.sift_rabitq_recall.rsreports RaBitQ recall on SIFT-small with filter-then-rerank.
simd_ops (always available)
Bit packing, Hamming distance, asymmetric inner product / L2, and multi-bit
code operations. All pack/unpack functions return Result:
use ;
let codes = ;
let mut packed = ;
pack_binary_fast.unwrap;
let mut roundtrip = ;
unpack_binary_fast.unwrap;
assert_eq!;
let other = ; // all-zero packed vector
assert_eq!; // 4 bits differ
rabitq (feature = "rabitq")
RaBitQ quantizer with configurable bit depth (1-8 bits per dimension). Supports centroid fitting and approximate L2 distance:
ternary (feature = "ternary")
Ternary quantization maps each dimension to {-1, 0, +1} using 2 bits per
value. ternary_hamming returns Option<usize> (None on dimension mismatch):
Design
- No hidden geometry: this crate provides code operations. It does not impose a distance metric on your original vectors.
- Determinism: all operations are pure and deterministic (given the same seed for rotation matrices).
- Error discipline: dimension mismatches and invalid configs surface as typed errors, not panics.
License
Licensed under either MIT or Apache-2.0 at your option.