SqliteGraphBackend

Struct SqliteGraphBackend 

Source
pub struct SqliteGraphBackend {
    conn: Mutex<Connection>,
    db_path: Option<PathBuf>,
}
Expand description

SQLite-based graph backend.

§Concurrency Model

Uses a Mutex<Connection> for thread-safe access. WAL mode and busy_timeout handle concurrent access gracefully.

§Schema

Three tables store the knowledge graph:

  • graph_entities: Entity nodes with temporal metadata
  • graph_relationships: Directed edges between entities
  • graph_entity_mentions: Links between entities and memories

Fields§

§conn: Mutex<Connection>

Connection to the SQLite database.

§db_path: Option<PathBuf>

Path to the database (None for in-memory).

Implementations§

Source§

impl SqliteGraphBackend

Source

pub fn new(db_path: impl Into<PathBuf>) -> Result<Self>

Creates a new SQLite graph backend.

§Errors

Returns an error if the database cannot be opened or initialized.

Source

pub fn in_memory() -> Result<Self>

Creates an in-memory SQLite graph backend (useful for testing).

§Errors

Returns an error if the database cannot be initialized.

Source

pub fn db_path(&self) -> Option<&Path>

Returns the database path.

Source

fn initialize(&self) -> Result<()>

Initializes the database schema.

Source

fn create_indexes(conn: &Connection)

Creates indexes for optimized queries.

Source

fn parse_entity_row(row: &Row<'_>) -> Result<Entity>

Parses an entity from a database row.

Source

fn parse_relationship_row(row: &Row<'_>) -> Result<Relationship>

Parses a relationship from a database row.

Source

fn build_entity_where_clause( query: &EntityQuery, ) -> (String, Vec<Box<dyn ToSql>>)

Builds WHERE clause conditions for entity queries.

Trait Implementations§

Source§

impl GraphBackend for SqliteGraphBackend

Source§

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

Stores an entity in the graph. Read more
Source§

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

Retrieves an entity by ID. Read more
Source§

fn query_entities(&self, query: &EntityQuery) -> Result<Vec<Entity>>

Queries entities with optional filters. Read more
Source§

fn delete_entity(&self, id: &EntityId) -> Result<bool>

Deletes an entity by ID. Read more
Source§

fn merge_entities( &self, entity_ids: &[EntityId], canonical_name: &str, ) -> Result<Entity>

Merges multiple entities into a canonical entity. Read more
Source§

fn find_entities_by_name( &self, name: &str, entity_type: Option<EntityType>, domain: Option<&Domain>, limit: usize, ) -> Result<Vec<Entity>>

Finds entities by name using fuzzy matching. Read more
Source§

fn store_relationship(&self, relationship: &Relationship) -> Result<()>

Stores a relationship in the graph. Read more
Source§

fn query_relationships( &self, query: &RelationshipQuery, ) -> Result<Vec<Relationship>>

Queries relationships with optional filters. Read more
Source§

fn delete_relationships(&self, query: &RelationshipQuery) -> Result<usize>

Deletes relationships matching the query. Read more
Source§

fn get_relationship_types( &self, from_entity: &EntityId, to_entity: &EntityId, ) -> Result<Vec<RelationshipType>>

Gets all relationship types between two entities. Read more
Source§

fn store_mention(&self, mention: &EntityMention) -> Result<()>

Stores an entity mention (link between entity and memory). Read more
Source§

fn get_mentions_for_entity( &self, entity_id: &EntityId, ) -> Result<Vec<EntityMention>>

Gets all mentions of an entity. Read more
Source§

fn get_entities_in_memory(&self, memory_id: &MemoryId) -> Result<Vec<Entity>>

Gets all entities mentioned in a memory. Read more
Source§

fn delete_mentions_for_entity(&self, entity_id: &EntityId) -> Result<usize>

Deletes all mentions of an entity. Read more
Source§

fn delete_mentions_for_memory(&self, memory_id: &MemoryId) -> Result<usize>

Deletes all entity mentions for a memory. Read more
Source§

fn traverse( &self, start: &EntityId, max_depth: u32, relationship_types: Option<&[RelationshipType]>, min_confidence: Option<f32>, ) -> Result<TraversalResult>

Traverses the graph from a starting entity. Read more
Source§

fn find_path( &self, from: &EntityId, to: &EntityId, max_depth: u32, ) -> Result<Option<TraversalResult>>

Finds the shortest path between two entities. Read more
Source§

fn query_entities_at( &self, query: &EntityQuery, point: &BitemporalPoint, ) -> Result<Vec<Entity>>

Queries entities at a specific point in bitemporal space. Read more
Source§

fn query_relationships_at( &self, query: &RelationshipQuery, point: &BitemporalPoint, ) -> Result<Vec<Relationship>>

Queries relationships at a specific point in bitemporal space. Read more
Source§

fn close_entity_valid_time(&self, id: &EntityId, end_time: i64) -> Result<()>

Closes (ends) an entity’s valid time at the given timestamp. Read more
Source§

fn close_relationship_valid_time( &self, from_entity: &EntityId, to_entity: &EntityId, relationship_type: RelationshipType, end_time: i64, ) -> Result<()>

Closes (ends) a relationship’s valid time at the given timestamp. Read more
Source§

fn get_stats(&self) -> Result<GraphStats>

Returns statistics about the graph. Read more
Source§

fn clear(&self) -> Result<()>

Clears all graph data. Read more
Gets entities related to a given entity within N hops. Read more

Auto Trait Implementations§

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.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,