Skip to content

Graph Data Store

Modules containing graph data store implementations to be used in Gen AI applications.

LlamaIndexNeo4jGraphRAGDataStore(*args, **kwargs)

Bases: LlamaIndexGraphRAGDataStore, Neo4jPropertyGraphStore

Graph RAG data store for Neo4j.

This class extends the Neo4jPropertyGraphStore class from LlamaIndex. This class provides an interface for graph-based Retrieval-Augmented Generation (RAG) operations on Neo4j graph databases.

Attributes:

Name Type Description
neo4j_version_tuple tuple[int, ...]

The Neo4j version tuple.

Example
store = LlamaIndexNeo4jGraphRAGDataStore(
    url="bolt://localhost:7687",
    username="neo4j",
    password="password"
)
# Perform RAG query
results = await store.query("What is the relationship between X and Y?")

# Delete document data
await store.delete_by_document_id("doc123")

Initialize the LlamaIndexNeo4jGraphRAGDataStore.

Parameters:

Name Type Description Default
*args

Variable length argument list.

()
**kwargs

Arbitrary keyword arguments.

{}

delete_by_document_id(document_id, **kwargs) async

Delete nodes and edges by document ID.

Parameters:

Name Type Description Default
document_id str

The document ID.

required
**kwargs Any

Additional keyword arguments.

{}

NebulaGraphDataStore(url, port, user, password, space, operation_wait_time=5)

Bases: BaseGraphDataStore

Implementation of BaseGraphDataStore for Nebula Graph.

This class provides an interface for graph-based Retrieval-Augmented Generation (RAG) operations on Nebula graph databases.

Attributes:

Name Type Description
connection_pool ConnectionPool

The connection pool for Nebula Graph.

space str

The space name.

user str

The username.

password str

The password.

operation_wait_time int

The timeout in seconds.

Example
store = NebulaGraphDataStore(
    url="127.0.0.1",
    port=9669,
    user="root",
    password="nebula",
    space="testing"
)
# Perform query
results = await store.query("MATCH (n) RETURN n")

# Create a node
node = await store.upsert_node("Person", "name", "John", {"age": 30})

Initialize NebulaGraphDataStore.

Parameters:

Name Type Description Default
url str

The URL of the graph store.

required
port int

The port of the graph store.

required
user str

The user of the graph store.

required
password str

The password of the graph store.

required
space str

The space name.

required
operation_wait_time int

The operation wait time in seconds. Defaults to 5.

5

close() async

Close the graph data store.

delete_node(label, identifier_key, identifier_value) async

Delete a node from the graph.

Parameters:

Name Type Description Default
label str

The label of the node.

required
identifier_key str

The key of the identifier.

required
identifier_value str

The identifier of the node.

required

Returns:

Name Type Description
Any Any

The result of the operation.

delete_relationship(node_source_key, node_source_value, relation, node_target_key, node_target_value) async

Delete a relationship between two nodes in the graph.

Parameters:

Name Type Description Default
node_source_key str

The key of the source node.

required
node_source_value str

The identifier of the source node.

required
relation str

The type of the relationship.

required
node_target_key str

The key of the target node.

required
node_target_value str

The identifier of the target node.

required

Returns:

Name Type Description
Any Any

The result of the operation.

get_nodes(label=None) async

Get all nodes with optional label filter.

Parameters:

Name Type Description Default
label str | None

The label of the nodes. Defaults to None.

None

Returns:

Type Description
list[dict[str, Any]]

list[dict[str, Any]]: The result of the query.

get_relationships(source_value=None, relation=None) async

Get relationships with optional filters.

Parameters:

Name Type Description Default
source_value str | None

The source vertex identifier. Defaults to None.

None
relation str | None

The relationship type. Defaults to None.

None

Returns:

Type Description
list[dict[str, Any]]

list[dict[str, Any]]: The result of the query.

query(query, parameters=None) async

Query the graph store.

Parameters:

Name Type Description Default
query str

The query to be executed.

required
parameters dict[str, Any] | None

The parameters of the query. Defaults to None.

None

Returns:

Type Description
list[dict[str, Any]]

list[dict[str, Any]]: The result of the query.

upsert_node(label, identifier_key, identifier_value, properties=None) async

Upsert a node in the graph.

Parameters:

Name Type Description Default
label str

The label of the node.

required
identifier_key str

The key of the identifier.

required
identifier_value str

The value of the identifier.

required
properties dict[str, Any] | None

The properties of the node. Defaults to None.

None

Returns:

Name Type Description
Any Any

The result of the operation.

upsert_relationship(node_source_key, node_source_value, relation, node_target_key, node_target_value, properties=None) async

Upsert a relationship between two nodes in the graph.

Parameters:

Name Type Description Default
node_source_key str

The key of the source node.

required
node_source_value str

The value of the source node.

required
relation str

The type of the relationship.

required
node_target_key str

The key of the target node.

required
node_target_value str

The value of the target node.

required
properties dict[str, Any] | None

The properties of the relationship. Defaults to None.

None

Returns:

Name Type Description
Any Any

The result of the operation.

Neo4jGraphDataStore(uri, user, password, max_connection_pool_size=100, retry_config=None, **kwargs)

Bases: BaseGraphDataStore

Implementation of BaseGraphDataStore for Neo4j.

This class provides an interface for graph-based Retrieval-Augmented Generation (RAG) operations on Neo4j graph databases.

Attributes:

Name Type Description
driver Driver

The Neo4j driver.

Example
store = Neo4jGraphDataStore(
    uri="bolt://localhost:7687",
    user="neo4j",
    password="password"
)
# Perform async operations
results = await store.query("MATCH (n) RETURN n")

# Create a node
node = await store.upsert_node("Person", "name", "John", {"age": 30})

Initialize Neo4jGraphDataStore.

Parameters:

Name Type Description Default
uri str

The URI of the graph store.

required
user str

The user of the graph store.

required
password str

The password of the graph store.

required
max_connection_pool_size int

The maximum size of the connection pool. Defaults to 100.

100
retry_config RetryConfig | None

Configuration for retry behavior. Defaults to None. If provided, query operations will be retried according to the specified RetryConfig parameters. When a database operation fails with a retryable exception (e.g., neo4j.exceptions.ServiceUnavailable), the operation will be automatically retried based on the retry policy defined in the configuration.

None
**kwargs Any

Additional keyword arguments for the driver.

{}

close() async

Close the graph data store.

delete_node(label, identifier_key, identifier_value) async

Delete a node from the graph.

Parameters:

Name Type Description Default
label str

The label of the node.

required
identifier_key str

The key of the identifier.

required
identifier_value str

The identifier of the node.

required

Returns:

Name Type Description
Any Any

The result of the operation.

delete_relationship(node_source_key, node_source_value, relation, node_target_key, node_target_value) async

Delete a relationship between two nodes in the graph.

Parameters:

Name Type Description Default
node_source_key str

The key of the source node.

required
node_source_value str

The identifier of the source node.

required
relation str

The type of the relationship.

required
node_target_key str

The key of the target node.

required
node_target_value str

The identifier of the target node.

required

Returns:

Name Type Description
Any Any

The result of the operation.

query(query, parameters=None) async

Query the graph store.

Parameters:

Name Type Description Default
query str

The query to be executed.

required
parameters dict[str, Any] | None

The parameters of the query. Defaults to None.

None

Returns:

Type Description
list[dict[str, Any]]

list[dict[str, Any]]: The result of the query.

upsert_node(label, identifier_key, identifier_value, properties=None) async

Upsert a node in the graph.

Parameters:

Name Type Description Default
label str

The label of the node.

required
identifier_key str

The key of the identifier.

required
identifier_value str

The value of the identifier.

required
properties dict[str, Any] | None

The properties of the node. Defaults to None.

None

Returns:

Name Type Description
Any Any

The result of the operation.

upsert_relationship(node_source_key, node_source_value, relation, node_target_key, node_target_value, properties=None) async

Upsert a relationship between two nodes in the graph.

Parameters:

Name Type Description Default
node_source_key str

The key of the source node.

required
node_source_value str

The value of the source node.

required
relation str

The type of the relationship.

required
node_target_key str

The key of the target node.

required
node_target_value str

The value of the target node.

required
properties dict[str, Any] | None

The properties of the relationship. Defaults to None.

None

Returns:

Name Type Description
Any Any

The result of the operation.