pub struct SqliteGraph { /* private fields */ }Expand description
SQLite-backed GraphBackend over one mutex-guarded connection.
Opening applies the schema and runs any pending migrations, so a database
created by an older llm-kernel is upgraded transparently on open.
Implementations§
Source§impl SqliteGraph
impl SqliteGraph
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Open (or create) a graph database at path, applying schema + migrations.
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Create an in-memory graph (useful for tests and ephemeral stores).
Sourcepub fn mark_verified(&self, id: &str, now: &str) -> Result<bool>
pub fn mark_verified(&self, id: &str, now: &str) -> Result<bool>
Record that a node’s content was verified as of now (ISO 8601).
Convenience wrapper over crate::graph::lifecycle::mark_verified —
the connection is owned by the graph, so callers don’t need to open
their own.
Sourcepub fn count_expired_nodes(&self, now: &str) -> Result<u64>
pub fn count_expired_nodes(&self, now: &str) -> Result<u64>
Count nodes whose valid_until is set and earlier than now (ISO 8601).
Convenience wrapper over crate::graph::lifecycle::count_expired_nodes.
Sourcepub fn with_tx(&self, f: impl FnOnce(&Connection) -> Result<()>) -> Result<()>
pub fn with_tx(&self, f: impl FnOnce(&Connection) -> Result<()>) -> Result<()>
Run f against the underlying connection inside one transaction.
Commits when f returns Ok, rolls back on Err — so multi-step
sequences (e.g. delete-then-insert edge replacement) cannot leave a
half-applied state. f receives &Connection: the transaction derefs
to it, so the free functions in crate::graph::store work as-is.
Do not call other SqliteGraph methods on the same instance inside
f — they re-acquire the connection lock and will deadlock. Use only
the free functions on the passed connection. Similarly, avoid the
free functions that open their own transaction inside f — notably
crate::graph::store::append_edges and
crate::graph::store::delete_node — they fail with “cannot start a
transaction within a transaction”. Their single-item counterparts
(crate::graph::store::append_edge, plain DELETE) are safe.
Source§impl SqliteGraph
CJK-aware convenience methods (available with the graph-cjk feature).
impl SqliteGraph
CJK-aware convenience methods (available with the graph-cjk feature).
Sourcepub fn search_nodes_cjk(
&self,
query: &str,
limit: usize,
) -> Result<Vec<GraphNode>>
pub fn search_nodes_cjk( &self, query: &str, limit: usize, ) -> Result<Vec<GraphNode>>
CJK (or mixed) search via contiguous substring matching.
Delegates to crate::graph::cjk::search_nodes_cjk; see its docs for
the matching semantics.
Sourcepub fn segment_cjk(text: &str) -> String
pub fn segment_cjk(text: &str) -> String
Segment a string for CJK tokenization (exposed for callers that want to pre-process queries or inspect tokenization).
Trait Implementations§
Source§impl GraphBackend for SqliteGraph
impl GraphBackend for SqliteGraph
Source§fn read_node(&self, id: &str) -> Result<Option<GraphNode>>
fn read_node(&self, id: &str) -> Result<Option<GraphNode>>
None if absent).Source§fn delete_node(&self, id: &str) -> Result<bool>
fn delete_node(&self, id: &str) -> Result<bool>
true if a row was removed.Source§fn search_nodes(&self, query: &str, limit: usize) -> Result<Vec<GraphNode>>
fn search_nodes(&self, query: &str, limit: usize) -> Result<Vec<GraphNode>>
Source§fn query_nodes(
&self,
tag: Option<&str>,
node_type: Option<&str>,
project: Option<&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>>
Source§fn smart_recall(
&self,
project: Option<&str>,
hint: Option<&str>,
limit: usize,
) -> Result<Vec<ScoredNode>>
fn smart_recall( &self, project: Option<&str>, hint: Option<&str>, limit: usize, ) -> Result<Vec<ScoredNode>>
depth hops from start_id, returning related node
IDs (excluding the start).Source§fn append_edge(&self, edge: &GraphEdge) -> Result<()>
fn append_edge(&self, edge: &GraphEdge) -> Result<()>
Source§fn append_edges(&self, edges: &[GraphEdge]) -> Result<()>
fn append_edges(&self, edges: &[GraphEdge]) -> Result<()>
Source§fn edges_for_node_dir(
&self,
node_id: &str,
dir: EdgeDirection,
relation: Option<&str>,
) -> Result<Vec<GraphEdge>>
fn edges_for_node_dir( &self, node_id: &str, dir: EdgeDirection, relation: Option<&str>, ) -> Result<Vec<GraphEdge>>
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)>>
fn neighbors_weighted( &self, seed_ids: &[String], dir: EdgeDirection, relation: Option<&str>, ) -> Result<Vec<(String, f64)>>
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 edges_for_node(&self, node_id: &str) -> Result<Vec<GraphEdge>>
fn edges_for_node(&self, node_id: &str) -> Result<Vec<GraphEdge>>
Source§fn delete_edge(&self, id: &str) -> Result<bool>
fn delete_edge(&self, id: &str) -> Result<bool>
true if a row was removed.Source§fn remove_edges_for_node(&self, node_id: &str) -> Result<()>
fn remove_edges_for_node(&self, node_id: &str) -> Result<()>
Source§fn current_version(&self) -> Result<u32>
fn current_version(&self) -> Result<u32>
Source§fn migrate(&self) -> Result<u32>
fn migrate(&self) -> Result<u32>
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.Auto Trait Implementations§
impl !Freeze for SqliteGraph
impl RefUnwindSafe for SqliteGraph
impl Send for SqliteGraph
impl Sync for SqliteGraph
impl Unpin for SqliteGraph
impl UnsafeUnpin for SqliteGraph
impl UnwindSafe for SqliteGraph
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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> ⓘ
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> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.