pub struct Vector {
pub dimensions: usize,
pub precision: VectorPrecision,
pub values: VectorData,
pub metadata: Option<HashMap<String, String>>,
}
Expand description
Multi-precision vector with enhanced functionality
Fields§
§dimensions: usize
§precision: VectorPrecision
§values: VectorData
§metadata: Option<HashMap<String, String>>
Implementations§
Source§impl Vector
impl Vector
Sourcepub fn pearson_correlation(&self, other: &Vector) -> Result<f32>
pub fn pearson_correlation(&self, other: &Vector) -> Result<f32>
Calculate Pearson correlation coefficient
Sourcepub fn spearman_correlation(&self, other: &Vector) -> Result<f32>
pub fn spearman_correlation(&self, other: &Vector) -> Result<f32>
Calculate Spearman rank correlation
Sourcepub fn jaccard_similarity(&self, other: &Vector) -> Result<f32>
pub fn jaccard_similarity(&self, other: &Vector) -> Result<f32>
Calculate Jaccard similarity for binary vectors
Sourcepub fn hamming_distance(&self, other: &Vector) -> Result<u32>
pub fn hamming_distance(&self, other: &Vector) -> Result<u32>
Calculate Hamming distance for binary vectors
Sourcepub fn jensen_shannon_divergence(&self, other: &Vector) -> Result<f32>
pub fn jensen_shannon_divergence(&self, other: &Vector) -> Result<f32>
Calculate Jensen-Shannon divergence
Sourcepub fn kl_divergence(&self, other: &Vector) -> Result<f32>
pub fn kl_divergence(&self, other: &Vector) -> Result<f32>
Calculate Kullback-Leibler divergence
Sourcepub fn hellinger_distance(&self, other: &Vector) -> Result<f32>
pub fn hellinger_distance(&self, other: &Vector) -> Result<f32>
Calculate Hellinger distance
Sourcepub fn earth_movers_distance(&self, other: &Vector) -> Result<f32>
pub fn earth_movers_distance(&self, other: &Vector) -> Result<f32>
Calculate Earth Mover’s Distance (1D approximation)
Sourcepub fn wasserstein_distance(&self, other: &Vector) -> Result<f32>
pub fn wasserstein_distance(&self, other: &Vector) -> Result<f32>
Calculate Wasserstein distance (1-Wasserstein, same as EMD for 1D)
Source§impl Vector
impl Vector
Sourcepub fn with_precision(values: VectorData) -> Self
pub fn with_precision(values: VectorData) -> Self
Create a new vector with specific precision
Sourcepub fn with_metadata(
values: Vec<f32>,
metadata: HashMap<String, String>,
) -> Self
pub fn with_metadata( values: Vec<f32>, metadata: HashMap<String, String>, ) -> Self
Create a new vector with metadata
Sourcepub fn quantize_to_i8(values: &[f32]) -> Vec<i8>
pub fn quantize_to_i8(values: &[f32]) -> Vec<i8>
Quantize f32 vector to i8
Sourcepub fn to_binary(values: &[f32], threshold: f32) -> Vec<u8> ⓘ
pub fn to_binary(values: &[f32], threshold: f32) -> Vec<u8> ⓘ
Convert to binary representation using threshold
Sourcepub fn cosine_similarity(&self, other: &Vector) -> Result<f32>
pub fn cosine_similarity(&self, other: &Vector) -> Result<f32>
Calculate cosine similarity with another vector
Sourcepub fn euclidean_distance(&self, other: &Vector) -> Result<f32>
pub fn euclidean_distance(&self, other: &Vector) -> Result<f32>
Calculate Euclidean distance to another vector
Sourcepub fn manhattan_distance(&self, other: &Vector) -> Result<f32>
pub fn manhattan_distance(&self, other: &Vector) -> Result<f32>
Calculate Manhattan distance (L1 norm) to another vector
Sourcepub fn minkowski_distance(&self, other: &Vector, p: f32) -> Result<f32>
pub fn minkowski_distance(&self, other: &Vector, p: f32) -> Result<f32>
Calculate Minkowski distance (general Lp norm) to another vector
Sourcepub fn chebyshev_distance(&self, other: &Vector) -> Result<f32>
pub fn chebyshev_distance(&self, other: &Vector) -> Result<f32>
Calculate Chebyshev distance (L∞ norm) to another vector
Sourcepub fn normalized(&self) -> Vector
pub fn normalized(&self) -> Vector
Get a normalized copy of this vector
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Vector
impl<'de> Deserialize<'de> for Vector
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>,
impl StructuralPartialEq for Vector
Auto Trait Implementations§
impl Freeze for Vector
impl RefUnwindSafe for Vector
impl Send for Vector
impl Sync for Vector
impl Unpin for Vector
impl UnwindSafe for Vector
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> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.