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
GraphAnalyticsfor 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 withenable_cache()/disable_cache()
- Optional in-process result caching with
- GraphAnalytics — Degree centrality ordered by degree DESC
- Connected component assignment
- Shortest path between nodes, neighbor traversal up to N hops
- Bulk Operations —
create_nodes(list): one round-trip for many nodescreate_relationship()with typed propertiesdelete_node(detach=True)removes all connected relationships
- Schema Management —
create_index(label, property_name=): makes MATCH queries orders-of-magnitude fasterget_stats(): node counts, edge counts, type breakdown- Create indexes before bulk loading for best performance
- Path Traversal —
shortest_path()returnslength,nodes,relationshipsget_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:
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
- Neo4j (recommended)
- FalkorDB
- Apache AGE
- Amazon Neptune
- Backend Comparison
Graph Operations
QueryEngine
QueryEngine handles query execution and optional caching. Access it via store.query_engine:
QueryEngine Methods
GraphAnalytics
Access analytics viastore._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
Common Workflows
- Build from KG data
- Parameterized queries
- Neighbor traversal
- Apache AGE notes
- 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.
