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
impl EdgeMetadata
Sourcepub fn new(
relationship_type: Option<String>,
weight: Option<f64>,
edge_text: Option<String>,
) -> Self
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).
Sourcepub 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
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.
Sourcepub fn ensure_edge_text(&mut self)
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
impl Clone for EdgeMetadata
Source§fn clone(&self) -> EdgeMetadata
fn clone(&self) -> EdgeMetadata
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EdgeMetadata
impl Debug for EdgeMetadata
Source§impl Default for EdgeMetadata
impl Default for EdgeMetadata
Source§fn default() -> EdgeMetadata
fn default() -> EdgeMetadata
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").
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>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl PartialEq for EdgeMetadata
impl PartialEq for EdgeMetadata
Source§fn eq(&self, other: &EdgeMetadata) -> bool
fn eq(&self, other: &EdgeMetadata) -> bool
self and other values to be equal, and is used by ==.