pub struct BinaryVector { /* private fields */ }Expand description
Binary quantized vector stored as packed u64 words
Implementations§
Source§impl BinaryVector
impl BinaryVector
Sourcepub fn from_f32(values: &[f32]) -> BinaryVector
pub fn from_f32(values: &[f32]) -> BinaryVector
Create a binary vector from fp32 values using sign-based quantization
Positive values become 1, negative/zero become 0
Sourcepub fn from_f32_threshold(values: &[f32], threshold: f32) -> BinaryVector
pub fn from_f32_threshold(values: &[f32], threshold: f32) -> BinaryVector
Create a binary vector from threshold-based quantization
Values above threshold become 1, below become 0
Sourcepub fn from_f32_median(values: &[f32]) -> BinaryVector
pub fn from_f32_median(values: &[f32]) -> BinaryVector
Create a binary vector from median-based quantization
Values above median become 1, below become 0. Better for non-normalized vectors.
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Get size in bytes
Sourcepub fn hamming_distance(&self, other: &BinaryVector) -> u32
pub fn hamming_distance(&self, other: &BinaryVector) -> u32
Compute Hamming distance to another binary vector
Hamming distance = number of positions where bits differ. Uses popcount which is a single CPU instruction on modern x86.
Sourcepub fn hamming_distance_normalized(&self, other: &BinaryVector) -> f32
pub fn hamming_distance_normalized(&self, other: &BinaryVector) -> f32
Compute normalized Hamming distance (0.0 to 1.0)
0.0 = identical, 1.0 = completely different
Sourcepub fn approx_cosine_similarity(&self, other: &BinaryVector) -> f32
pub fn approx_cosine_similarity(&self, other: &BinaryVector) -> f32
Convert Hamming distance to approximate cosine similarity
For normalized embeddings, there’s a relationship between Hamming distance and cosine similarity: cos_sim ≈ 1 - 2 * (hamming_dist / dim)
Trait Implementations§
Source§impl Clone for BinaryVector
impl Clone for BinaryVector
Source§fn clone(&self) -> BinaryVector
fn clone(&self) -> BinaryVector
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BinaryVector
impl RefUnwindSafe for BinaryVector
impl Send for BinaryVector
impl Sync for BinaryVector
impl Unpin for BinaryVector
impl UnsafeUnpin for BinaryVector
impl UnwindSafe for BinaryVector
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request