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
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
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.Basic Search
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: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
Database connection errors
Database connection errors
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 variablesOpenAI API errors
OpenAI API errors
- Verify
OPENAI_API_KEYis set correctly - Check you have sufficient API credits
- Ensure you’re using a supported model (defaults to
gpt-4o-mini)
429 Rate Limit Errors
429 Rate Limit Errors
Graphiti defaults to low concurrency (If your LLM provider allows higher throughput, increase this value for better performance.
SEMAPHORE_LIMIT=10) to avoid rate limits. If you still encounter 429 errors:Graph not found errors
Graph not found errors
The Neo4j driver defaults to the
neo4j database. To use a different database: