pub struct Embedding {
pub vector: Vec<f32>,
pub text_hash: u64,
}Expand description
A single embedding vector with metadata.
Fields§
§vector: Vec<f32>The embedding vector (normalized to unit length).
text_hash: u64Hash of the original text for cache lookups.
Implementations§
Source§impl Embedding
impl Embedding
Sourcepub fn new(vector: Vec<f32>, text_hash: u64) -> Self
pub fn new(vector: Vec<f32>, text_hash: u64) -> Self
Create a new embedding from a vector. Automatically normalizes the vector to unit length.
Sourcepub fn from_normalized(vector: Vec<f32>, text_hash: u64) -> Self
pub fn from_normalized(vector: Vec<f32>, text_hash: u64) -> Self
Create an embedding without normalizing (assumes already normalized).
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Get the dimensionality of this embedding.
Sourcepub fn cosine_similarity(&self, other: &Embedding) -> f32
pub fn cosine_similarity(&self, other: &Embedding) -> f32
Cosine similarity with another embedding. For normalized vectors, this equals the dot product.
Sourcepub fn dot_product(&self, other: &Embedding) -> f32
pub fn dot_product(&self, other: &Embedding) -> f32
Dot product (for pre-normalized vectors, equals cosine similarity).
Sourcepub fn euclidean_distance(&self, other: &Embedding) -> f32
pub fn euclidean_distance(&self, other: &Embedding) -> f32
Euclidean distance to another embedding.
Sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Check if this embedding is normalized (unit length).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Embedding
impl<'de> Deserialize<'de> for Embedding
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
Auto Trait Implementations§
impl Freeze for Embedding
impl RefUnwindSafe for Embedding
impl Send for Embedding
impl Sync for Embedding
impl Unpin for Embedding
impl UnsafeUnpin for Embedding
impl UnwindSafe for Embedding
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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>
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