pub enum EmbeddingVector {
Dense(Vec<f64>),
DenseF32(Vec<f32>),
Sparse(HashMap<String, f64>),
}Expand description
An embedding vector for semantic similarity comparison.
Variants§
Dense(Vec<f64>)
Dense vector from API-based embeddings (f64 for precision).
DenseF32(Vec<f32>)
Dense f32 vector (for HNSW index compatibility).
Sparse(HashMap<String, f64>)
Sparse TF-IDF vector (term → weight).
Implementations§
Source§impl EmbeddingVector
impl EmbeddingVector
Sourcepub fn cosine_similarity(&self, other: &EmbeddingVector) -> f64
pub fn cosine_similarity(&self, other: &EmbeddingVector) -> f64
Compute cosine similarity between two vectors.
Sourcepub fn to_f32_dense(&self) -> Option<Vec<f32>>
pub fn to_f32_dense(&self) -> Option<Vec<f32>>
Convert to f32 dense vector (for HNSW index).
DenseF32→ cloneDense→ cast f64 to f32Sparse→ returns None (not convertible)
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Get the dimensionality of the vector.
Trait Implementations§
Source§impl Clone for EmbeddingVector
impl Clone for EmbeddingVector
Source§fn clone(&self) -> EmbeddingVector
fn clone(&self) -> EmbeddingVector
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 EmbeddingVector
impl Debug for EmbeddingVector
Source§impl<'de> Deserialize<'de> for EmbeddingVector
impl<'de> Deserialize<'de> for EmbeddingVector
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<EmbeddingVector, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<EmbeddingVector, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for EmbeddingVector
impl Serialize for EmbeddingVector
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for EmbeddingVector
impl RefUnwindSafe for EmbeddingVector
impl Send for EmbeddingVector
impl Sync for EmbeddingVector
impl Unpin for EmbeddingVector
impl UnsafeUnpin for EmbeddingVector
impl UnwindSafe for EmbeddingVector
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