pub struct BinaryQuantizedVector {
pub data: Vec<u8>,
/* private fields */
}Expand description
A binary quantized vector using 1-bit per dimension.
Each f32 value is converted to 1 bit: >= 0.0 becomes 1, < 0.0 becomes 0. This provides 32x memory reduction compared to f32 storage.
§Memory Usage
| Dimension | f32 | Binary |
|---|---|---|
| 768 | 3072 bytes | 96 bytes |
| 1536 | 6144 bytes | 192 bytes |
§Use with Rescoring
For best accuracy, use binary search for candidate selection, then rescore top candidates with full-precision vectors.
Fields§
§data: Vec<u8>Binary data (1 bit per dimension, packed into bytes).
Implementations§
Source§impl BinaryQuantizedVector
impl BinaryQuantizedVector
Sourcepub fn memory_size(&self) -> usize
pub fn memory_size(&self) -> usize
Returns the memory size in bytes.
Sourcepub fn get_bits(&self) -> Vec<bool>
pub fn get_bits(&self) -> Vec<bool>
Returns the individual bits as a boolean vector.
Useful for debugging and testing.
Sourcepub fn hamming_distance(&self, other: &Self) -> u32
pub fn hamming_distance(&self, other: &Self) -> u32
Computes the Hamming distance to another binary vector.
Hamming distance counts the number of bits that differ. Uses POPCNT for fast bit counting.
§Panics
Panics if the vectors have different dimensions.
Sourcepub fn hamming_similarity(&self, other: &Self) -> f32
pub fn hamming_similarity(&self, other: &Self) -> f32
Computes normalized Hamming similarity (0.0 to 1.0).
Returns 1.0 for identical vectors, 0.0 for completely different.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Deserializes a binary quantized vector from bytes.
§Errors
Returns an error if the bytes are invalid.
Trait Implementations§
Source§impl Clone for BinaryQuantizedVector
impl Clone for BinaryQuantizedVector
Source§fn clone(&self) -> BinaryQuantizedVector
fn clone(&self) -> BinaryQuantizedVector
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BinaryQuantizedVector
impl RefUnwindSafe for BinaryQuantizedVector
impl Send for BinaryQuantizedVector
impl Sync for BinaryQuantizedVector
impl Unpin for BinaryQuantizedVector
impl UnwindSafe for BinaryQuantizedVector
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,
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