Skip to main content

Overview

This quickstart demonstrates how to build a temporally-aware knowledge graph with Graphiti. You’ll learn how to:
  • Connect to a graph database
  • Add episodes (data) to your knowledge graph
  • Search for relationships and entities
  • Use graph-based reranking for contextual results
This guide uses Neo4j as the graph database backend. Graphiti also supports FalkorDB, Kuzu, and Amazon Neptune.

Prerequisites

Before you begin, ensure you have:
  • Python 3.10 or higher
  • A graph database running (Neo4j, FalkorDB, Kuzu, or Amazon Neptune)
  • An OpenAI API key
The simplest way to get started is with Neo4j Desktop or FalkorDB via Docker:

Step 1: Install Graphiti

Install Graphiti using your preferred package manager:

Step 2: Set Up Environment Variables

Create a .env file or export environment variables:
.env
Keep your API keys secure. Never commit them to version control.

Step 3: Initialize Graphiti

Create a new Python file and initialize your Graphiti instance:
quickstart.py
Graphiti defaults to using OpenAI for LLM inference and embeddings. Set OPENAI_API_KEY in your environment.

Step 4: Add Episodes to Your Graph

Episodes are the primary units of information in Graphiti. They can be text or structured JSON and are automatically processed to extract entities and relationships.
1

Define Your Episodes

Create a list of episodes with both text and JSON content:
2

Add Episodes to the Graph

Process each episode and add it to your knowledge graph:
Graphiti automatically:
  • Extracts entities (nodes) like “Kamala Harris” and “California”
  • Identifies relationships (edges) like “is Attorney General of”
  • Creates embeddings for semantic search
  • Tracks temporal information

Step 5: Search Your Knowledge Graph

Now that you’ve added data, you can search for information using hybrid search that combines semantic similarity and keyword matching. Search for relationships (edges) in your graph:
The search() method performs hybrid search combining:
  • Semantic similarity using embeddings
  • BM25 keyword matching
  • Graph-based retrieval

Graph-Aware Reranking

For more contextually relevant results, use a center node to rerank search results based on their graph distance:
Graph-based reranking prioritizes results that are closer in the graph structure to a specific node, giving you more contextually relevant information.

Node Search with Recipes

Graphiti provides predefined search recipes optimized for different scenarios:

Complete Example

Here’s the full working example:
quickstart.py

Next Steps

Now that you have a working knowledge graph:

Explore Different Backends

Try FalkorDB, Kuzu, or Amazon Neptune

Use Different LLM Providers

Configure Anthropic, Google Gemini, or Ollama

Custom Entity Types

Define domain-specific entities and relationships

Advanced Search

Learn about search recipes and filtering

Troubleshooting

Ensure your graph database is running:Neo4j: Check Neo4j Desktop and verify your DBMS is startedFalkorDB: Verify Docker container is running with docker psConnection refused: Double-check URI, username, and password in your environment variables
  • Verify OPENAI_API_KEY is set correctly
  • Check you have sufficient API credits
  • Ensure you’re using a supported model (defaults to gpt-4o-mini)
Graphiti defaults to low concurrency (SEMAPHORE_LIMIT=10) to avoid rate limits. If you still encounter 429 errors:
If your LLM provider allows higher throughput, increase this value for better performance.
The Neo4j driver defaults to the neo4j database. To use a different database: