pub struct Embedding {
pub values: Vec<f32>,
pub metadata: HashMap<String, Value>,
}
Expand description
A text embedding
Fields§
§values: Vec<f32>
The embedding vector
metadata: HashMap<String, Value>
Metadata about the embedding
Implementations§
Source§impl Embedding
impl Embedding
Sourcepub fn new_with_metadata(
values: Vec<f32>,
metadata: HashMap<String, Value>,
) -> Self
pub fn new_with_metadata( values: Vec<f32>, metadata: HashMap<String, Value>, ) -> Self
Create a new embedding with metadata
Sourcepub fn cosine_similarity(&self, other: &Embedding) -> f32
pub fn cosine_similarity(&self, other: &Embedding) -> f32
Calculate cosine similarity with another embedding
Sourcepub fn euclidean_distance(&self, other: &Embedding) -> f32
pub fn euclidean_distance(&self, other: &Embedding) -> f32
Calculate Euclidean distance to another embedding
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
Source§impl Serializable for Embedding
impl Serializable for Embedding
Source§fn is_serializable() -> bool
fn is_serializable() -> bool
Check if this object is serializable Read more
Source§fn to_json_pretty(&self) -> Result<String>
fn to_json_pretty(&self) -> Result<String>
Serialize this object to a pretty-printed JSON string
Source§fn to_dict(&self) -> Result<HashMap<String, Value>>
fn to_dict(&self) -> Result<HashMap<String, Value>>
Serialize this object to a dictionary (HashMap)
impl StructuralPartialEq for Embedding
Auto Trait Implementations§
impl Freeze for Embedding
impl RefUnwindSafe for Embedding
impl Send for Embedding
impl Sync for Embedding
impl Unpin 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