pub struct Persistence { /* private fields */ }Implementations§
Source§impl Persistence
impl Persistence
Sourcepub fn new<P>(db_path: P) -> Result<Persistence, Error>
pub fn new<P>(db_path: P) -> Result<Persistence, Error>
Create or open the database at the provided path and run migrations.
Sourcepub fn with_instance_id<P>(
db_path: P,
instance_id: String,
) -> Result<Persistence, Error>
pub fn with_instance_id<P>( db_path: P, instance_id: String, ) -> Result<Persistence, Error>
Create with a specific instance_id
Sourcepub fn instance_id(&self) -> &str
pub fn instance_id(&self) -> &str
Get the instance ID for this persistence instance
Sourcepub fn checkpoint(&self) -> Result<(), Error>
pub fn checkpoint(&self) -> Result<(), Error>
Checkpoint the database to ensure all WAL data is written to the main database file. Call this before shutdown to ensure clean database state.
Sourcepub fn new_default() -> Result<Persistence, Error>
pub fn new_default() -> Result<Persistence, Error>
Creates or opens the default database at ~/.spec-ai/agent_data.duckdb
Sourcepub fn conn(&self) -> MutexGuard<'_, Connection>
pub fn conn(&self) -> MutexGuard<'_, Connection>
Get access to the pooled database connection. Returns a MutexGuard that provides exclusive access to the connection.
pub fn insert_message( &self, session_id: &str, role: MessageRole, content: &str, ) -> Result<i64, Error>
pub fn list_messages( &self, session_id: &str, limit: i64, ) -> Result<Vec<Message>, Error>
pub fn get_message(&self, message_id: i64) -> Result<Option<Message>, Error>
Sourcepub fn prune_messages(
&self,
session_id: &str,
keep_latest: i64,
) -> Result<u64, Error>
pub fn prune_messages( &self, session_id: &str, keep_latest: i64, ) -> Result<u64, Error>
Simple pruning by keeping only the most recent keep_latest messages.
pub fn insert_memory_vector( &self, session_id: &str, message_id: Option<i64>, embedding: &[f32], ) -> Result<i64, Error>
pub fn recall_top_k( &self, session_id: &str, query_embedding: &[f32], k: usize, ) -> Result<Vec<(MemoryVector, f32)>, Error>
Sourcepub fn list_sessions(&self) -> Result<Vec<String>, Error>
pub fn list_sessions(&self) -> Result<Vec<String>, Error>
List known session IDs ordered by most recent activity
pub fn log_tool( &self, session_id: &str, agent_name: &str, run_id: &str, tool_name: &str, arguments: &Value, result: &Value, success: bool, error: Option<&str>, ) -> Result<i64, Error>
pub fn policy_upsert(&self, key: &str, value: &Value) -> Result<(), Error>
pub fn policy_get(&self, key: &str) -> Result<Option<PolicyEntry>, Error>
Source§impl Persistence
impl Persistence
pub fn insert_graph_node( &self, session_id: &str, node_type: NodeType, label: &str, properties: &Value, embedding_id: Option<i64>, ) -> Result<i64, Error>
pub fn get_graph_node(&self, node_id: i64) -> Result<Option<GraphNode>, Error>
pub fn list_graph_nodes( &self, session_id: &str, node_type: Option<NodeType>, limit: Option<i64>, ) -> Result<Vec<GraphNode>, Error>
pub fn count_graph_nodes(&self, session_id: &str) -> Result<i64, Error>
pub fn update_graph_node( &self, node_id: i64, properties: &Value, ) -> Result<(), Error>
pub fn delete_graph_node(&self, node_id: i64) -> Result<(), Error>
pub fn insert_graph_edge( &self, session_id: &str, source_id: i64, target_id: i64, edge_type: EdgeType, predicate: Option<&str>, properties: Option<&Value>, weight: f32, ) -> Result<i64, Error>
pub fn get_graph_edge(&self, edge_id: i64) -> Result<Option<GraphEdge>, Error>
pub fn list_graph_edges( &self, session_id: &str, source_id: Option<i64>, target_id: Option<i64>, ) -> Result<Vec<GraphEdge>, Error>
pub fn count_graph_edges(&self, session_id: &str) -> Result<i64, Error>
pub fn delete_graph_edge(&self, edge_id: i64) -> Result<(), Error>
pub fn find_shortest_path( &self, session_id: &str, source_id: i64, target_id: i64, max_hops: Option<usize>, ) -> Result<Option<GraphPath>, Error>
pub fn traverse_neighbors( &self, session_id: &str, node_id: i64, direction: TraversalDirection, depth: usize, ) -> Result<Vec<GraphNode>, Error>
pub fn insert_transcription( &self, session_id: &str, chunk_id: i64, text: &str, timestamp: DateTime<Utc>, ) -> Result<i64, Error>
pub fn update_transcription_embedding( &self, transcription_id: i64, embedding_id: i64, ) -> Result<(), Error>
pub fn list_transcriptions( &self, session_id: &str, limit: Option<i64>, ) -> Result<Vec<(i64, i64, String, DateTime<Utc>)>, Error>
pub fn get_full_transcription(&self, session_id: &str) -> Result<String, Error>
pub fn delete_transcriptions(&self, session_id: &str) -> Result<(), Error>
pub fn get_transcription_by_embedding( &self, embedding_id: i64, ) -> Result<Option<String>, Error>
Sourcepub fn upsert_tokenized_file(
&self,
session_id: &str,
path: &str,
file_hash: &str,
raw_tokens: usize,
cleaned_tokens: usize,
bytes_captured: usize,
truncated: bool,
embedding_id: Option<i64>,
) -> Result<i64, Error>
pub fn upsert_tokenized_file( &self, session_id: &str, path: &str, file_hash: &str, raw_tokens: usize, cleaned_tokens: usize, bytes_captured: usize, truncated: bool, embedding_id: Option<i64>, ) -> Result<i64, Error>
Persist tokenization metadata for a file, replacing any existing entry for the path.
pub fn get_tokenized_file( &self, session_id: &str, path: &str, ) -> Result<Option<TokenizedFileRecord>, Error>
pub fn list_tokenized_files( &self, session_id: &str, ) -> Result<Vec<TokenizedFileRecord>, Error>
Sourcepub fn mesh_message_store(
&self,
message_id: &str,
source_instance: &str,
target_instance: Option<&str>,
message_type: &str,
payload: &Value,
status: &str,
) -> Result<i64, Error>
pub fn mesh_message_store( &self, message_id: &str, source_instance: &str, target_instance: Option<&str>, message_type: &str, payload: &Value, status: &str, ) -> Result<i64, Error>
Store a mesh message in the database
Sourcepub fn mesh_message_exists(&self, message_id: &str) -> Result<bool, Error>
pub fn mesh_message_exists(&self, message_id: &str) -> Result<bool, Error>
Check if a message with this ID already exists (for duplicate detection)
Sourcepub fn mesh_message_update_status(
&self,
message_id: i64,
status: &str,
) -> Result<(), Error>
pub fn mesh_message_update_status( &self, message_id: i64, status: &str, ) -> Result<(), Error>
Update message status (e.g., delivered, failed)
Sourcepub fn mesh_message_get_pending(
&self,
target_instance: &str,
) -> Result<Vec<MeshMessageRecord>, Error>
pub fn mesh_message_get_pending( &self, target_instance: &str, ) -> Result<Vec<MeshMessageRecord>, Error>
Get pending messages for a target instance
Sourcepub fn mesh_message_get_history(
&self,
instance_id: Option<&str>,
limit: usize,
) -> Result<Vec<MeshMessageRecord>, Error>
pub fn mesh_message_get_history( &self, instance_id: Option<&str>, limit: usize, ) -> Result<Vec<MeshMessageRecord>, Error>
Get message history for analytics
Sourcepub fn graph_changelog_append(
&self,
session_id: &str,
instance_id: &str,
entity_type: &str,
entity_id: i64,
operation: &str,
vector_clock: &str,
data: Option<&str>,
) -> Result<i64, Error>
pub fn graph_changelog_append( &self, session_id: &str, instance_id: &str, entity_type: &str, entity_id: i64, operation: &str, vector_clock: &str, data: Option<&str>, ) -> Result<i64, Error>
Append an entry to the graph changelog
Sourcepub fn graph_changelog_get_since(
&self,
session_id: &str,
since_timestamp: &str,
) -> Result<Vec<ChangelogEntry>, Error>
pub fn graph_changelog_get_since( &self, session_id: &str, since_timestamp: &str, ) -> Result<Vec<ChangelogEntry>, Error>
Get changelog entries since a given timestamp for a session
Sourcepub fn graph_changelog_prune(&self, days_to_keep: i64) -> Result<usize, Error>
pub fn graph_changelog_prune(&self, days_to_keep: i64) -> Result<usize, Error>
Prune old changelog entries (keep last N days)
Sourcepub fn graph_sync_state_get(
&self,
instance_id: &str,
session_id: &str,
graph_name: &str,
) -> Result<Option<String>, Error>
pub fn graph_sync_state_get( &self, instance_id: &str, session_id: &str, graph_name: &str, ) -> Result<Option<String>, Error>
Get the vector clock for an instance/session/graph combination
Sourcepub fn graph_sync_state_update(
&self,
instance_id: &str,
session_id: &str,
graph_name: &str,
vector_clock: &str,
) -> Result<(), Error>
pub fn graph_sync_state_update( &self, instance_id: &str, session_id: &str, graph_name: &str, vector_clock: &str, ) -> Result<(), Error>
Update the vector clock for an instance/session/graph combination
Sourcepub fn graph_set_sync_enabled(
&self,
session_id: &str,
graph_name: &str,
enabled: bool,
) -> Result<(), Error>
pub fn graph_set_sync_enabled( &self, session_id: &str, graph_name: &str, enabled: bool, ) -> Result<(), Error>
Enable or disable sync for a graph
Sourcepub fn graph_get_sync_enabled(
&self,
session_id: &str,
graph_name: &str,
) -> Result<bool, Error>
pub fn graph_get_sync_enabled( &self, session_id: &str, graph_name: &str, ) -> Result<bool, Error>
Check if sync is enabled for a graph
Sourcepub fn graph_list(&self, session_id: &str) -> Result<Vec<String>, Error>
pub fn graph_list(&self, session_id: &str) -> Result<Vec<String>, Error>
List all graphs for a session
Sourcepub fn graph_get_node_with_sync(
&self,
node_id: i64,
) -> Result<Option<SyncedNodeRecord>, Error>
pub fn graph_get_node_with_sync( &self, node_id: i64, ) -> Result<Option<SyncedNodeRecord>, Error>
Get a node with its sync metadata
Sourcepub fn graph_list_nodes_with_sync(
&self,
session_id: &str,
sync_enabled_only: bool,
include_deleted: bool,
) -> Result<Vec<SyncedNodeRecord>, Error>
pub fn graph_list_nodes_with_sync( &self, session_id: &str, sync_enabled_only: bool, include_deleted: bool, ) -> Result<Vec<SyncedNodeRecord>, Error>
Get all synced nodes for a session with optional filters
Sourcepub fn graph_get_edge_with_sync(
&self,
edge_id: i64,
) -> Result<Option<SyncedEdgeRecord>, Error>
pub fn graph_get_edge_with_sync( &self, edge_id: i64, ) -> Result<Option<SyncedEdgeRecord>, Error>
Get an edge with its sync metadata
Sourcepub fn graph_list_edges_with_sync(
&self,
session_id: &str,
sync_enabled_only: bool,
include_deleted: bool,
) -> Result<Vec<SyncedEdgeRecord>, Error>
pub fn graph_list_edges_with_sync( &self, session_id: &str, sync_enabled_only: bool, include_deleted: bool, ) -> Result<Vec<SyncedEdgeRecord>, Error>
Get all synced edges for a session with optional filters
Sourcepub fn graph_update_node_sync_metadata(
&self,
node_id: i64,
vector_clock: &str,
last_modified_by: &str,
sync_enabled: bool,
) -> Result<(), Error>
pub fn graph_update_node_sync_metadata( &self, node_id: i64, vector_clock: &str, last_modified_by: &str, sync_enabled: bool, ) -> Result<(), Error>
Update a node’s sync metadata
Sourcepub fn graph_update_edge_sync_metadata(
&self,
edge_id: i64,
vector_clock: &str,
last_modified_by: &str,
sync_enabled: bool,
) -> Result<(), Error>
pub fn graph_update_edge_sync_metadata( &self, edge_id: i64, vector_clock: &str, last_modified_by: &str, sync_enabled: bool, ) -> Result<(), Error>
Update an edge’s sync metadata
Trait Implementations§
Source§impl Clone for Persistence
impl Clone for Persistence
Source§fn clone(&self) -> Persistence
fn clone(&self) -> Persistence
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Persistence
impl RefUnwindSafe for Persistence
impl Send for Persistence
impl Sync for Persistence
impl Unpin for Persistence
impl UnwindSafe for Persistence
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more