Skip to main content
Graphiti uses a pluggable driver architecture that allows you to integrate any graph database backend. This guide walks through implementing a custom driver from scratch.

Driver Architecture Overview

Graphiti’s driver layer is organized into three tiers:

1. GraphDriver ABC

The core interface (graphiti_core/driver/driver.py) that every backend must implement:

2. GraphProvider Enum

Identifies the backend in query builders:

3. Operations Interfaces

Eleven abstract base classes covering all CRUD and search operations:
  • Node operations: EntityNodeOperations, EpisodeNodeOperations, CommunityNodeOperations, SagaNodeOperations
  • Edge operations: EntityEdgeOperations, EpisodicEdgeOperations, CommunityEdgeOperations, HasEpisodeEdgeOperations, NextEpisodeEdgeOperations
  • Search & maintenance: SearchOperations, GraphMaintenanceOperations

Building a Custom Driver

Step 1: Add to GraphProvider Enum

Edit graphiti_core/driver/driver.py:

Step 2: Create Directory Structure

Step 3: Implement the Driver Class

Create graphiti_core/driver/my_backend_driver.py:

Step 4: Implement GraphDriverSession

Create a session class for connection management:

Step 5: Implement Operations

Implement all 11 operation classes. Here’s an example of EntityNodeOperations:

Step 6: Add Query Variants

Add database-specific query builders in graphiti_core/models/nodes/node_db_queries.py:
Do the same for edge queries in graphiti_core/models/edges/edge_db_queries.py.

Step 7: Register Optional Dependency

Add to pyproject.toml:

Step 8: Export from init.py

Create graphiti_core/driver/my_backend/operations/__init__.py:

Real-World Examples

The Neo4j driver is the most straightforward reference implementation:
Key features:
  • Full transaction support
  • Native Cypher queries
  • Vector index support
  • Constraint management
See: graphiti_core/driver/neo4j_driver.py and graphiti_core/driver/neo4j/operations/

FalkorDB Driver (Lightweight Alternative)

FalkorDB is Redis-based with a different query approach:
Key differences:
  • Redis-based connection
  • Custom fulltext query syntax (@ prefix)
  • Stopwords filtering
  • No native transaction support
See: graphiti_core/driver/falkordb_driver.py and graphiti_core/driver/falkordb/operations/

Kuzu Driver (Embedded Database)

Kuzu demonstrates an embedded, in-process database:
Key features:
  • Embedded database (no server)
  • Explicit schema definition
  • Custom edge representation (RelatesToNode_)
  • Schema creation in init
Schema definition in kuzu_driver.py:
See: graphiti_core/driver/kuzu_driver.py and graphiti_core/driver/kuzu/operations/ Neptune shows integration with external search (OpenSearch):
Key features:
  • Cloud-managed graph database
  • External OpenSearch for fulltext
  • AWS IAM authentication
  • Separate search backend
See: graphiti_core/driver/neptune_driver.py and graphiti_core/driver/neptune/operations/

Usage Pattern

Once implemented, use your driver with Graphiti:

Testing Your Driver

Create tests in tests/driver/test_my_backend_driver.py:

Best Practices

1. Use Query Builders

Leverage shared query builders instead of hardcoding queries:

2. Handle Transactions Properly

Implement transaction support if your database supports it:

3. Parse Results Consistently

Create helper methods for result parsing:

4. Handle Database Dialects

Account for syntax differences in your query builders:

5. Document Limitations

Clearly document any limitations:

Performance Considerations

Connection Pooling

Batch Operations

Implement efficient bulk operations:

Index Optimization

Create appropriate indices:

Troubleshooting

Driver Not Found

Error: ImportError: cannot import name 'MyBackendDriver' Solution: Ensure your driver is installed:

Query Syntax Errors

Error: SyntaxError: Invalid query syntax Solution: Add your provider to query builders:

Missing Operations

Error: AttributeError: 'MyBackendDriver' object has no attribute 'entity_node_ops' Solution: Implement all 11 operation properties:

Contributing Your Driver

To contribute your driver to the Graphiti project:
  1. Fork the repository
  2. Implement your driver following this guide
  3. Add comprehensive tests
  4. Update documentation
  5. Submit a pull request
See CONTRIBUTING.md for details.

Resources

Next Steps