ruvector_pq_search - Rust
Skip to main content

Crate ruvector_pq_search

Crate ruvector_pq_search 

Source
Expand description

Product Quantization with Asymmetric Distance Computation (PQ-ADC)

Decomposes D-dimensional vectors into M sub-vectors of d=D/M dimensions, trains K centroids per sub-space with Lloyd’s algorithm, and encodes each vector as M bytes (K=256 → 8 bits per sub-space).

Three search strategies:

  • FlatPqIndex — linear ADC scan over all PQ codes (baseline)
  • IvfPqIndex — coarse IVF + PQ per cell (alternative A)
  • ResidualPqIndex — PQ + f32 residual correction for top-k (alternative B)

All implement the PqSearch trait; no external service dependency.

Re-exports§

pub use codebook::PqCodebook;
pub use codebook::PqConfig;
pub use encoder::decode_vector;
pub use encoder::encode_vector;
pub use flat::FlatPqIndex;
pub use ivf_pq::IvfPqIndex;
pub use residual::ResidualPqIndex;

Modules§

codebook
PQ codebook: M sub-spaces, K centroids each, trained with Lloyd’s k-means.
encoder
PQ encode/decode utilities.
flat
Flat PQ Index: linear ADC scan over all encoded vectors (baseline variant).
ivf_pq
IVF+PQ Index: coarse IVF clustering, then PQ within each inverted list.
residual
Residual-Corrected PQ Index: PQ scan + exact L2 re-score for top-k candidates.

Structs§

ExactSearch
Brute-force exact L2 search; used for recall ground-truth only.
SearchResult
Single search result returned by all variants.

Traits§

PqSearch
Unified trait for all PQ-based search backends.

Functions§

recall_at_k
Compute recall@k: fraction of true top-k found in approximate top-k.