pub struct SqliteGraphStore { /* private fields */ }Expand description
SQLite implementation of GraphStore
Integrates with existing openfang-memory schema by adding two tables:
ainl_graph_nodes: stores node payloadsainl_graph_edges: stores graph edges
Implementations§
Source§impl SqliteGraphStore
impl SqliteGraphStore
pub fn query<'a>(&'a self, agent_id: &str) -> GraphQuery<'a>
Source§impl SqliteGraphStore
impl SqliteGraphStore
Sourcepub fn ensure_schema(conn: &Connection) -> Result<(), Error>
pub fn ensure_schema(conn: &Connection) -> Result<(), Error>
Ensure the AINL graph schema exists in the database
Sourcepub fn from_connection(conn: Connection) -> Result<Self, String>
pub fn from_connection(conn: Connection) -> Result<Self, String>
Create from an existing connection (for integration with openfang-memory pool)
Sourcepub fn insert_graph_edge(
&self,
from_id: Uuid,
to_id: Uuid,
label: &str,
) -> Result<(), String>
pub fn insert_graph_edge( &self, from_id: Uuid, to_id: Uuid, label: &str, ) -> Result<(), String>
Insert a directed edge between two node IDs (separate from per-node edge payloads).
Sourcepub fn insert_graph_edge_checked(
&self,
from_id: Uuid,
to_id: Uuid,
label: &str,
) -> Result<(), String>
pub fn insert_graph_edge_checked( &self, from_id: Uuid, to_id: Uuid, label: &str, ) -> Result<(), String>
Like Self::insert_graph_edge, but verifies both endpoints exist first (clear errors for strict runtime wiring).
Sourcepub fn insert_graph_edge_with_meta(
&self,
from_id: Uuid,
to_id: Uuid,
label: &str,
weight: f32,
metadata: Option<&Value>,
) -> Result<(), String>
pub fn insert_graph_edge_with_meta( &self, from_id: Uuid, to_id: Uuid, label: &str, weight: f32, metadata: Option<&Value>, ) -> Result<(), String>
Same as Self::insert_graph_edge, with optional edge weight and JSON metadata.
Sourcepub fn query_nodes_by_type_since(
&self,
node_type: &str,
since_timestamp: i64,
limit: usize,
) -> Result<Vec<AinlMemoryNode>, String>
pub fn query_nodes_by_type_since( &self, node_type: &str, since_timestamp: i64, limit: usize, ) -> Result<Vec<AinlMemoryNode>, String>
Nodes of a given node_type with timestamp >= since_timestamp, most recent first.
Sourcepub fn read_runtime_state(
&self,
agent_id: &str,
) -> Result<Option<RuntimeStateNode>, String>
pub fn read_runtime_state( &self, agent_id: &str, ) -> Result<Option<RuntimeStateNode>, String>
Read the most recent persisted RuntimeStateNode for agent_id, if any.
Rows are stored with node_type = 'runtime_state' and JSON $.node_type.runtime_state.agent_id matching the agent.
Sourcepub fn write_runtime_state(
&self,
state: &RuntimeStateNode,
) -> Result<(), String>
pub fn write_runtime_state( &self, state: &RuntimeStateNode, ) -> Result<(), String>
Upsert one RuntimeStateNode row per agent (stable id via Uuid::new_v5).
Sourcepub fn write_node_with_edges(
&mut self,
node: &AinlMemoryNode,
) -> Result<(), String>
pub fn write_node_with_edges( &mut self, node: &AinlMemoryNode, ) -> Result<(), String>
Write a node and its embedded edges in one transaction; fails if any edge target is missing.
Sourcepub fn validate_graph(
&self,
agent_id: &str,
) -> Result<GraphValidationReport, String>
pub fn validate_graph( &self, agent_id: &str, ) -> Result<GraphValidationReport, String>
Validate structural integrity for one agent’s induced subgraph.
Sourcepub fn validate_graph_checked(
&self,
agent_id: &str,
) -> Result<GraphValidationReport, GraphValidationError>
pub fn validate_graph_checked( &self, agent_id: &str, ) -> Result<GraphValidationReport, GraphValidationError>
Typed validation variant for callers that need structured error handling.
Sourcepub fn agent_subgraph_edges(
&self,
agent_id: &str,
) -> Result<Vec<SnapshotEdge>, String>
pub fn agent_subgraph_edges( &self, agent_id: &str, ) -> Result<Vec<SnapshotEdge>, String>
Directed edges where both endpoints are nodes owned by agent_id (aligned with Self::export_graph edge set).
Sourcepub fn export_graph(&self, agent_id: &str) -> Result<AgentGraphSnapshot, String>
pub fn export_graph(&self, agent_id: &str) -> Result<AgentGraphSnapshot, String>
Export all nodes and interconnecting edges for agent_id.
Sourcepub fn import_graph(
&mut self,
snapshot: &AgentGraphSnapshot,
allow_dangling_edges: bool,
) -> Result<(), String>
pub fn import_graph( &mut self, snapshot: &AgentGraphSnapshot, allow_dangling_edges: bool, ) -> Result<(), String>
Import a snapshot in one transaction (INSERT OR IGNORE per row).
allow_dangling_edges == false(default / production):PRAGMA foreign_keysstays enabled; every edge must reference existing node rows after inserts (same invariants asSelf::write_node_with_edges).allow_dangling_edges == true(repair / forensic): FK checks are disabled only for this import so partially invalid snapshots can be loaded; runSelf::validate_graphafterward and repair before returning to normal writes.
Sourcepub fn import_graph_checked(
&mut self,
snapshot: &AgentGraphSnapshot,
allow_dangling_edges: bool,
) -> Result<(), SnapshotImportError>
pub fn import_graph_checked( &mut self, snapshot: &AgentGraphSnapshot, allow_dangling_edges: bool, ) -> Result<(), SnapshotImportError>
Typed import variant for callers that want structured error handling.
Sourcepub fn insert_trajectory_detail(
&self,
row: &TrajectoryDetailRecord,
) -> Result<(), String>
pub fn insert_trajectory_detail( &self, row: &TrajectoryDetailRecord, ) -> Result<(), String>
Large-step trajectory row (sibling table); episode row must exist first.
Sourcepub fn list_trajectories_for_agent(
&self,
agent_id: &str,
limit: usize,
since_timestamp: Option<i64>,
) -> Result<Vec<TrajectoryDetailRecord>, String>
pub fn list_trajectories_for_agent( &self, agent_id: &str, limit: usize, since_timestamp: Option<i64>, ) -> Result<Vec<TrajectoryDetailRecord>, String>
Recent trajectory detail rows for an agent (newest first).
Sourcepub fn count_trajectory_details_before(
&self,
agent_id: &str,
before_unix: i64,
) -> Result<usize, String>
pub fn count_trajectory_details_before( &self, agent_id: &str, before_unix: i64, ) -> Result<usize, String>
Count ainl_trajectories rows for agent_id with recorded_at strictly before before_unix (seconds).
Sourcepub fn delete_trajectory_details_before(
&self,
agent_id: &str,
before_unix: i64,
) -> Result<usize, String>
pub fn delete_trajectory_details_before( &self, agent_id: &str, before_unix: i64, ) -> Result<usize, String>
Delete ainl_trajectories detail rows for agent_id with recorded_at strictly before
before_unix (seconds). Returns the number of rows removed.
This does not delete Trajectory nodes from ainl_graph_nodes or any edges; use graph
export / repair paths if you need a fully consistent graph after bulk pruning.
Sourcepub fn search_failures_fts_for_agent(
&self,
agent_id: &str,
query: &str,
limit: usize,
) -> Result<Vec<AinlMemoryNode>, String>
pub fn search_failures_fts_for_agent( &self, agent_id: &str, query: &str, limit: usize, ) -> Result<Vec<AinlMemoryNode>, String>
Full-text search over persisted failure nodes for one agent (node_type = failure).
Returns matching AinlMemoryNode rows (newest first). Invalid FTS syntax yields an empty list.
Sourcepub fn search_all_nodes_fts_for_agent(
&self,
agent_id: &str,
query: &str,
project_id: Option<&str>,
limit: usize,
) -> Result<Vec<AinlMemoryNode>, String>
pub fn search_all_nodes_fts_for_agent( &self, agent_id: &str, query: &str, project_id: Option<&str>, limit: usize, ) -> Result<Vec<AinlMemoryNode>, String>
Full-text search over all graph node JSON payloads (see ainl_nodes_fts), scoped by agent.
project_id: when Some (non-empty), return matches whose stored project is empty/NULL
or equal to that id (so legacy unscoped rows remain visible in a project workspace).
When None, do not filter by project.
Trait Implementations§
Source§impl GraphStore for SqliteGraphStore
impl GraphStore for SqliteGraphStore
Source§fn write_node(&self, node: &AinlMemoryNode) -> Result<(), String>
fn write_node(&self, node: &AinlMemoryNode) -> Result<(), String>
Persists the full node JSON under id via INSERT OR REPLACE (upsert).
Backfill pattern: read_node → patch fields (e.g. episodic signals) → write_node, preserving loaded edges.