Deleting Data from the Graph

Delete an Edge

Here’s how to delete an edge from a graph:

1from zep_cloud.client import Zep
2
3client = Zep(
4 api_key=API_KEY,
5)
6
7client.graph.edge.delete(uuid_="your_edge_uuid")

Note that when you delete an edge, it never deletes the associated nodes, even if it means there will be a node with no edges.

Delete a Node

Here’s how to delete a node from a graph:

1from zep_cloud.client import Zep
2
3client = Zep(
4 api_key=API_KEY,
5)
6
7client.graph.node.delete(uuid_="your_node_uuid")

Deleting a node will also delete all edges connected to that node. This is a cascading delete operation - the node and all its relationships are permanently removed from the graph.

Delete an Episode

Deleting an episode does not regenerate the names or summaries of nodes shared with other episodes. This episode information may still exist within these nodes. If an episode invalidates a fact, and the episode is deleted, the fact will remain marked as invalidated.

When you delete an episode:

  • Edges are deleted only if no other episodes are associated with them. An edge associated with other episodes will be preserved.
  • Nodes are deleted only if no other episodes are associated with them. A node associated with other episodes will be preserved.

Here’s how to delete an episode from a graph:

1from zep_cloud.client import Zep
2
3client = Zep(
4 api_key=API_KEY,
5)
6
7client.graph.episode.delete(uuid_="episode_uuid")

How episodes become associated with edges and nodes

Both edges and nodes track which episodes they are associated with:

  • Nodes gain an episode association each time the entity they represent is mentioned in that episode. For example, if a user mentions “Paris” in three separate conversations, the “Paris” node will be associated with three episodes.
  • Edges gain an episode association in two ways: the episode that originally extracted the relationship creates the edge, and later episodes are appended as additional references if they either reaffirm the same fact (marked as a duplicate) or invalidate the edge.

During deletion, edges and nodes follow a similar rule: edges are deleted only if no other episodes are associated with them, and nodes are deleted only if no other episodes are associated with them.

You can inspect these associations using the API:

  • Edge → episodes: The episodes field on an edge object is a list of episode UUIDs associated with that edge.
  • Node → episodes: Use the get episodes for a node endpoint to retrieve all episodes that mention a given node.
  • Episode → nodes and edges: Use the get episode mentions endpoint to retrieve all nodes and edges mentioned in an episode.

Delete a Thread

Deleting a thread removes all episodes associated with that thread. This triggers a cascading effect on the graph.

When a thread is deleted, each associated episode is removed. For each episode:

  • Edges are deleted only if no other episodes are associated with them
  • Nodes are deleted only if no other episodes are associated with them

This design preserves graph integrity. If multiple conversations mention the same entity or establish the same relationship, deleting one thread will not remove data that other threads contributed to the graph.

Here’s how to delete a thread:

1from zep_cloud.client import Zep
2
3client = Zep(
4 api_key=API_KEY,
5)
6
7client.thread.delete(thread_id="your_thread_id")