Quick Start
For complete working examples, check out the Graphiti Quickstart Examples on GitHub.
Getting Started with Graphiti
For a comprehensive overview of Graphiti and its capabilities, check out the Overview page.
Required Imports
First, import the necessary libraries for working with Graphiti. If you haven’t installed Graphiti yet, see the Installation page:
Configuration
Graphiti uses OpenAI by default for LLM inference and embedding. Ensure that an OPENAI_API_KEY
is set in your environment. Support for Anthropic and Groq LLM inferences is available, too.
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 password
For more details on requirements and setup, see the Installation page.
Set up logging and environment variables for connecting to the Neo4j database:
Main Function
Create an async main function to run all Graphiti operations:
Initialization
Connect to Neo4j and set up Graphiti indices. This is required before using other Graphiti functionality:
Adding Episodes
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:
Basic Search
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:
Center Node Search
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:
Node Search Using Search Recipes
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:
Complete Example
For a complete working example that puts all these concepts together, check out the Graphiti Quickstart Examples on GitHub.
Next Steps
Now that you’ve learned the basics of Graphiti, you can explore more advanced features:
- Custom Entity Types: Learn how to define and use custom entity types to better model your domain-specific knowledge
- Communities: Discover how to work with communities, which are groups of related nodes that share common attributes or relationships
- Advanced Search Techniques: Explore more sophisticated search strategies, including different reranking approaches and configurable search recipes
- Adding Fact Triples: Learn how to directly add fact triples to your graph for more precise knowledge representation
- Agent Integration: Discover how to integrate Graphiti with LLM agents for more powerful AI applications
Make sure to run await statements within an async function.