pub struct Embedding {
pub data_point_id: Uuid,
pub data_type: String,
pub field_name: String,
pub vector: Vec<f32>,
}Expand description
Embedding vector for a data point field.
Each embedding represents a specific field (e.g., “text”, “name”) of a data point (e.g., DocumentChunk, Entity) as a dense vector.
§Examples
use cognee_models::Embedding;
use uuid::Uuid;
let chunk_id = Uuid::new_v4();
let embedding = Embedding::new(
chunk_id,
"DocumentChunk",
"text",
vec![0.1, 0.2, 0.3], // Dense vector
);
assert_eq!(embedding.dimensions(), 3);
assert_eq!(embedding.field_name, "text");Fields§
§data_point_id: UuidUUID of the data point this embedding belongs to
data_type: StringType of the data point (e.g., “DocumentChunk”, “Entity”, “TextSummary”)
field_name: StringName of the field that was embedded (e.g., “text”, “name”, “content”)
vector: Vec<f32>Dense embedding vector (f32 for compatibility with most vector DBs)
Implementations§
Source§impl Embedding
impl Embedding
Sourcepub fn new(
data_point_id: Uuid,
data_type: impl Into<String>,
field_name: impl Into<String>,
vector: Vec<f32>,
) -> Self
pub fn new( data_point_id: Uuid, data_type: impl Into<String>, field_name: impl Into<String>, vector: Vec<f32>, ) -> Self
Create a new embedding.
§Arguments
data_point_id- UUID of the source data pointdata_type- Type discriminator (e.g., “DocumentChunk”)field_name- Field that was embedded (e.g., “text”)vector- Dense embedding vector (usually 384, 768, or 1536 dimensions)
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Get the dimensionality of the embedding vector.
Sourcepub fn cosine_similarity(&self, other: &Embedding) -> Option<f32>
pub fn cosine_similarity(&self, other: &Embedding) -> Option<f32>
Calculate cosine similarity with another embedding.
Both embeddings must be normalized (L2 norm = 1.0). Returns dot product in range [-1.0, 1.0].
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
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 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