Skip to main content

Triplet

Struct Triplet 

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

Unique identifier for this triplet. Generated as uuid5 from edge key (deterministic).

§source_entity_id: Uuid

Source entity ID.

§target_entity_id: Uuid

Target entity ID.

§relationship_name: String

Relationship name (edge type).

§text: String

Embeddable 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

Source

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 UUID
  • target_entity_id - Target entity UUID
  • relationship_name - Relationship/edge type name
  • text - 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(),
);
Source

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 name
  • target_name - Target entity name
Source

pub fn get_text(&self) -> &str

Get embeddable text (for consistency with other models).

Trait Implementations§

Source§

impl Clone for Triplet

Source§

fn clone(&self) -> Triplet

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 Triplet

Source§

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

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

impl<'de> Deserialize<'de> for Triplet

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 Triplet

Source§

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

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 Triplet

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.