Skip to main content
The 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 endpoint
  • neptune-graph://<graph-id> - Neptune Analytics graph identifier
Example: "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: 8182
int
default:"443"
The OpenSearch Serverless port.Typically 443 for HTTPS connections.Default: 443

Methods

execute_query

Execute a Cypher query and return results.
Parameters:
  • cypher_query_ (str | list) - The Cypher query or list of queries to execute
  • **kwargs - Query parameters (automatically sanitized for Neptune)
Returns: 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.
Parameters:
  • database (str | None) - Ignored for Neptune (single graph per endpoint)
Returns: NeptuneDriverSession - Session object

close

Close the driver and release connections.
Returns: None

build_indices_and_constraints

Create OpenSearch indices for fulltext search.
Parameters:
  • delete_existing (bool) - If True, delete existing AOSS indices before creating new ones
Returns: None
Index creation takes approximately 60 seconds. The method includes a sleep to ensure indices are ready before use.

create_aoss_indices

Create OpenSearch Serverless indices.
Returns: None Creates the following indices:
  • node_name_and_summary - Entity and community node fulltext
  • community_name - Community name search
  • episode_content - Episode content search
  • edge_name_and_fact - Edge relationship search

delete_aoss_indices

Delete all OpenSearch Serverless indices.
Returns: None

run_aoss_query

Execute a fulltext search query against OpenSearch.
Parameters:
  • name (str) - The index name to query
  • query_text (str) - The search query text
  • limit (int) - Maximum number of results (default: 10)
Returns: dict[str, Any] - OpenSearch response with hits

save_to_aoss

Bulk index documents into OpenSearch.
Parameters:
  • name (str) - The index name
  • data (list[dict]) - List of documents to index
Returns: int - Number of successfully indexed documents

Properties

provider

Returns the GraphProvider.NEPTUNE enum value.

aoss_client

Access the underlying OpenSearch client for advanced queries.

Operations Properties

The driver exposes specialized operation interfaces:

Usage Examples

Neptune Database Connection

Neptune Analytics Connection

With Graphiti

Bulk Indexing to OpenSearch

Datetime Handling

The driver automatically:
  1. Converts datetime objects to ISO strings
  2. Wraps them with Neptune’s datetime() function
  3. Handles datetimes in nested structures (lists, dicts)

Environment Variables

Common environment variables for Neptune configuration:
Load in your application:

AWS Authentication

The NeptuneDriver uses boto3 for AWS authentication. It automatically:
  1. Reads credentials from environment variables
  2. Uses IAM role credentials if running on EC2/ECS/Lambda
  3. Reads from ~/.aws/credentials
  4. Uses AWS SSO credentials
Ensure your credentials have permissions for:
  • 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_id

community_name

Searches community nodes by name and group_id. Fields: uuid, name, group_id

episode_content

Searches episode nodes by content, source, and description. Fields: uuid, content, source, source_description, group_id

edge_name_and_fact

Searches entity edges by name, fact, and group_id. Fields: uuid, name, fact, group_id

Limitations

Neptune has some limitations:
  • Index creation delay - OpenSearch indices take ~60 seconds to become available
  • Single graph per endpoint - Cannot switch databases like Neo4j
  • AWS region required - Must be in the same region as Neptune and AOSS
  • IAM authentication required - Must configure AWS credentials
  • Cost considerations - Managed service with per-hour/per-query pricing

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
Consider alternatives for:
  • Non-AWS deployments → Neo4j or FalkorDB
  • Development/testing → Kuzu
  • Self-hosted requirements → Neo4j or FalkorDB
  • Cost-sensitive projects → Neo4j or FalkorDB

Drivers Overview

Learn about the driver architecture

Graphiti

Main Graphiti class documentation

Neo4j Driver

Self-hosted production driver

FalkorDB Driver

Redis-based alternative