Skip to main content

Graph

Struct Graph 

Source
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

Source

pub fn open(db_path: &Path) -> Result<Self>

Open an existing database file.

Source

pub fn open_or_create(db_path: &Path) -> Result<Self>

Open an existing database or create a new one at the given path.

Source

pub fn in_memory() -> Result<Self>

Open an in-memory database (for testing or ephemeral use).

Source

pub fn add_episode(&self, episode: Episode) -> Result<EpisodeResult>

Add an episode (event, decision, message) to the graph.

Source

pub fn get_episode(&self, id: &str) -> Result<Option<Episode>>

Get an episode by ID.

Source

pub fn list_episodes(&self, limit: usize, offset: usize) -> Result<Vec<Episode>>

List episodes with pagination.

Source

pub fn add_entity(&self, entity: Entity) -> Result<()>

Add an entity (node) to the graph.

Source

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).

Source

pub fn get_entity(&self, id: &str) -> Result<Option<Entity>>

Get an entity by ID.

Source

pub fn get_entity_by_name(&self, name: &str) -> Result<Option<Entity>>

Get an entity by name.

Source

pub fn list_entities( &self, entity_type: Option<&str>, limit: usize, ) -> Result<Vec<Entity>>

List entities, optionally filtered by type.

Source

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

Add an edge (relationship) between two entities.

Source

pub fn get_edges_for_entity(&self, entity_id: &str) -> Result<Vec<Edge>>

Get all edges for an entity (both as source and target).

Source

pub fn invalidate_edge(&self, edge_id: &str) -> Result<()>

Invalidate an edge (set valid_until to now).

Link an episode to an entity (with optional character span).

Source

pub fn store_embedding(&self, episode_id: &str, embedding: &[f32]) -> Result<()>

Store an embedding for an episode (serialized as little-endian f32 bytes).

Source

pub fn store_entity_embedding( &self, entity_id: &str, embedding: &[f32], ) -> Result<()>

Store an embedding for an entity.

Source

pub fn get_embeddings(&self) -> Result<Vec<(String, Vec<f32>)>>

Load all episode embeddings as (episode_id, Vec) pairs.

Source

pub fn search(&self, query: &str, limit: usize) -> Result<Vec<(Episode, f64)>>

Search episodes via FTS5 full-text search.

Source

pub fn search_entities( &self, query: &str, limit: usize, ) -> Result<Vec<(Entity, f64)>>

Search entities via FTS5.

Source

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.

Source

pub fn get_entity_context(&self, entity_id: &str) -> Result<EntityContext>

Get context around an entity — its neighbors and connecting edges.

Source

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.

Source

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.

Source

pub fn stats(&self) -> Result<GraphStats>

Get graph-wide statistics.

Auto Trait Implementations§

§

impl !Freeze for Graph

§

impl !RefUnwindSafe for Graph

§

impl Send for Graph

§

impl !Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl !UnwindSafe for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.