> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs-beta.getzep.com/v2/graphiti/core-concepts/adding-episodes/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs-beta.getzep.com/_mcp/server. # Adding Episodes > **Note** > > Refer to the [Custom Entity Types](/graphiti/core-concepts/custom-entity-and-edge-types) page for detailed instructions on adding user-defined ontology to your graph. ### Adding Episodes Episodes represent a single data ingestion event. An `episode` is itself a node, and any nodes identified while ingesting the episode are related to the episode via `MENTIONS` edges. Episodes enable querying for information at a point in time and understanding the provenance of nodes and their edge relationships. Supported episode types: * `text`: Unstructured text data * `message`: Conversational messages of the format `speaker: message...` * `json`: Structured data, processed distinctly from the other types The graph below was generated using the code in the [Quick Start](/graphiti/getting-started/quick-start). Each **podcast** is an individual episode. ![Simple Graph Visualization](https://raw.githubusercontent.com/getzep/graphiti/main/images/simple_graph.svg) #### Adding a `text` or `message` Episode Using the `EpisodeType.text` type: ```python await graphiti.add_episode( name="tech_innovation_article", episode_body=( "MIT researchers have unveiled 'ClimateNet', an AI system capable of predicting " "climate patterns with unprecedented accuracy. Early tests show it can forecast " "major weather events up to three weeks in advance, potentially revolutionizing " "disaster preparedness and agricultural planning." ), source=EpisodeType.text, # A description of the source (e.g., "podcast", "news article") source_description="Technology magazine article", # The timestamp for when this episode occurred or was created reference_time=datetime(2023, 11, 15, 9, 30), ) ``` Using the `EpisodeType.message` type supports passing in multi-turn conversations in the `episode_body`. The text should be structured in `{role/name}: {message}` pairs. ```python await graphiti.add_episode( name="Customer_Support_Interaction_1", episode_body=( "Customer: Hi, I'm having trouble with my Allbirds shoes. " "The sole is coming off after only 2 months of use.\n" "Support: I'm sorry to hear that. Can you please provide your order number?" ), source=EpisodeType.message, source_description="Customer support chat", reference_time=datetime(2024, 3, 15, 14, 45), ) ``` #### Adding an Episode using structured data in JSON format JSON documents can be arbitrarily nested. However, it's advisable to keep documents compact, as they must fit within your LLM's context window. > **Note** > > For large data imports, consider using the `add_episode_bulk` API to > add multiple episodes in one call. ```python import json product_data = { "id": "PROD001", "name": "Men's SuperLight Wool Runners", "color": "Dark Grey", "sole_color": "Medium Grey", "material": "Wool", "technology": "SuperLight Foam", "price": 125.00, "in_stock": True, "last_updated": "2024-03-15T10:30:00Z" } # Add the episode to the graph await graphiti.add_episode( name="Product Update - PROD001", episode_body=json.dumps(product_data), # episode_body must be a JSON string, not a dict source=EpisodeType.json, source_description="Allbirds product catalog update", reference_time=datetime.now(), ) ``` #### Loading Episodes in Bulk Graphiti offers `add_episode_bulk` to add multiple episodes in one batch. Use this method for bulk loading. The bulk path resolves invalidated edges and extracts temporal dates before it saves the results. ```python import json from datetime import datetime, timezone from graphiti_core.nodes import EpisodeType from graphiti_core.utils.bulk_utils import RawEpisode product_data = [ { "id": "PROD001", "name": "Men's SuperLight Wool Runners", "color": "Dark Grey", "sole_color": "Medium Grey", "material": "Wool", "technology": "SuperLight Foam", "price": 125.00, "in_stock": True, "last_updated": "2024-03-15T10:30:00Z" }, { "id": "PROD0100", "name": "Kids Wool Runner-up Mizzles", "color": "Natural Grey", "sole_color": "Orange", "material": "Wool", "technology": "Water-repellent", "price": 80.00, "in_stock": True, "last_updated": "2024-03-17T14:45:00Z" } ] bulk_episodes = [ RawEpisode( name=f"Product Update - {product['id']}", content=json.dumps(product), source=EpisodeType.json, source_description="Allbirds product catalog update", reference_time=datetime.now(timezone.utc), ) for product in product_data ] await graphiti.add_episode_bulk(bulk_episodes) ``` > How to add data to your Graphiti graph