Skip to main content

GraphBackend

Trait GraphBackend 

Source
pub trait GraphBackend: Send + Sync {
Show 17 methods // Required methods fn upsert_node(&self, node: &GraphNode) -> Result<()>; fn read_node(&self, id: &str) -> Result<Option<GraphNode>>; fn delete_node(&self, id: &str) -> Result<bool>; fn search_nodes(&self, query: &str, limit: usize) -> Result<Vec<GraphNode>>; fn query_nodes( &self, tag: Option<&str>, node_type: Option<&str>, project: Option<&str>, limit: usize, ) -> Result<Vec<GraphNode>>; fn smart_recall( &self, project: Option<&str>, hint: Option<&str>, limit: usize, ) -> Result<Vec<ScoredNode>>; fn related_nodes(&self, start_id: &str, depth: usize) -> Result<Vec<String>>; fn append_edge(&self, edge: &GraphEdge) -> Result<()>; fn edges_for_node(&self, node_id: &str) -> Result<Vec<GraphEdge>>; fn delete_edge(&self, id: &str) -> Result<bool>; fn remove_edges_for_node(&self, node_id: &str) -> Result<()>; fn current_version(&self) -> Result<u32>; fn migrate(&self) -> Result<u32>; // Provided methods fn append_edges(&self, edges: &[GraphEdge]) -> Result<()> { ... } fn edges_for_node_dir( &self, node_id: &str, dir: EdgeDirection, relation: Option<&str>, ) -> Result<Vec<GraphEdge>> { ... } fn neighbors_weighted( &self, seed_ids: &[String], dir: EdgeDirection, relation: Option<&str>, ) -> Result<Vec<(String, f64)>> { ... } fn related_nodes_filtered( &self, start_id: &str, depth: usize, dir: EdgeDirection, relation: Option<&str>, ) -> Result<Vec<String>> { ... }
}
Expand description

Sync, object-safe trait for graph backends.

Methods cover node/edge CRUD, FTS search, filtered query, and schema migration. No method exposes rusqlite types, so the trait is implementable by any backend. dyn GraphBackend is usable.

Required Methods§

Source

fn upsert_node(&self, node: &GraphNode) -> Result<()>

Insert or replace a node.

Source

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

Read a single node by ID (None if absent).

Source

fn delete_node(&self, id: &str) -> Result<bool>

Delete a node by ID. Returns true if a row was removed.

Source

fn search_nodes(&self, query: &str, limit: usize) -> Result<Vec<GraphNode>>

FTS5 full-text search, ranked by importance DESC.

Source

fn query_nodes( &self, tag: Option<&str>, node_type: Option<&str>, project: Option<&str>, limit: usize, ) -> Result<Vec<GraphNode>>

Dynamic filter by tag / node_type / project.

Source

fn smart_recall( &self, project: Option<&str>, hint: Option<&str>, limit: usize, ) -> Result<Vec<ScoredNode>>

Composite recall — rank nodes by recency, importance, access, FTS, and graph boost. The canonical high-level read path for “what’s relevant”.

Source

fn related_nodes(&self, start_id: &str, depth: usize) -> Result<Vec<String>>

BFS-traverse up to depth hops from start_id, returning related node IDs (excluding the start).

Source

fn append_edge(&self, edge: &GraphEdge) -> Result<()>

Append an edge (duplicates by edge ID are ignored).

Source

fn edges_for_node(&self, node_id: &str) -> Result<Vec<GraphEdge>>

Read edges where the given node is source or target.

Source

fn delete_edge(&self, id: &str) -> Result<bool>

Delete an edge by ID. Returns true if a row was removed.

Source

fn remove_edges_for_node(&self, node_id: &str) -> Result<()>

Remove every edge connected to a node.

Source

fn current_version(&self) -> Result<u32>

Recorded schema version for this backend.

Source

fn migrate(&self) -> Result<u32>

Apply pending migrations up to the backend’s latest schema version. Returns the resulting version.

Provided Methods§

Source

fn append_edges(&self, edges: &[GraphEdge]) -> Result<()>

Append many edges in one call.

Duplicates by edge ID or by the (source, target, relation) unique index are ignored. The default implementation loops Self::append_edge; backends with a batch path override it for throughput (citation graphs built during indexing can reach hundreds of thousands of edges).

Source

fn edges_for_node_dir( &self, node_id: &str, dir: EdgeDirection, relation: Option<&str>, ) -> Result<Vec<GraphEdge>>

Read edges touching node_id, filtered by direction and an optional relation. The default implementation reads both directions via Self::edges_for_node and filters in Rust; backends with directional indexes override for efficiency.

Source

fn neighbors_weighted( &self, seed_ids: &[String], dir: EdgeDirection, relation: Option<&str>, ) -> Result<Vec<(String, f64)>>

1-hop neighbors of seed_ids (weighted sum), restricted by direction and an optional relation. Seed nodes are excluded. The default implementation walks each seed via Self::edges_for_node_dir.

Source

fn related_nodes_filtered( &self, start_id: &str, depth: usize, dir: EdgeDirection, relation: Option<&str>, ) -> Result<Vec<String>>

BFS-traverse up to depth hops from start_id, returning related node IDs (excluding the start), restricted by direction and an optional relation. The default implementation hops via Self::neighbors_weighted.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§