Skip to main content

GraphBackend

Trait GraphBackend 

Source
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§

Source

fn add_node(&mut self, node: GraphNode) -> Result<(), CodememError>

Add a node to the graph.

Source

fn get_node(&self, id: &str) -> Result<Option<GraphNode>, CodememError>

Get a node by ID.

Source

fn remove_node(&mut self, id: &str) -> Result<bool, CodememError>

Remove a node by ID.

Source

fn add_edge(&mut self, edge: Edge) -> Result<(), CodememError>

Add an edge between two nodes.

Source

fn get_edges(&self, node_id: &str) -> Result<Vec<Edge>, CodememError>

Get edges from a node.

Source

fn remove_edge(&mut self, id: &str) -> Result<bool, CodememError>

Remove an edge by ID.

Source

fn bfs( &self, start_id: &str, max_depth: usize, ) -> Result<Vec<GraphNode>, CodememError>

BFS traversal from a start node up to max_depth.

Source

fn dfs( &self, start_id: &str, max_depth: usize, ) -> Result<Vec<GraphNode>, CodememError>

DFS traversal from a start node up to max_depth.

Source

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.

Source

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.

Source

fn shortest_path( &self, from: &str, to: &str, ) -> Result<Vec<String>, CodememError>

Shortest path between two nodes.

Source

fn stats(&self) -> GraphStats

Get graph statistics.

Provided Methods§

Source

fn get_all_nodes(&self) -> Vec<GraphNode>

Get all nodes in the graph.

Source

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.

Source

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.

Source

fn node_count(&self) -> usize

Number of nodes in the graph.

Source

fn edge_count(&self) -> usize

Number of edges in the graph.

Source

fn recompute_centrality(&mut self)

Recompute all centrality metrics (PageRank + betweenness).

Source

fn recompute_centrality_with_options(&mut self, _include_betweenness: bool)

Recompute centrality, optionally including expensive betweenness calculation.

Source

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.

Source

fn ensure_betweenness_computed(&mut self)

Lazily compute betweenness centrality if not yet computed.

Source

fn compute_centrality(&mut self)

Compute degree centrality (updates nodes in place).

Source

fn get_pagerank(&self, _node_id: &str) -> f64

Get cached PageRank score for a node.

Source

fn get_betweenness(&self, _node_id: &str) -> f64

Get cached betweenness centrality score for a node.

Source

fn raw_graph_metrics_for_memory( &self, _memory_id: &str, ) -> Option<RawGraphMetrics>

Collect graph metrics for a memory node (used in hybrid scoring).

Source

fn connected_components(&self) -> Vec<Vec<String>>

Find connected components (treating graph as undirected).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn louvain_with_assignment(&self, resolution: f64) -> HashMap<String, usize>

Return node-to-community-ID mapping for Louvain.

Source

fn subgraph_top_n( &self, _n: usize, _namespace: Option<&str>, _kinds: Option<&[NodeKind]>, ) -> (Vec<GraphNode>, Vec<Edge>)

Return a top-N subgraph: the highest-centrality nodes plus all edges between them. Non-structural edges from top-N nodes pull their targets into the result.

Implementors§