Graphiti: Temporal Graph Building Library

repository·main·Indexed 12 days ago

https://github.com/getzep/graphiti

A framework for building and querying temporal context graphs for AI agents, enabling dynamic memory that tracks how facts change over time. Graphiti supports hybrid search (semantic, BM25, and graph traversal) and integrates with Neo4j, FalkorDB, and Amazon Neptune. It provides a core library (graphiti-core v0.29.3) and an MCP server, with support for various LLM providers including OpenAI, Azure OpenAI, Anthropic, and Groq, as well as experimental GLiNER2 hybrid entity extraction.

Tokens
41.1K
Snippets
134
Records
174
Agent score
98%

What's inside Graphiti

  1. Overview of the Graphiti MCP Server

    main

    The Graphiti MCP Server is an experimental implementation of the Model Context Protocol (MCP) that exposes Graphiti's knowledge graph capabilities to AI assistants. It allows agents to interact with a temporally-aware knowledge graph that continuously integrates user interactions, structured/unstructured data, and external information.

    Key capabilities include:

    • Episode Management: Add, retrieve, and delete episodes (text, messages, or JSON).
    • Entity Management: Search and manage entity nodes and relationships.
    • Search: Semantic and hybrid search for facts (edges) and node summaries.
    • Group Management: Organize data using group_id filtering.
    • Graph Maintenance: Clear the graph and rebuild indices.
    • Database Support: Supports FalkorDB (default) and Neo4j.
    • Provider Support: Multiple LLM (OpenAI, Anthropic, Gemini, Groq, Azure OpenAI) and Embedding (OpenAI, Voyage, Sentence Transformers, Gemini) providers.
  2. What is Graphiti and how does it work?

    main

    Graphiti is a framework for building and querying temporal context graphs for AI agents. Unlike static knowledge graphs or traditional RAG (Retrieval-Augmented Generation) which rely on batch processing and static document chunks, Graphiti is designed for dynamic, evolving data.

    Key Capabilities:

    • Temporal Fact Management: Tracks how facts change over time using validity windows. When information changes, old facts are invalidated rather than deleted, allowing you to query what was true at any specific point in time.
    • Incremental Updates: Integrates new data (episodes) immediately without requiring full graph recomputation.
    • Hybrid Retrieval: Uses a combination of semantic embeddings, keyword (BM25) search, and graph traversal for high-precision, low-latency queries.
    • Provenance: Every entity and relationship traces back to the original episodes (raw data) that produced it.
    • Flexible Ontology: Supports both prescribed ontology (defining entity and edge types upfront via Pydantic models) and learned ontology (allowing structure to emerge from data).
  3. Graphiti vs. GraphRAG

    main

    While both involve graphs, Graphiti is optimized for agentic, real-time workflows compared to the batch-oriented nature of GraphRAG:

    AspectGraphRAGGraphiti
    Primary UseStatic document summarizationDynamic, evolving context for agents
    Data HandlingBatch-oriented processingContinuous, incremental updates
    Temporal HandlingBasic timestamp trackingExplicit bi-temporal tracking with automatic fact invalidation
    Query LatencySeconds to tens of secondsTypically sub-second latency
    Custom Entity TypesNoYes, customizable via Pydantic models
  4. Tune concurrency with SEMAPHORE_LIMIT

    main

    Graphiti's ingestion pipelines use the SEMAPHORE_LIMIT environment variable to control how many episodes are processed simultaneously. Because each episode triggers multiple LLM calls, you must tune this value based on your LLM provider's rate limits to avoid 429 errors.

    Default: SEMAPHORE_LIMIT=10

    Tuning Guidelines

    • OpenAI Tier 1 (Free): 1-2
    • OpenAI Tier 2 (60 RPM): 5-8
    • OpenAI Tier 3 (500 RPM): 10-15
    • Anthropic (50 RPM): 5-8
    • Ollama (Local): 1-5 (Hardware dependent)

    Set this in your .env file:

    SEMAPHORE_LIMIT=10
  5. Configure GLiNER2 Hybrid LLM Client

    main

    The GLiNER2Client is an experimental hybrid client that performs local entity extraction via GLiNER2 and uses a standard LLMClient for edge/fact extraction, deduplication, and summarization.

    Configuration Parameters

    ParameterDescriptionDefault
    thresholdGLiNER2 confidence threshold (0.0-1.0). Higher values reduce spurious extractions.0.5
    GLINER2_MODELHuggingFace model ID (e.g., fastino/gliner2-base-v1, fastino/gliner2-large-v1, or fastino/gliner2-multi-v1).fastino/gliner2-large-v1

    Swapping LLM and Embedding Providers

    The GLiNER2Client accepts any Graphiti LLMClient. You can replace the default Gemini providers with other supported clients:

    LLM Clients:

    • graphiti_core.llm_client.openai_client.OpenAIClient
    • graphiti_core.llm_client.anthropic_client.AnthropicClient
    • graphiti_core.llm_client.groq_client.GroqClient

    Embedders:

    • graphiti_core.embedder.openai.OpenAIEmbedder
    • graphiti_core.embedder.voyage.VoyageAIEmbedder
  6. How the Graphiti Driver and Operations architecture works

    main

    Graphiti uses a layered architecture to separate high-level orchestration from low-level database operations.

    1. GraphDriver (Layer 2): An abstract base class that inherits from QueryExecutor. It composes various specialized operation interfaces (e.g., EntityNodeOperations, SearchOperations) via properties. This allows the driver to support different database backends (like Neo4j or FalkorDB) by implementing these specific operation sets.

    2. Namespace Wrappers (Layer 3): Thin wrappers on the Graphiti client that orchestrate non-database concerns (like generating embeddings via an EmbedderClient) before delegating the actual database work to the driver's operations. These are accessed via graphiti.nodes and graphiti.edges.

    3. Graphiti Client: The primary entry point that wires together the GraphDriver, the EmbedderClient, and the NodeNamespace/EdgeNamespace wrappers.

    class GraphDriver(QueryExecutor, ABC):
        @abstractmethod
        async def close(self) -> None: ...
    
        @abstractmethod
        def transaction(self) -> AsyncContextManager[Transaction]: ...
    
        @property
        @abstractmethod
        def entity_node_ops(self) -> EntityNodeOperations: ...
        # ... other ops properties ...
  7. Understand Episodes, Hybrid Search, and Graph Traversal in Graphiti

    main

    Episodes

    Episodes are the fundamental units of information ingested into Graphiti. They can be provided as:

    • Text: Raw content like documents or transcripts.
    • JSON: Structured data containing key-value pairs.

    Graphiti performs searches by combining multiple strategies:

    • Semantic Search: Uses embeddings to find content with similar meaning.
    • BM25: A keyword-based retrieval method.
    • Graph Traversal: Uses the relationships between entities in the graph to find related information.

    This is a specialized search pattern that reranks results based on their graph distance to a specific target node.

  8. Customize Entity Types in Graphiti

    main

    Graphiti uses built-in entity types for structured knowledge extraction. These are always enabled but can be customized or extended in config.yaml by modifying their descriptions.

    Built-in Entity Types:

    • Preference: User preferences, choices, opinions.
    • Requirement: Specific needs or functionality.
    • Procedure: SOPs or sequential instructions.
    • Location: Physical or virtual places.
    • Event: Time-bound activities.
    • Person: Individual humans.
    • Organization: Companies or institutions.
    • Document: Books, articles, reports, etc.
    • Topic: Subject of conversation (fallback).
    • Object: Physical items (fallback).

    Customization Example:

    graphiti:
      entity_types:
        - name: "Preference"
          description: "User preferences, choices, opinions, or selections"
        - name: "Requirement"
          description: "Specific needs, features, or functionality"

    Note: To disable rich-attribute extraction and use the previous attribute-free behavior, set graphiti.entity_types to an empty list.

    graphiti:
      entity_types:
        - name: "Preference"
          description: "User preferences, choices, opinions, or selections"
  9. Understanding the components of a Context Graph

    main

    A context graph in Graphiti is composed of four primary elements that allow for temporal awareness and data lineage:

    ComponentWhat it stores
    Entities (nodes)People, products, policies, concepts — with summaries that evolve over time
    Facts / Relationships (edges)Triplets (Entity → Relationship → Entity) with temporal validity windows
    Episodes (provenance)Raw data as ingested — the ground truth stream. Every derived fact traces back here
    Custom Types (ontology)Developer-defined entity and edge types via Pydantic models
  10. Graphiti MCP Server

    main

    The mcp_server provides a Model Context Protocol (MCP) implementation. This allows AI assistants to interact with Graphiti's context graph capabilities, including:

    • Episode management (add, retrieve, delete)
    • Entity management and relationship handling
    • Semantic and hybrid search
    • Group management
    • Graph maintenance operations
  11. Understand the Graphiti architecture layers

    main

    Graphiti is organized into three distinct layers to decouple data models from database I/O:

    1. Graphiti Client (graphiti.py): The top-level entry point for users.
    2. Namespace Wrappers: Thin orchestration layers that handle cross-cutting concerns like embedding generation and tracing before delegating to operations.
    3. Operations ABCs: Pure database I/O interfaces implemented per driver. These depend on a slim QueryExecutor interface rather than the full driver to avoid circular dependencies.
    4. GraphDriver: The concrete implementation that manages connections and executes queries.