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
TheEpisodeType 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
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"
Represents an episode containing a JSON string object with structured data.Use cases:
- API responses
- Structured event data
- Configuration snapshots
- Telemetry data
Represents a plain text episode without special formatting requirements.Use cases:
- Document content
- Unstructured narratives
- Raw text data
- Notes or transcripts
Methods
Converts a string to the corresponding EpisodeType enum value.Parameters:
episode_type: str- String representation of the episode type (“message”, “json”, or “text”)
EpisodeType - The corresponding enum valueRaises: NotImplementedError - If the episode type string is not recognizedExample:Episode Content Formatting
Message Type
ForEpisodeType.message, content must follow the actor-content format:
JSON Type
ForEpisodeType.json, content should be a JSON string:
Text Type
ForEpisodeType.text, content can be any plain text:
Episode Processing
When episodes are added to Graphiti, they undergo several processing steps:- Content Extraction - The episode content is parsed based on its type
- Entity Extraction - Named entities are identified in the content
- Relationship Extraction - Relationships between entities are detected
- Graph Integration - New nodes and edges are created or existing ones updated
- Temporal Tracking - The
valid_attimestamp 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 theEpisodicNode 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:UUIDs of entity edges (relationships) that were extracted from this episode. This links the episode to the facts it contributed to the knowledge graph.
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.
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.messagefor conversational data where actor context is important - Use
EpisodeType.jsonfor structured data that should preserve its schema - Use
EpisodeType.textfor unstructured documents and narratives
Provide Meaningful Timestamps
Setvalid_at to the actual time the event occurred, not when it was ingested:
Use Descriptive Names and Sources
Maintain Consistent Group IDs
Use consistentgroup_id values to logically partition your knowledge graph:
Related
- EpisodicNode - The node type representing episodes
- EpisodicEdge - Edges connecting episodes to entities
- Adding Episodes Guide - Comprehensive guide to adding episodes
- Temporal Model - Understanding time in Graphiti