Expand description
Graph backend trait for knowledge graph storage.
The graph layer provides entity and relationship storage with temporal tracking, enabling knowledge graph construction and traversal.
§Available Implementations
| Backend | Use Case | Features |
|---|---|---|
SqliteGraphBackend | Default; embedded | Recursive CTEs for traversal |
InMemoryGraphBackend | Testing | Fast, no persistence |
Neo4jGraphBackend | Future | Native graph operations |
§Error Modes and Guarantees
All backends return Result<T> with errors propagated via crate::Error.
§Entity Operations
| Operation | Complexity | Notes |
|---|---|---|
store_entity | O(1) | Insert or update |
get_entity | O(1) | By ID lookup |
query_entities | O(log n) | With filters |
delete_entity | O(k) | k = relationship count |
§Relationship Operations
| Operation | Complexity | Notes |
|---|---|---|
store_relationship | O(1) | Insert or update |
query_relationships | O(log n) | With filters |
traverse | O(b^d) | b = branching, d = depth |
§Temporal Queries
Bitemporal queries filter by both valid_time and transaction_time:
valid_at: Filter entities/relationships valid at a point in timeas_of: Filter by when records were known to the system
§Example
ⓘ
use subcog::storage::traits::GraphBackend;
use subcog::models::graph::{Entity, EntityType, EntityQuery};
// Query all Person entities with confidence > 0.8
let query = EntityQuery::new()
.with_type(EntityType::Person)
.with_min_confidence(0.8)
.with_limit(20);
let people = backend.query_entities(&query)?;Structs§
- Graph
Stats - Statistics about the knowledge graph.
Traits§
- Graph
Backend - Trait for graph layer backends.