Expand description
TurboQuant implementation for vector search.
Compresses high-dimensional vectors to 2-4 bits per coordinate with near-optimal distortion. Data-oblivious — no training required.
use turbovec::TurboQuantIndex;
// 1536-dim vectors compressed to 4 bits per coordinate.
let mut index = TurboQuantIndex::new(1536, 4);
// `vectors` is a flat [f32] of length n * dim, `queries` likewise.
let vectors: Vec<f32> = vec![0.0; 1536 * 10];
let queries: Vec<f32> = vec![0.0; 1536 * 2];
index.add(&vectors);
let results = index.search(&queries, 10);
index.write("index.tv").unwrap();
let loaded = TurboQuantIndex::load("index.tv").unwrap();§Concurrent search
search takes &self and is safe to call from multiple threads
concurrently. Internally the rotation matrix, the Lloyd-Max centroids
and the SIMD-blocked code layout are initialised lazily via
std::sync::OnceLock, so the first caller pays the one-time
initialisation cost and every subsequent caller reads the caches
without locking. TurboQuantIndex::prepare can be called once
after add/load to pay that cost up front.
Mutation still flows through &mut self: add extends the packed
codes and invalidates the blocked layout cache by replacing its
OnceLock. This keeps the invariant that once a cache is populated
from &self, it matches the current packed_codes.
Re-exports§
pub use id_map::IdMapIndex;
Modules§
- codebook
- Lloyd-Max scalar quantizer for the Beta distribution.
- encode
- Encode vectors: normalize, rotate, quantize, bit-pack.
- id_map
- Stable external IDs on top of
TurboQuantIndex. - io
- Read/write TurboVec index files.
- pack
- Bit-plane to SIMD-blocked layout repacking.
- rotation
- Random orthogonal rotation matrix generation.
- search
- SIMD-accelerated search pipeline.