pub struct BinaryQuantizer { /* private fields */ }Expand description
Binary quantization: f32 → bit
Maps each dimension to a single bit based on sign (positive = 1, negative = 0). Provides 32x memory reduction. Best used for initial filtering with reranking.
Distance is computed using Hamming distance (number of differing bits).
§Example
use foxstash_core::vector::quantize::{BinaryQuantizer, Quantizer};
let quantizer = BinaryQuantizer::new(128);
let vec_a = vec![0.5; 128]; // All positive → all 1s
let vec_b = vec![-0.5; 128]; // All negative → all 0s
let qa = quantizer.quantize(&vec_a);
let qb = quantizer.quantize(&vec_b);
// Maximum Hamming distance (all bits differ)
let distance = quantizer.distance_quantized(&qa, &qb);
assert_eq!(distance, 128.0);Implementations§
Trait Implementations§
Source§impl Clone for BinaryQuantizer
impl Clone for BinaryQuantizer
Source§fn clone(&self) -> BinaryQuantizer
fn clone(&self) -> BinaryQuantizer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BinaryQuantizer
impl Debug for BinaryQuantizer
Source§impl<'de> Deserialize<'de> for BinaryQuantizer
impl<'de> Deserialize<'de> for BinaryQuantizer
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Quantizer for BinaryQuantizer
impl Quantizer for BinaryQuantizer
Source§type Quantized = BinaryQuantizedVector
type Quantized = BinaryQuantizedVector
Quantized representation type
Auto Trait Implementations§
impl Freeze for BinaryQuantizer
impl RefUnwindSafe for BinaryQuantizer
impl Send for BinaryQuantizer
impl Sync for BinaryQuantizer
impl Unpin for BinaryQuantizer
impl UnsafeUnpin for BinaryQuantizer
impl UnwindSafe for BinaryQuantizer
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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