Skip to main content

EdgeMetadata

Struct EdgeMetadata 

Source
pub struct EdgeMetadata {
    pub relationship_type: Option<String>,
    pub weight: Option<f64>,
    pub weights: Option<HashMap<String, f64>>,
    pub properties: Option<HashMap<String, Value>>,
    pub edge_text: Option<String>,
}
Expand description

Edge metadata for relationships between DataPoints.

Matches the Python Edge(BaseModel) class. Supports single weight, multiple named weights, arbitrary properties, and an edge_text field that is auto-populated from relationship_type when not explicitly set (mirroring Python’s field_validator("edge_text") behavior).

§Examples

use cognee_models::EdgeMetadata;

// Auto-populates edge_text from relationship_type
let edge = EdgeMetadata::new(Some("contains".into()), None, None);
assert_eq!(edge.edge_text.as_deref(), Some("contains"));

// Explicit edge_text takes priority
let edge = EdgeMetadata::new(
    Some("contains".into()),
    Some(0.5),
    Some("relationship_name: contains; entity: Alice".into()),
);
assert_eq!(edge.edge_text.as_deref(), Some("relationship_name: contains; entity: Alice"));

Fields§

§relationship_type: Option<String>

Relationship type name (e.g., “works_at”, “contains”).

§weight: Option<f64>

Single weight value (backward compatible with Python’s weight field).

§weights: Option<HashMap<String, f64>>

Multiple named weights (e.g., {"strength": 0.8, "confidence": 0.9}).

§properties: Option<HashMap<String, Value>>

Arbitrary edge properties (flexible key-value storage).

§edge_text: Option<String>

Text representation for embedding. Auto-populated from relationship_type if not explicitly set (matches Python’s field_validator behavior).

Implementations§

Source§

impl EdgeMetadata

Source

pub fn new( relationship_type: Option<String>, weight: Option<f64>, edge_text: Option<String>, ) -> Self

Create a new EdgeMetadata, auto-populating edge_text from relationship_type if edge_text is not provided (matches Python’s field_validator behavior).

Source

pub fn with_all( relationship_type: Option<String>, weight: Option<f64>, weights: Option<HashMap<String, f64>>, properties: Option<HashMap<String, Value>>, edge_text: Option<String>, ) -> Self

Create an EdgeMetadata with all fields specified.

Source

pub fn ensure_edge_text(&mut self)

Auto-populate edge_text from relationship_type if edge_text is None.

This mirrors Python’s field_validator("edge_text") which sets edge_text = relationship_type when edge_text is not provided.

Trait Implementations§

Source§

impl Clone for EdgeMetadata

Source§

fn clone(&self) -> EdgeMetadata

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 EdgeMetadata

Source§

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

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

impl Default for EdgeMetadata

Source§

fn default() -> EdgeMetadata

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for EdgeMetadata

Custom Deserialize implementation that auto-populates edge_text from relationship_type after deserialization, matching Python’s field_validator behavior. This ensures that JSON like {"relationship_type": "contains"} will produce edge_text == Some("contains").

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 EdgeMetadata

Source§

fn eq(&self, other: &EdgeMetadata) -> 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 EdgeMetadata

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 EdgeMetadata

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.