pub struct Triplet {
pub id: Uuid,
pub source_entity_id: Uuid,
pub target_entity_id: Uuid,
pub relationship_name: String,
pub text: String,
pub source_name: Option<String>,
pub target_name: Option<String>,
}Expand description
A triplet representing a semantic relationship between two entities.
Triplets are embedded as text in the format: “source_text-›relationship_text-›target_text”
Example: “Steve Jobs: Co-founder of Apple-›founded-›Apple Inc.: Technology company”
Python reference: cognee/modules/engine/models/Triplet.py
Fields§
§id: UuidUnique identifier for this triplet. Generated as uuid5 from edge key (deterministic).
source_entity_id: UuidSource entity ID.
target_entity_id: UuidTarget entity ID.
relationship_name: StringRelationship name (edge type).
text: StringEmbeddable text representation. Format: “{source_text}-›{relationship_text}-›{target_text}” This is the text that gets embedded for semantic search.
source_name: Option<String>Optional: Source entity name for display/debugging.
target_name: Option<String>Optional: Target entity name for display/debugging.
Implementations§
Source§impl Triplet
impl Triplet
Sourcepub fn new(
source_entity_id: Uuid,
target_entity_id: Uuid,
relationship_name: String,
text: String,
) -> Self
pub fn new( source_entity_id: Uuid, target_entity_id: Uuid, relationship_name: String, text: String, ) -> Self
Create a new triplet with deterministic ID.
The ID is generated using UUID v5 from the edge key, matching Python’s behavior.
§Arguments
source_entity_id- Source entity UUIDtarget_entity_id- Target entity UUIDrelationship_name- Relationship/edge type nametext- Formatted text for embedding
§Example
use cognee_models::Triplet;
use uuid::Uuid;
let source_id = Uuid::new_v4();
let target_id = Uuid::new_v4();
let triplet = Triplet::new(
source_id,
target_id,
"founded".to_string(),
"Steve Jobs-›founded-›Apple Inc.".to_string(),
);Sourcepub fn with_names(self, source_name: String, target_name: String) -> Self
pub fn with_names(self, source_name: String, target_name: String) -> Self
Set source and target names for display purposes.
§Arguments
source_name- Source entity nametarget_name- Target entity name