For complete working examples, check out the Graphiti Quickstart Examples on GitHub.
Requirements:
The simplest way to install Neo4j is via Neo4j Desktop. It provides a user-friendly interface to manage Neo4j instances and databases.
or
While Graphiti defaults to OpenAI, it supports multiple LLM providers including Azure OpenAI, Google Gemini, Anthropic, Groq, and local models via Ollama. For detailed configuration instructions, see our LLM Configuration guide.
Graphiti’s ingestion pipelines are designed for high concurrency. By default, concurrency is set low to avoid LLM Provider 429 Rate Limit Errors. If you find Graphiti slow, please increase concurrency as described below.
Concurrency controlled by the SEMAPHORE_LIMIT environment variable. By default, SEMAPHORE_LIMIT is set to 10 concurrent operations to help prevent 429 rate limit errors from your LLM provider. If you encounter such errors, try lowering this value.
If your LLM provider allows higher throughput, you can increase SEMAPHORE_LIMIT to boost episode ingestion performance.
Set your OpenAI API key:
GRAPHITI_TELEMETRY_ENABLED: Set to false to disable anonymous telemetry collectionFor a comprehensive overview of Graphiti and its capabilities, check out the Overview page.
First, import the necessary libraries for working with Graphiti:
Graphiti uses OpenAI by default for LLM inference and embedding. Ensure that an OPENAI_API_KEY is set in your environment. Support for multiple LLM providers is available - see our LLM Configuration guide.
Graphiti also requires Neo4j connection parameters. Set the following environment variables:
NEO4J_URI: The URI of your Neo4j database (default: bolt://localhost:7687)NEO4J_USER: Your Neo4j username (default: neo4j)NEO4J_PASSWORD: Your Neo4j passwordFor detailed database setup instructions, see our Graph Database Configuration guide.
Set up logging and environment variables for connecting to the Neo4j database:
Create an async main function to run all Graphiti operations:
Connect to Neo4j and set up Graphiti indices. This is required before using other Graphiti functionality:
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. For more detailed information on episodes and bulk loading, see the Adding Episodes page:
The simplest way to retrieve relationships (edges) from Graphiti is using the search method, which performs a hybrid search combining semantic similarity and BM25 text retrieval. For more details on search capabilities, see the Searching the Graph page:
For more contextually relevant results, you can use a center node to rerank search results based on their graph distance to a specific node. This is particularly useful for entity-specific queries as described in the Searching the Graph page:
Graphiti provides predefined search recipes optimized for different search scenarios. Here we use NODE_HYBRID_SEARCH_RRF for retrieving nodes directly instead of edges. For a complete list of available search recipes and reranking approaches, see the Configurable Search Strategies section in the Searching documentation:
For a complete working example that puts all these concepts together, check out the Graphiti Quickstart Examples on GitHub.
Now that you’ve learned the basics of Graphiti, you can explore more advanced features:
Make sure to run await statements within an async function.