pub struct Graph { /* private fields */ }Expand description
An embeddable graph database built on SQLite.
Provides entity/edge storage, bi-temporal edges, FTS5 search, vector embeddings with RRF fusion, and recursive CTE traversal.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn open_or_create(db_path: &Path) -> Result<Self>
pub fn open_or_create(db_path: &Path) -> Result<Self>
Open an existing database or create a new one at the given path.
Sourcepub fn add_episode(&self, episode: Episode) -> Result<EpisodeResult>
pub fn add_episode(&self, episode: Episode) -> Result<EpisodeResult>
Add an episode (event, decision, message) to the graph.
Sourcepub fn list_episodes(&self, limit: usize, offset: usize) -> Result<Vec<Episode>>
pub fn list_episodes(&self, limit: usize, offset: usize) -> Result<Vec<Episode>>
List episodes with pagination.
Sourcepub fn add_entity(&self, entity: Entity) -> Result<()>
pub fn add_entity(&self, entity: Entity) -> Result<()>
Add an entity (node) to the graph.
Sourcepub fn add_entity_deduped(
&self,
entity: Entity,
threshold: f64,
) -> Result<(String, bool)>
pub fn add_entity_deduped( &self, entity: Entity, threshold: f64, ) -> Result<(String, bool)>
Add an entity with fuzzy deduplication against existing entities of the same type.
If an existing entity with Jaro-Winkler similarity >= threshold exists, returns that entity’s ID and stores the new name as an alias. Otherwise creates a new entity.
Returns (entity_id, was_merged: bool).
Sourcepub fn list_entities(
&self,
entity_type: Option<&str>,
limit: usize,
) -> Result<Vec<Entity>>
pub fn list_entities( &self, entity_type: Option<&str>, limit: usize, ) -> Result<Vec<Entity>>
List entities, optionally filtered by type.
Sourcepub fn add_edge(&self, edge: Edge) -> Result<()>
pub fn add_edge(&self, edge: Edge) -> Result<()>
Add an edge (relationship) between two entities.
Sourcepub fn get_edges_for_entity(&self, entity_id: &str) -> Result<Vec<Edge>>
pub fn get_edges_for_entity(&self, entity_id: &str) -> Result<Vec<Edge>>
Get all edges for an entity (both as source and target).
Sourcepub fn invalidate_edge(&self, edge_id: &str) -> Result<()>
pub fn invalidate_edge(&self, edge_id: &str) -> Result<()>
Invalidate an edge (set valid_until to now).
Sourcepub fn link_episode_entity(
&self,
episode_id: &str,
entity_id: &str,
span_start: Option<usize>,
span_end: Option<usize>,
) -> Result<()>
pub fn link_episode_entity( &self, episode_id: &str, entity_id: &str, span_start: Option<usize>, span_end: Option<usize>, ) -> Result<()>
Link an episode to an entity (with optional character span).
Sourcepub fn store_embedding(&self, episode_id: &str, embedding: &[f32]) -> Result<()>
pub fn store_embedding(&self, episode_id: &str, embedding: &[f32]) -> Result<()>
Store an embedding for an episode (serialized as little-endian f32 bytes).
Sourcepub fn store_entity_embedding(
&self,
entity_id: &str,
embedding: &[f32],
) -> Result<()>
pub fn store_entity_embedding( &self, entity_id: &str, embedding: &[f32], ) -> Result<()>
Store an embedding for an entity.
Sourcepub fn get_embeddings(&self) -> Result<Vec<(String, Vec<f32>)>>
pub fn get_embeddings(&self) -> Result<Vec<(String, Vec<f32>)>>
Load all episode embeddings as (episode_id, Vec
Sourcepub fn search(&self, query: &str, limit: usize) -> Result<Vec<(Episode, f64)>>
pub fn search(&self, query: &str, limit: usize) -> Result<Vec<(Episode, f64)>>
Search episodes via FTS5 full-text search.
Sourcepub fn search_entities(
&self,
query: &str,
limit: usize,
) -> Result<Vec<(Entity, f64)>>
pub fn search_entities( &self, query: &str, limit: usize, ) -> Result<Vec<(Entity, f64)>>
Search entities via FTS5.
Sourcepub fn search_fused(
&self,
query: &str,
query_embedding: &[f32],
limit: usize,
) -> Result<Vec<FusedEpisodeResult>>
pub fn search_fused( &self, query: &str, query_embedding: &[f32], limit: usize, ) -> Result<Vec<FusedEpisodeResult>>
Fused search using Reciprocal Rank Fusion (RRF) over FTS5 + semantic results.
query_embedding should be the pre-computed embedding for query.
Returns episodes ranked by combined RRF score.
Sourcepub fn get_entity_context(&self, entity_id: &str) -> Result<EntityContext>
pub fn get_entity_context(&self, entity_id: &str) -> Result<EntityContext>
Get context around an entity — its neighbors and connecting edges.
Sourcepub fn traverse(
&self,
start_entity_id: &str,
max_depth: usize,
) -> Result<(Vec<Entity>, Vec<Edge>)>
pub fn traverse( &self, start_entity_id: &str, max_depth: usize, ) -> Result<(Vec<Entity>, Vec<Edge>)>
Multi-hop graph traversal from a starting entity.
Returns all entities reachable within max_depth hops and the edges connecting them.
Sourcepub fn traverse_with_history(
&self,
start_entity_id: &str,
max_depth: usize,
) -> Result<(Vec<Entity>, Vec<Edge>)>
pub fn traverse_with_history( &self, start_entity_id: &str, max_depth: usize, ) -> Result<(Vec<Entity>, Vec<Edge>)>
Multi-hop traversal including historical (invalidated) edges.
Sourcepub fn stats(&self) -> Result<GraphStats>
pub fn stats(&self) -> Result<GraphStats>
Get graph-wide statistics.