NeptuneDriver class provides connectivity to AWS Neptune, a fully managed graph database service with OpenSearch integration.
Overview
AWS Neptune is a managed graph database service that supports both property graph (openCypher) and RDF models. The NeptuneDriver provides:- Support for Neptune Database and Neptune Analytics
- OpenSearch Serverless (AOSS) integration for fulltext search
- AWS IAM authentication
- Managed infrastructure and scaling
- Automatic datetime conversion
Constructor
Parameters
str
required
The Neptune endpoint URL.Must use one of these URI schemes:
neptune-db://<endpoint>- Neptune Database cluster endpointneptune-graph://<graph-id>- Neptune Analytics graph identifier
"neptune-db://my-cluster.us-east-1.neptune.amazonaws.com" or "neptune-graph://g-abc123def456"str
required
The OpenSearch Serverless (AOSS) endpoint hostname.Used for fulltext indexing and search. Must be an AOSS endpoint in the same AWS region.Example:
"search-graphiti.us-east-1.aoss.amazonaws.com"int
default:"8182"
The Neptune Database port.Only used for Neptune Database. Ignored for Neptune Analytics.Default:
8182int
default:"443"
The OpenSearch Serverless port.Typically 443 for HTTPS connections.Default:
443Methods
execute_query
Execute a Cypher query and return results.cypher_query_(str | list) - The Cypher query or list of queries to execute**kwargs- Query parameters (automatically sanitized for Neptune)
tuple[list[dict], None, None] - Records, None, None
Neptune requires datetime objects to be converted to ISO strings and wrapped with
datetime(). The driver handles this automatically.session
Create a new database session.database(str | None) - Ignored for Neptune (single graph per endpoint)
NeptuneDriverSession - Session object
close
Close the driver and release connections.None
build_indices_and_constraints
Create OpenSearch indices for fulltext search.delete_existing(bool) - If True, delete existing AOSS indices before creating new ones
None
create_aoss_indices
Create OpenSearch Serverless indices.None
Creates the following indices:
node_name_and_summary- Entity and community node fulltextcommunity_name- Community name searchepisode_content- Episode content searchedge_name_and_fact- Edge relationship search
delete_aoss_indices
Delete all OpenSearch Serverless indices.None
run_aoss_query
Execute a fulltext search query against OpenSearch.name(str) - The index name to queryquery_text(str) - The search query textlimit(int) - Maximum number of results (default: 10)
dict[str, Any] - OpenSearch response with hits
save_to_aoss
Bulk index documents into OpenSearch.name(str) - The index namedata(list[dict]) - List of documents to index
int - Number of successfully indexed documents
Properties
provider
GraphProvider.NEPTUNE enum value.
aoss_client
Operations Properties
The driver exposes specialized operation interfaces:Usage Examples
Neptune Database Connection
Neptune Analytics Connection
With Graphiti
OpenSearch Fulltext Search
Bulk Indexing to OpenSearch
Datetime Handling
- Converts datetime objects to ISO strings
- Wraps them with Neptune’s
datetime()function - Handles datetimes in nested structures (lists, dicts)
Environment Variables
Common environment variables for Neptune configuration:AWS Authentication
The NeptuneDriver usesboto3 for AWS authentication. It automatically:
- Reads credentials from environment variables
- Uses IAM role credentials if running on EC2/ECS/Lambda
- Reads from
~/.aws/credentials - Uses AWS SSO credentials
- Neptune read/write access
- OpenSearch Serverless read/write access
OpenSearch Indices
The driver creates four OpenSearch indices:node_name_and_summary
Searches entity and community nodes by name, summary, and group_id. Fields: uuid, name, summary, group_idcommunity_name
Searches community nodes by name and group_id. Fields: uuid, name, group_idepisode_content
Searches episode nodes by content, source, and description. Fields: uuid, content, source, source_description, group_idedge_name_and_fact
Searches entity edges by name, fact, and group_id. Fields: uuid, name, fact, group_idLimitations
When to Use Neptune
Use NeptuneDriver for:- AWS-native deployments
- Managed graph database requirements
- Integration with other AWS services
- Scalable cloud workloads
- Production applications with AWS infrastructure
- Non-AWS deployments → Neo4j or FalkorDB
- Development/testing → Kuzu
- Self-hosted requirements → Neo4j or FalkorDB
- Cost-sensitive projects → Neo4j or FalkorDB
Related
Drivers Overview
Learn about the driver architecture
Graphiti
Main Graphiti class documentation
Neo4j Driver
Self-hosted production driver
FalkorDB Driver
Redis-based alternative