Vector quantization in Rust. Compresses float vectors for fast approximate similarity search.
Pure Rust, no C dependencies. SIMD-accelerated on x86 (AVX2) and ARM (NEON).
| Method | Bits/dim | Compression | Distance |
|---|---|---|---|
| Binary (BQ) | 1 | 32x | Hamming |
| Scalar (SQ) | 8 | 4x | L2 in u8 space |
| Product (PQ) | ~1 (tunable) | up to 64x | Asymmetric (ADC) |
| Optimized Product (OPQ) | same as PQ | same as PQ | ADC with learned rotation |
All four implement a shared Quantizer trait for interchangeable use.
use vorq::{ProductQuantizer, PqConfig, Metric};
let dim = 128;
let n = 10_000;
// your embeddings as a flat &[f32] of length n * dim
let data: Vec<f32> = load_vectors();
let config = PqConfig { m: 8, k: 256, kmeans_max_iter: 25 };
let pq = ProductQuantizer::train(dim, &data, n, Metric::L2, &config)?;
let codes = pq.encode(&data, n)?;
// top-10 nearest neighbors
let results = pq.search(&codes, &query, 10)?;[dependencies]
vorq = "0.1"Optional: serde for serialization, rayon for parallel k-means training.
MIT