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 metadatagraph_relationships: Directed edges between entitiesgraph_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
impl SqliteGraphBackend
Sourcepub fn new(db_path: impl Into<PathBuf>) -> Result<Self>
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.
Sourcepub fn in_memory() -> Result<Self>
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.
Sourcefn initialize(&self) -> Result<()>
fn initialize(&self) -> Result<()>
Initializes the database schema.
Sourcefn create_indexes(conn: &Connection)
fn create_indexes(conn: &Connection)
Creates indexes for optimized queries.
Sourcefn parse_entity_row(row: &Row<'_>) -> Result<Entity>
fn parse_entity_row(row: &Row<'_>) -> Result<Entity>
Parses an entity from a database row.
Sourcefn parse_relationship_row(row: &Row<'_>) -> Result<Relationship>
fn parse_relationship_row(row: &Row<'_>) -> Result<Relationship>
Parses a relationship from a database row.
Sourcefn build_entity_where_clause(
query: &EntityQuery,
) -> (String, Vec<Box<dyn ToSql>>)
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
impl GraphBackend for SqliteGraphBackend
Source§fn store_entity(&self, entity: &Entity) -> Result<()>
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>>
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>>
fn query_entities(&self, query: &EntityQuery) -> Result<Vec<Entity>>
Queries entities with optional filters. Read more
Source§fn merge_entities(
&self,
entity_ids: &[EntityId],
canonical_name: &str,
) -> Result<Entity>
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>>
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<()>
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>>
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>
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>>
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<()>
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>>
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>>
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>
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>
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>
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>>
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>>
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>>
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<()>
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<()>
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
Gets entities related to a given entity within N hops. Read more
Auto Trait Implementations§
impl !Freeze for SqliteGraphBackend
impl RefUnwindSafe for SqliteGraphBackend
impl Send for SqliteGraphBackend
impl Sync for SqliteGraphBackend
impl Unpin for SqliteGraphBackend
impl UnwindSafe for SqliteGraphBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
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].