pub trait GraphBackend: Send + Sync {
Show 33 methods
// Required methods
fn add_node(&mut self, node: GraphNode) -> Result<(), CodememError>;
fn get_node(&self, id: &str) -> Result<Option<GraphNode>, CodememError>;
fn remove_node(&mut self, id: &str) -> Result<bool, CodememError>;
fn add_edge(&mut self, edge: Edge) -> Result<(), CodememError>;
fn get_edges(&self, node_id: &str) -> Result<Vec<Edge>, CodememError>;
fn remove_edge(&mut self, id: &str) -> Result<bool, CodememError>;
fn bfs(
&self,
start_id: &str,
max_depth: usize,
) -> Result<Vec<GraphNode>, CodememError>;
fn dfs(
&self,
start_id: &str,
max_depth: usize,
) -> Result<Vec<GraphNode>, CodememError>;
fn bfs_filtered(
&self,
start_id: &str,
max_depth: usize,
exclude_kinds: &[NodeKind],
include_relationships: Option<&[RelationshipType]>,
) -> Result<Vec<GraphNode>, CodememError>;
fn dfs_filtered(
&self,
start_id: &str,
max_depth: usize,
exclude_kinds: &[NodeKind],
include_relationships: Option<&[RelationshipType]>,
) -> Result<Vec<GraphNode>, CodememError>;
fn shortest_path(
&self,
from: &str,
to: &str,
) -> Result<Vec<String>, CodememError>;
fn stats(&self) -> GraphStats;
// Provided methods
fn get_all_nodes(&self) -> Vec<GraphNode> { ... }
fn get_node_ref(&self, _id: &str) -> Option<&GraphNode> { ... }
fn get_edges_ref(&self, _node_id: &str) -> Vec<&Edge> { ... }
fn node_count(&self) -> usize { ... }
fn edge_count(&self) -> usize { ... }
fn recompute_centrality(&mut self) { ... }
fn recompute_centrality_with_options(&mut self, _include_betweenness: bool) { ... }
fn recompute_centrality_for_namespace(&mut self, _namespace: &str) { ... }
fn ensure_betweenness_computed(&mut self) { ... }
fn compute_centrality(&mut self) { ... }
fn get_pagerank(&self, _node_id: &str) -> f64 { ... }
fn get_betweenness(&self, _node_id: &str) -> f64 { ... }
fn raw_graph_metrics_for_memory(
&self,
_memory_id: &str,
) -> Option<RawGraphMetrics> { ... }
fn connected_components(&self) -> Vec<Vec<String>> { ... }
fn strongly_connected_components(&self) -> Vec<Vec<String>> { ... }
fn pagerank(
&self,
_damping: f64,
_iterations: usize,
_tolerance: f64,
) -> HashMap<String, f64> { ... }
fn pagerank_for_namespace(
&self,
_namespace: &str,
_damping: f64,
_iterations: usize,
_tolerance: f64,
) -> HashMap<String, f64> { ... }
fn louvain_communities(&self, _resolution: f64) -> Vec<Vec<String>> { ... }
fn topological_layers(&self) -> Vec<Vec<String>> { ... }
fn louvain_with_assignment(&self, resolution: f64) -> HashMap<String, usize> { ... }
fn subgraph_top_n(
&self,
_n: usize,
_namespace: Option<&str>,
_kinds: Option<&[NodeKind]>,
) -> (Vec<GraphNode>, Vec<Edge>) { ... }
}Expand description
Graph backend trait for graph operations.
§Default implementations
Extended methods (centrality, community detection, etc.) have no-op defaults
so that the core CRUD + traversal methods are sufficient for a minimal
implementation. Backend authors should override the algorithmic methods
relevant to their storage engine. The in-memory GraphEngine overrides all
of them.
§_ref methods
get_node_ref and get_edges_ref return borrowed references into the
backend’s in-memory storage. They exist for zero-copy hot-path performance
in the default GraphEngine. Database-backed implementations cannot return
references to internal state and should leave the defaults (which return
None / empty). Callers that need database compatibility should use the
owned variants get_node / get_edges instead.
Required Methods§
Sourcefn remove_node(&mut self, id: &str) -> Result<bool, CodememError>
fn remove_node(&mut self, id: &str) -> Result<bool, CodememError>
Remove a node by ID.
Sourcefn remove_edge(&mut self, id: &str) -> Result<bool, CodememError>
fn remove_edge(&mut self, id: &str) -> Result<bool, CodememError>
Remove an edge by ID.
Sourcefn bfs(
&self,
start_id: &str,
max_depth: usize,
) -> Result<Vec<GraphNode>, CodememError>
fn bfs( &self, start_id: &str, max_depth: usize, ) -> Result<Vec<GraphNode>, CodememError>
BFS traversal from a start node up to max_depth.
Sourcefn dfs(
&self,
start_id: &str,
max_depth: usize,
) -> Result<Vec<GraphNode>, CodememError>
fn dfs( &self, start_id: &str, max_depth: usize, ) -> Result<Vec<GraphNode>, CodememError>
DFS traversal from a start node up to max_depth.
Sourcefn bfs_filtered(
&self,
start_id: &str,
max_depth: usize,
exclude_kinds: &[NodeKind],
include_relationships: Option<&[RelationshipType]>,
) -> Result<Vec<GraphNode>, CodememError>
fn bfs_filtered( &self, start_id: &str, max_depth: usize, exclude_kinds: &[NodeKind], include_relationships: Option<&[RelationshipType]>, ) -> Result<Vec<GraphNode>, CodememError>
BFS traversal with filtering: exclude certain node kinds and optionally restrict to specific relationship types.
Sourcefn dfs_filtered(
&self,
start_id: &str,
max_depth: usize,
exclude_kinds: &[NodeKind],
include_relationships: Option<&[RelationshipType]>,
) -> Result<Vec<GraphNode>, CodememError>
fn dfs_filtered( &self, start_id: &str, max_depth: usize, exclude_kinds: &[NodeKind], include_relationships: Option<&[RelationshipType]>, ) -> Result<Vec<GraphNode>, CodememError>
DFS traversal with filtering: exclude certain node kinds and optionally restrict to specific relationship types.
Sourcefn shortest_path(
&self,
from: &str,
to: &str,
) -> Result<Vec<String>, CodememError>
fn shortest_path( &self, from: &str, to: &str, ) -> Result<Vec<String>, CodememError>
Shortest path between two nodes.
Sourcefn stats(&self) -> GraphStats
fn stats(&self) -> GraphStats
Get graph statistics.
Provided Methods§
Sourcefn get_all_nodes(&self) -> Vec<GraphNode>
fn get_all_nodes(&self) -> Vec<GraphNode>
Get all nodes in the graph.
Sourcefn get_node_ref(&self, _id: &str) -> Option<&GraphNode>
fn get_node_ref(&self, _id: &str) -> Option<&GraphNode>
Zero-copy node lookup. Returns a reference into the backend’s internal storage.
Only meaningful for in-memory backends. Database backends should leave the
default (returns None) and callers should use get_node() instead.
Sourcefn get_edges_ref(&self, _node_id: &str) -> Vec<&Edge>
fn get_edges_ref(&self, _node_id: &str) -> Vec<&Edge>
Zero-copy edge lookup. Returns references into the backend’s internal storage.
Only meaningful for in-memory backends. Database backends should leave the
default (returns empty) and callers should use get_edges() instead.
Sourcefn node_count(&self) -> usize
fn node_count(&self) -> usize
Number of nodes in the graph.
Sourcefn edge_count(&self) -> usize
fn edge_count(&self) -> usize
Number of edges in the graph.
Sourcefn recompute_centrality(&mut self)
fn recompute_centrality(&mut self)
Recompute all centrality metrics (PageRank + betweenness).
Sourcefn recompute_centrality_with_options(&mut self, _include_betweenness: bool)
fn recompute_centrality_with_options(&mut self, _include_betweenness: bool)
Recompute centrality, optionally including expensive betweenness calculation.
Sourcefn recompute_centrality_for_namespace(&mut self, _namespace: &str)
fn recompute_centrality_for_namespace(&mut self, _namespace: &str)
Recompute PageRank scoped to a single namespace, updating only that namespace’s scores in the cache. Nodes from other namespaces are unaffected.
Sourcefn ensure_betweenness_computed(&mut self)
fn ensure_betweenness_computed(&mut self)
Lazily compute betweenness centrality if not yet computed.
Sourcefn compute_centrality(&mut self)
fn compute_centrality(&mut self)
Compute degree centrality (updates nodes in place).
Sourcefn get_pagerank(&self, _node_id: &str) -> f64
fn get_pagerank(&self, _node_id: &str) -> f64
Get cached PageRank score for a node.
Sourcefn get_betweenness(&self, _node_id: &str) -> f64
fn get_betweenness(&self, _node_id: &str) -> f64
Get cached betweenness centrality score for a node.
Sourcefn raw_graph_metrics_for_memory(
&self,
_memory_id: &str,
) -> Option<RawGraphMetrics>
fn raw_graph_metrics_for_memory( &self, _memory_id: &str, ) -> Option<RawGraphMetrics>
Collect graph metrics for a memory node (used in hybrid scoring).
Sourcefn connected_components(&self) -> Vec<Vec<String>>
fn connected_components(&self) -> Vec<Vec<String>>
Find connected components (treating graph as undirected).
Sourcefn strongly_connected_components(&self) -> Vec<Vec<String>>
fn strongly_connected_components(&self) -> Vec<Vec<String>>
Find strongly connected components using Tarjan’s algorithm. Each SCC is a group where every node can reach every other via directed edges.
Sourcefn pagerank(
&self,
_damping: f64,
_iterations: usize,
_tolerance: f64,
) -> HashMap<String, f64>
fn pagerank( &self, _damping: f64, _iterations: usize, _tolerance: f64, ) -> HashMap<String, f64>
Compute PageRank scores for all nodes. Returns a map from node ID to PageRank score.
Sourcefn pagerank_for_namespace(
&self,
_namespace: &str,
_damping: f64,
_iterations: usize,
_tolerance: f64,
) -> HashMap<String, f64>
fn pagerank_for_namespace( &self, _namespace: &str, _damping: f64, _iterations: usize, _tolerance: f64, ) -> HashMap<String, f64>
Compute PageRank scores for nodes in a single namespace.
Only nodes belonging to namespace participate; cross-namespace edges are ignored.
Returns a map from node ID to PageRank score (only for nodes in the namespace).
Default is abstract; implementers must provide namespace-scoped computation.
Sourcefn louvain_communities(&self, _resolution: f64) -> Vec<Vec<String>>
fn louvain_communities(&self, _resolution: f64) -> Vec<Vec<String>>
Run Louvain community detection at the given resolution. Returns groups of node IDs, one group per community.
Sourcefn topological_layers(&self) -> Vec<Vec<String>>
fn topological_layers(&self) -> Vec<Vec<String>>
Compute topological layers of the graph. Returns layers where all nodes in layer i have no dependencies on nodes in layer i or later.