pub struct RaBitQuantizer { /* private fields */ }Expand description
RaBitQ 1-bit quantizer (32x compression, unbiased distance estimator).
Implementations§
Source§impl RaBitQuantizer
impl RaBitQuantizer
Sourcepub fn fit(training_vectors: &[Vec<f32>]) -> Self
pub fn fit(training_vectors: &[Vec<f32>]) -> Self
Fit a quantizer from training vectors using the default rotation seed.
Computes the centroid as the per-dimension mean and generates a seeded random orthonormal rotation. Reproducible across runs.
§Panics
Panics if training_vectors is empty or has inconsistent dimensions.
Sourcepub fn fit_with_seed(training_vectors: &[Vec<f32>], seed: u64) -> Self
pub fn fit_with_seed(training_vectors: &[Vec<f32>], seed: u64) -> Self
Fit with an explicit rotation seed.
Sourcepub fn prepare_query(&self, query: &[f32]) -> PreparedQuery
pub fn prepare_query(&self, query: &[f32]) -> PreparedQuery
Prepare a query once for repeated estimate_dist_sq calls.
Sourcepub fn estimate_dist_sq(&self, query: &PreparedQuery, code: &RaBitCode) -> f32
pub fn estimate_dist_sq(&self, query: &PreparedQuery, code: &RaBitCode) -> f32
Estimate squared L2 distance between a prepared query and a code.
S = Σ (2bᵢ − 1) · rqᵢ, then ‖o−q‖² ≈ dtc² + ‖q−c‖² − 2·est_factor·S.
Source§impl RaBitQuantizer
Inherent, not a trait impl.
impl RaBitQuantizer
Inherent, not a trait impl.
These used to satisfy a Quantizer trait in vector::quantize, which had three implementors
and was used polymorphically by nothing – no dyn Quantizer, no T: Quantizer bound anywhere
in the workspace. The other two implementors (ScalarQuantizer, BinaryQuantizer) were a
SECOND implementation of SQ8, which the index never called: hnsw.rs has its own SoA layout
and its own AVX2 kernels in vector::simd. Two copies of one idea, one of them shipped and
one of them merely benchmarked. That is the shape of every bug in the 1.0 audit, so the copy
nobody ran was deleted and the abstraction over it went with it.
Sourcepub fn quantize(&self, vector: &[f32]) -> RaBitCode
pub fn quantize(&self, vector: &[f32]) -> RaBitCode
Encode a vector to its 1-bit code. See Self::encode.
Sourcepub fn dequantize(&self, quantized: &RaBitCode) -> Vec<f32>
pub fn dequantize(&self, quantized: &RaBitCode) -> Vec<f32>
Reconstruct an approximate vector from its code. Lossy (sign-only) but directionally
correct; used by [Self::distance_symmetric].
Sourcepub fn distance_quantized(&self, a: &RaBitCode, b: &RaBitCode) -> f32
pub fn distance_quantized(&self, a: &RaBitCode, b: &RaBitCode) -> f32
Distance between two codes, with one side dequantized – RaBitQ’s estimator is asymmetric, so there is no honest code-to-code distance.
Sourcepub fn distance_asymmetric(&self, query: &[f32], quantized: &RaBitCode) -> f32
pub fn distance_asymmetric(&self, query: &[f32], quantized: &RaBitCode) -> f32
Distance from a full-precision query to a code. This is the estimator the index uses,
though the hot path goes through simd::rabitq_asymmetric_l2_simd rather than here.
Trait Implementations§
Source§impl Clone for RaBitQuantizer
impl Clone for RaBitQuantizer
Source§fn clone(&self) -> RaBitQuantizer
fn clone(&self) -> RaBitQuantizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RaBitQuantizer
impl Debug for RaBitQuantizer
Source§impl<'de> Deserialize<'de> for RaBitQuantizer
impl<'de> Deserialize<'de> for RaBitQuantizer
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for RaBitQuantizer
impl RefUnwindSafe for RaBitQuantizer
impl Send for RaBitQuantizer
impl Sync for RaBitQuantizer
impl Unpin for RaBitQuantizer
impl UnsafeUnpin for RaBitQuantizer
impl UnwindSafe for RaBitQuantizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more