qntz
Vector quantization primitives for ANN systems.
Scope: small, reusable pieces (bit packing, low-bit codes) that higher-level ANN crates can build on. This crate intentionally does not implement full indices.
Quickstart
[]
= "0.1.0"
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 |
|---|---|
rabitq |
RaBitQ quantizer -- 1-bit sign codes with optional extended bits (up to 8-bit total) and correction factors for approximate L2 distance |
ternary |
Ternary (1.58-bit) quantizer -- maps each dimension to {-1, 0, +1} with configurable thresholds and adaptive sparsity |
Enable one or both:
[]
= { = "0.1.0", = ["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.
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.