Skip to main content

Embedding

Struct Embedding 

Source
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: Uuid

UUID of the data point this embedding belongs to

§data_type: String

Type of the data point (e.g., “DocumentChunk”, “Entity”, “TextSummary”)

§field_name: String

Name 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

Source

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 point
  • data_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)
Source

pub fn dimensions(&self) -> usize

Get the dimensionality of the embedding vector.

Source

pub fn norm(&self) -> f32

Calculate L2 norm of the embedding (should be ~1.0 if normalized).

Source

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 Clone for Embedding

Source§

fn clone(&self) -> Embedding

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Embedding

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Embedding

Source§

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 PartialEq for Embedding

Source§

fn eq(&self, other: &Embedding) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Embedding

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Embedding

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.