Skip to content

Graphiti Integration

Overview

Graphiti is an open-source framework that transforms text, JSON, and chat content into queryable knowledge graphs using language models and graph databases. It excels at:

  • Semantic indexing and retrieval
  • Contextual search across structured/unstructured data
  • Building long-term memory for AI agents

Why use Graphiti with Relax AI? Combine Neo4j’s graph capabilities with Relax’s powerful LLMs for context-aware applications.

Key Features

  • Multi-format Ingestion: Process text, JSON, and chat messages
  • Hybrid Search: Combine vector similarity and graph traversal
  • Relax AI Integration: Use any Relax AI model for embeddings and reasoning
  • Neo4j Backend: Lever industry-leading graph database
  • Memory API: Create persistent knowledge for AI agents

Use Cases

  • Building corporate knowledge graphs from documents and chats
  • Creating contextual memory systems for AI copilots
  • Real-time reasoning over dynamic data streams
  • Customer support history analysis and retrieval
  • Integrating Slack/PDF data into queryable knowledge

Quick Setup

  1. Install Graphiti Core:

    Terminal window
    pip install graphiti-core openai
  2. Graphiti requires Neo4j version 5.26 or higher. Either download and install Neo4j Desktop. Create a project, add a new database (Local DBMS), set password for user neo4j, and start the database or start a docker conrainer with the following command:

    Terminal window
    docker run \
    --name neo4j-graphiti \
    -p 7474:7474 -p 7687:7687 \
    -e NEO4J_AUTH=neo4j/your_password \
    -e NEO4J_PLUGINS='["apoc"]' \
    neo4j:5.26-community

This exposes the HTTP (7474) and Bolt (7687) ports with neo4j/your_password credentials.

  1. Set required environment variables (can be in .env)
    Terminal window
    export NEO4J_URI="bolt://localhost:7687"
    export NEO4J_USER="neo4j"
    export NEO4J_PASSWORD="your-password"
    export OPENAI_API_KEY="rak_..." # Replace with your Relax AI API key
    export OPENAI_BASE_URL="https://api.relax.ai/v1"
  2. Intialize the Neo4j database schema, run the below sample script to create the schema:
    db_schema.py
    import os
    import asyncio
    from graphiti_core import Graphiti
    async def main():
    graphiti = Graphiti(
    os.getenv("NEO4J_URI"),
    os.getenv("NEO4J_USER"),
    os.getenv("NEO4J_PASSWORD")
    )
    await graphiti.build_indices_and_constraints(delete_existing=True)
    print("✅ Neo4j schema initialized")
    await graphiti.close()
    if __name__ == "__main__":
    asyncio.run(main())
  3. Now configure Graphiti with RelaxAI client along with a sample python example below.
configure.py
import os, asyncio, json
from graphiti_core import Graphiti
from graphiti_core.llm_client import LLMConfig, OpenAIClient
from graphiti_core.embedder.openai import OpenAIEmbedder, OpenAIEmbedderConfig
from graphiti_core.nodes import EpisodeType
from datetime import datetime, timezone
# LLM & Embedder setup
llm_config = LLMConfig(model="DeepSeek-R1-0528", small_model="Llama-4-Maverick-17B-128E")
llm_client = OpenAIClient(llm_config, None)
embedder = OpenAIEmbedder(OpenAIEmbedderConfig(embedding_model="Mistral-7b-embedding"), None)
async def main():
graphiti = Graphiti(
os.getenv("NEO4J_URI"),
os.getenv("NEO4J_USER"),
os.getenv("NEO4J_PASSWORD"),
llm_client=llm_client,
embedder=embedder
)
await graphiti.build_indices_and_constraints(delete_existing=True)
print("✅ Schema built")
# episodes
episodes = [
{
"name": "acquisition-news",
"body": (
"In April 2025, Acme Corp acquired BetaTech for $25M. "
"Jane Doe, VP of Strategy at Acme, will lead integration."
),
"source": EpisodeType.text,
"description": "Corporate acquisition announcement",
"time": datetime(2025, 4, 1, tzinfo=timezone.utc)
},
{
"name": "customer-support-chat",
"body": (
"Customer: I've been using your mobile app since last year, and the notifications aren't working.\n"
"Support: Hi! We rolled out a fix in March 2025. Please update the app."
),
"source": EpisodeType.message,
"description": "Customer support chat",
"time": datetime(2025, 4, 5, tzinfo=timezone.utc)
},
{
"name": "product-release",
"body": json.dumps({
"product_id": "P-100",
"name": "EcoSmart Thermostat",
"manufacturer": "HomeTech Inc",
"price": 199.99,
"release_date": "2025-03-20T10:00:00Z",
"features": ["Remote control", "Energy saving mode", "Voice integration"]
}),
"source": EpisodeType.json,
"description": "Product catalog entry",
"time": datetime(2025, 3, 20, tzinfo=timezone.utc)
}
]
for ep in episodes:
await graphiti.add_episode(
name=ep["name"],
episode_body=ep["body"],
source=ep["source"],
source_description=ep["description"],
reference_time=ep["time"]
)
print(f"✅ Added episode: {ep['name']}")
# Sample search
results = await graphiti.search("Who did Acme Corp acquire?")
print("Search results:", results)
await graphiti.close()
if __name__ == "__main__":
asyncio.run(main())

Advanced Usage

Namespaces (group_id)

You can assign a group_id when initializing Graphiti to separate memory graphs by application, tenant, or agent.

graphiti = Graphiti(
uri, user, password,
llm_client=llm_client,
embedder=embedder,
group_id="team-42"
)

By default, graphiti.search() uses vector similarity + graph traversal. You can override search strategies, weights, or filter by time, entity type, or tag.

Graph Queries (Cypher)

Use Neo4j Browser or Bloom to run the following queries:

Terminal window
// Get all people involved in launches
MATCH (e:Event)<-[:INVOLVED_IN]-(p:Entity)
WHERE e.name CONTAINS 'launch'
RETURN p.name, e.date
// Find related support tickets
MATCH (t:Ticket)-[r:RELATED_TO]->(p:Product)
RETURN t, p, r

You should see graph nodes representing entities, events, and relationships in the Neo4j Browser.

Graphiti Neo4j Browser


Troubleshooting

  • Connection Issues: Verify Neo4j is running and credentials are correct
  • Schema Errors: Run build_indices_and_constraints(delete_existing=True)
  • Model Compatibility: Ensure Relax AI model names match available models

Resources