pub struct Embedding {
pub vector: EmbeddingVector,
pub dimensions: usize,
pub model: String,
pub source_id: String,
pub metadata: HashMap<String, Value>,
pub created_at: DateTime<Utc>,
}Expand description
A dense vector representation of text content with metadata
Embeddings are high-dimensional vectors that capture semantic meaning of text in a format suitable for similarity comparison and retrieval. Each embedding includes the vector data, source information, and generation metadata.
§Example
use rrag::prelude::*;
let vector = vec![0.1, -0.2, 0.3, 0.4]; // 4-dimensional example
let embedding = Embedding::new(vector, "text-embedding-ada-002", "doc-123")
.with_metadata("content_type", "paragraph".into())
.with_metadata("language", "en".into());
assert_eq!(embedding.dimensions, 4);
assert_eq!(embedding.model, "text-embedding-ada-002");Fields§
§vector: EmbeddingVectorThe actual embedding vector
dimensions: usizeDimensions of the embedding
model: StringModel used to generate this embedding
source_id: StringSource content identifier
metadata: HashMap<String, Value>Embedding metadata
created_at: DateTime<Utc>Generation timestamp
Implementations§
Source§impl Embedding
impl Embedding
Sourcepub fn new(
vector: EmbeddingVector,
model: impl Into<String>,
source_id: impl Into<String>,
) -> Self
pub fn new( vector: EmbeddingVector, model: impl Into<String>, source_id: impl Into<String>, ) -> Self
Create a new embedding
Sourcepub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
Add metadata using builder pattern
Sourcepub fn cosine_similarity(&self, other: &Embedding) -> RragResult<f32>
pub fn cosine_similarity(&self, other: &Embedding) -> RragResult<f32>
Calculate cosine similarity with another embedding
Sourcepub fn euclidean_distance(&self, other: &Embedding) -> RragResult<f32>
pub fn euclidean_distance(&self, other: &Embedding) -> RragResult<f32>
Calculate Euclidean distance with 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
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