semantica.graph_store provides a single unified API for persisting and querying knowledge graphs in production graph databases:
  • Swap backends with a one-line change: Neo4j, FalkorDB, Apache AGE, Amazon Neptune
  • Parameterized Cypher execution with optional result caching via QueryEngine
  • Batch node and edge loading: faster than individual writes
  • GraphAnalytics for degree centrality, connected components, shortest path, neighbor traversal
  • Context manager support: with GraphStore(...) as store: closes connection automatically

Exported Classes

What You Get

  • GraphStore — Unified API across Neo4j, FalkorDB, Apache AGE, Amazon Neptune
    • Context manager support for automatic connection cleanup
    • create_nodes() for bulk loading: faster than individual calls
  • QueryEngine — Parameterized Cypher construction prevents injection attacks
    • Optional in-process result caching with use_cache=True
    • clear_cache() on writes, toggle with enable_cache() / disable_cache()
  • GraphAnalytics — Degree centrality ordered by degree DESC
    • Connected component assignment
    • Shortest path between nodes, neighbor traversal up to N hops
  • Bulk Operationscreate_nodes(list): one round-trip for many nodes
    • create_relationship() with typed properties
    • delete_node(detach=True) removes all connected relationships
  • Schema Managementcreate_index(label, property_name=): makes MATCH queries orders-of-magnitude faster
    • get_stats(): node counts, edge counts, type breakdown
    • Create indexes before bulk loading for best performance
  • Path Traversalshortest_path() returns length, nodes, relationships
    • get_neighbors() with direction and depth control
    • Cross-backend path traversal via the unified API

Getting Started

GraphStore wraps the backend of your choice behind a single API. Call connect() (or use it as a context manager) before running any queries:
Use as a context manager to close the connection automatically:
Call connect() before any operations. GraphStore does not connect automatically on construction. Either call store.connect() explicitly or use the context manager form with GraphStore(...) as store:.

Quick Start

1

Connect to a graph database

2

Create indexes before loading data

3

Load nodes and relationships

4

Query the graph

GraphStore Methods

Backends

Graph Operations

Use create_nodes() for bulk loading. Individual create_node() calls issue one network round-trip each. create_nodes(list) is faster for initial graph population.

QueryEngine

QueryEngine handles query execution and optional caching. Access it via store.query_engine:

QueryEngine Methods

Use QueryEngine caching for read-heavy workloads. Access the engine via store.query_engine. Call engine.execute(query, use_cache=True) to cache identical queries in-process. Call engine.clear_cache() after writes that invalidate results.
Use parameterized queries, never string interpolation. store.query("WHERE n.name = $name", parameters={"name": user_input}) prevents Cypher injection attacks. Never use f"WHERE n.name = '{user_input}'".

GraphAnalytics

Access analytics via store._manager.analytics or construct directly with the backend store instance:

GraphAnalytics Methods

betweenness_centrality(), pagerank(), detect_communities(), and all_paths() are not implemented. Use Neo4j GDS procedures directly via store.execute_query() for those algorithms.

Schema Management

Create indexes before bulk loading. store.create_index(label="Person", property_name="name") makes MATCH queries on name orders of magnitude faster. Without indexes, every query does a full scan. Create indexes first, then load data.
create_index parameter is property_name=, not property=. store.create_index(label="Person", property_name="name"): using property= will be silently ignored.

Common Workflows

  • KG Module — Build the graph before persisting it.
  • Triplet Store — RDF triple store for semantic web and SPARQL queries.
  • Visualization — Visualize graphs stored in any backend.
  • Context — AgentContext uses GraphStore for memory retrieval.