Skip to main content

Edge Types

Graphiti uses five edge types to represent different kinds of relationships in the knowledge graph. All edges inherit from the base Edge class and share common fields for identification, grouping, and timestamps.

Base Edge

The abstract base class that all edge types inherit from.
uuid
str
required
Unique identifier for the edge. Automatically generated using UUID4 if not provided.
group_id
str
required
Partition identifier for the graph. Used to organize edges into logical groups or namespaces.
source_node_uuid
str
required
UUID of the source node in this relationship.
target_node_uuid
str
required
UUID of the target node in this relationship.
created_at
datetime
required
Timestamp of when the edge was created.

EntityEdge

Represents a RELATES_TO relationship between two entity nodes, containing a fact about their relationship.

Fields

Inherits all fields from Edge, plus:
name
str
required
Name of the edge, describing the relation type (e.g., “works_at”, “located_in”, “friend_of”).
fact
str
required
A factual statement representing the edge and the nodes it connects. This is the semantic content of the relationship.
fact_embedding
list[float] | None
Vector embedding of the fact, used for semantic similarity searches. Generated using the configured embedder client.
episodes
list[str]
List of episode UUIDs that reference or mention this entity edge. Default: empty list.
expired_at
datetime | None
Timestamp of when the edge was invalidated or marked as expired.
valid_at
datetime | None
Timestamp of when the fact became true or valid.
invalid_at
datetime | None
Timestamp of when the fact stopped being true.
attributes
dict[str, Any]
Additional attributes of the edge. Content depends on the edge name and can store custom properties. Default: empty dict.

Methods

generate_embedding
async method
Generates and stores the fact embedding for this edge.Parameters:
  • embedder: EmbedderClient - The embedder client to use for generating embeddings
Returns: list[float] - The generated embedding vector
load_fact_embedding
async method
Loads the fact embedding from the graph database.Parameters:
  • driver: GraphDriver - The graph driver instance
Raises: EdgeNotFoundError if the edge doesn’t exist
save
async method
Persists the entity edge to the graph database.Parameters:
  • driver: GraphDriver - The graph driver instance

Class Methods

get_by_uuid
async classmethod
Retrieves a single entity edge by UUID.Parameters:
  • driver: GraphDriver
  • uuid: str
Returns: EntityEdgeRaises: EdgeNotFoundError if not found
get_by_uuids
async classmethod
Retrieves multiple entity edges by UUIDs.Parameters:
  • driver: GraphDriver
  • uuids: list[str]
Returns: list[EntityEdge]
get_between_nodes
async classmethod
Retrieves all entity edges between two specific nodes.Parameters:
  • driver: GraphDriver
  • source_node_uuid: str - UUID of the source entity node
  • target_node_uuid: str - UUID of the target entity node
Returns: list[EntityEdge]
get_by_node_uuid
async classmethod
Retrieves all entity edges connected to a specific node.Parameters:
  • driver: GraphDriver
  • node_uuid: str - UUID of the entity node
Returns: list[EntityEdge]
get_by_group_ids
async classmethod
Retrieves entity edges by group IDs with optional pagination.Parameters:
  • driver: GraphDriver
  • group_ids: list[str]
  • limit: int | None - Maximum number of results (optional)
  • uuid_cursor: str | None - UUID cursor for pagination (optional)
  • with_embeddings: bool - Whether to include embeddings (default: False)
Returns: list[EntityEdge]Raises: GroupsEdgesNotFoundError if no edges found

EpisodicEdge

Represents a MENTIONS relationship from an episodic node to an entity node, indicating that the episode mentions the entity.

Fields

Inherits all fields from Edge with no additional fields.

Methods

save
async method
Persists the episodic edge to the graph database.Parameters:
  • driver: GraphDriver - The graph driver instance

Class Methods

get_by_uuid
async classmethod
Retrieves a single episodic edge by UUID.Parameters:
  • driver: GraphDriver
  • uuid: str
Returns: EpisodicEdgeRaises: EdgeNotFoundError if not found
get_by_uuids
async classmethod
Retrieves multiple episodic edges by UUIDs.Parameters:
  • driver: GraphDriver
  • uuids: list[str]
Returns: list[EpisodicEdge]Raises: EdgeNotFoundError if not found
get_by_group_ids
async classmethod
Retrieves episodic edges by group IDs with optional pagination.Parameters:
  • driver: GraphDriver
  • group_ids: list[str]
  • limit: int | None - Maximum number of results (optional)
  • uuid_cursor: str | None - UUID cursor for pagination (optional)
Returns: list[EpisodicEdge]Raises: GroupsEdgesNotFoundError if no edges found

CommunityEdge

Represents a HAS_MEMBER relationship from a community node to an entity node, indicating that the entity is a member of the community.

Fields

Inherits all fields from Edge with no additional fields.

Methods

save
async method
Persists the community edge to the graph database.Parameters:
  • driver: GraphDriver - The graph driver instance

Class Methods

get_by_uuid
async classmethod
Retrieves a single community edge by UUID.Parameters:
  • driver: GraphDriver
  • uuid: str
Returns: CommunityEdge
get_by_uuids
async classmethod
Retrieves multiple community edges by UUIDs.Parameters:
  • driver: GraphDriver
  • uuids: list[str]
Returns: list[CommunityEdge]
get_by_group_ids
async classmethod
Retrieves community edges by group IDs with optional pagination.Parameters:
  • driver: GraphDriver
  • group_ids: list[str]
  • limit: int | None - Maximum number of results (optional)
  • uuid_cursor: str | None - UUID cursor for pagination (optional)
Returns: list[CommunityEdge]

HasEpisodeEdge

Represents a HAS_EPISODE relationship from a saga node to an episodic node, indicating that the episode is part of the saga.

Fields

Inherits all fields from Edge with no additional fields.

Methods

save
async method
Persists the has-episode edge to the graph database.Parameters:
  • driver: GraphDriver - The graph driver instance
delete
async method
Deletes the has-episode edge from the graph database.Parameters:
  • driver: GraphDriver - The graph driver instance

Class Methods

get_by_uuid
async classmethod
Retrieves a single has-episode edge by UUID.Parameters:
  • driver: GraphDriver
  • uuid: str
Returns: HasEpisodeEdgeRaises: EdgeNotFoundError if not found
get_by_uuids
async classmethod
Retrieves multiple has-episode edges by UUIDs.Parameters:
  • driver: GraphDriver
  • uuids: list[str]
Returns: list[HasEpisodeEdge]
get_by_group_ids
async classmethod
Retrieves has-episode edges by group IDs with optional pagination.Parameters:
  • driver: GraphDriver
  • group_ids: list[str]
  • limit: int | None - Maximum number of results (optional)
  • uuid_cursor: str | None - UUID cursor for pagination (optional)
Returns: list[HasEpisodeEdge]

NextEpisodeEdge

Represents a NEXT_EPISODE relationship from one episodic node to another, forming a sequential chain of episodes.

Fields

Inherits all fields from Edge with no additional fields.

Methods

save
async method
Persists the next-episode edge to the graph database.Parameters:
  • driver: GraphDriver - The graph driver instance
delete
async method
Deletes the next-episode edge from the graph database.Parameters:
  • driver: GraphDriver - The graph driver instance

Class Methods

get_by_uuid
async classmethod
Retrieves a single next-episode edge by UUID.Parameters:
  • driver: GraphDriver
  • uuid: str
Returns: NextEpisodeEdgeRaises: EdgeNotFoundError if not found
get_by_uuids
async classmethod
Retrieves multiple next-episode edges by UUIDs.Parameters:
  • driver: GraphDriver
  • uuids: list[str]
Returns: list[NextEpisodeEdge]
get_by_group_ids
async classmethod
Retrieves next-episode edges by group IDs with optional pagination.Parameters:
  • driver: GraphDriver
  • group_ids: list[str]
  • limit: int | None - Maximum number of results (optional)
  • uuid_cursor: str | None - UUID cursor for pagination (optional)
Returns: list[NextEpisodeEdge]

Common Edge Operations

All edge types support the following operations:

Delete Operations

delete
async method
Deletes the edge from the graph database.Parameters:
  • driver: GraphDriver - The graph driver instance
delete_by_uuids
async classmethod
Deletes multiple edges by their UUIDs.Parameters:
  • driver: GraphDriver
  • uuids: list[str]

Helper Functions

create_entity_edge_embeddings
async function
Batch generates embeddings for multiple entity edges.Parameters:
  • embedder: EmbedderClient
  • edges: list[EntityEdge]
Filters out edges with empty facts and generates embeddings for the remaining edges in batch.

Graph Relationship Types

The following relationship types are used in the graph database:
  • RELATES_TO - EntityEdge connecting two entity nodes
  • MENTIONS - EpisodicEdge from an episode to an entity it mentions
  • HAS_MEMBER - CommunityEdge from a community to a member entity
  • HAS_EPISODE - HasEpisodeEdge from a saga to an episode
  • NEXT_EPISODE - NextEpisodeEdge linking sequential episodes
  • Node Types - Learn about node types in the graph
  • Episodes - Learn about episode types and processing
  • Search - Search across edges in the knowledge graph

Build docs developers (and LLMs) love