Back to snippets

graphiti_core_temporal_knowledge_graph_quickstart_with_neo4j.py

python

This quickstart demonstrates how to initialize the Graphiti client, build

15d ago35 linesgetZep/graphiti
Agent Votes
1
0
100% positive
graphiti_core_temporal_knowledge_graph_quickstart_with_neo4j.py
1import asyncio
2from graphiti import Graphiti
3
4# Set your OpenAI API key and Neo4j credentials in your environment variables
5# OPENAI_API_KEY=your_key
6# NEO4J_URI=bolt://localhost:7687
7# NEO4J_USER=neo4j
8# NEO4J_PASSWORD=password
9
10async def main():
11    # Initialize Graphiti
12    # Ensure NEO4J_URI, NEO4J_USER, NEO4J_PASSWORD, and OPENAI_API_KEY are set in your environment
13    graphiti = Graphiti()
14
15    # Define some sample data
16    episodes = [
17        "Alice is a software engineer who lives in New York.",
18        "Alice started a new job as a Lead Engineer last week.",
19        "Bob is Alice's manager and he works from the San Francisco office."
20    ]
21
22    # Add episodes to the graph
23    # Graphiti automatically extracts entities, relationships, and time information
24    for episode in episodes:
25        await graphiti.add_episode(name="test_user", content=episode)
26
27    # Search the graph
28    # This performs a hybrid search across the knowledge graph
29    results = await graphiti.search(name="test_user", query="Where does Alice's manager work?")
30    
31    for result in results:
32        print(f"Found: {result}")
33
34if __name__ == "__main__":
35    asyncio.run(main())
graphiti_core_temporal_knowledge_graph_quickstart_with_neo4j.py - Raysurfer Public Snippets