Skip to main content

Episodes

Episodes are the fundamental units of input data in Graphiti. They represent events, messages, documents, or other temporal data that gets processed and integrated into the knowledge graph.

EpisodeType Enum

The EpisodeType enum defines the various sources or formats of episodes that Graphiti can handle. The type determines how the episode content should be interpreted and processed.

Enum Values

str
Represents a standard message-type episode. The content for this type should be formatted as "actor: content".Examples:
  • "user: Hello, how are you?"
  • "assistant: I'm doing well, thank you for asking."
  • "system: User logged in at 10:30 AM"
str
Represents an episode containing a JSON string object with structured data.Use cases:
  • API responses
  • Structured event data
  • Configuration snapshots
  • Telemetry data
str
Represents a plain text episode without special formatting requirements.Use cases:
  • Document content
  • Unstructured narratives
  • Raw text data
  • Notes or transcripts

Methods

static method
Converts a string to the corresponding EpisodeType enum value.Parameters:
  • episode_type: str - String representation of the episode type (“message”, “json”, or “text”)
Returns: EpisodeType - The corresponding enum valueRaises: NotImplementedError - If the episode type string is not recognizedExample:

Episode Content Formatting

Message Type

For EpisodeType.message, content must follow the actor-content format:

JSON Type

For EpisodeType.json, content should be a JSON string:

Text Type

For EpisodeType.text, content can be any plain text:

Episode Processing

When episodes are added to Graphiti, they undergo several processing steps:
  1. Content Extraction - The episode content is parsed based on its type
  2. Entity Extraction - Named entities are identified in the content
  3. Relationship Extraction - Relationships between entities are detected
  4. Graph Integration - New nodes and edges are created or existing ones updated
  5. Temporal Tracking - The valid_at timestamp is used for temporal queries

Working with Episodes

Adding Episodes

Episodes are typically added through the main Graphiti interface:

Retrieving Episodes

Episodes can be retrieved using the EpisodicNode class methods:

Episode Relationships

Episodes form several types of relationships in the graph:
  • MENTIONS edges - Connect episodes to the entities they reference (see EpisodicEdge)
  • NEXT_EPISODE edges - Chain episodes in temporal sequence (see NextEpisodeEdge)
  • HAS_EPISODE edges - Group episodes into sagas (see HasEpisodeEdge)

Episode Metadata

Beyond the core fields, episodes track important metadata:
list[str]
UUIDs of entity edges (relationships) that were extracted from this episode. This links the episode to the facts it contributed to the knowledge graph.
datetime
The timestamp when the episode occurred or when the document was created. This is crucial for temporal queries and understanding the evolution of the knowledge graph over time.
str
Human-readable description of where the episode came from (e.g., “Slack conversation”, “Email thread”, “Meeting transcript”). Helps track data provenance.

Best Practices

Choose the Right Type

  • Use EpisodeType.message for conversational data where actor context is important
  • Use EpisodeType.json for structured data that should preserve its schema
  • Use EpisodeType.text for unstructured documents and narratives

Provide Meaningful Timestamps

Set valid_at to the actual time the event occurred, not when it was ingested:

Use Descriptive Names and Sources

Maintain Consistent Group IDs

Use consistent group_id values to logically partition your knowledge graph: