Persistence

Struct Persistence 

Source
pub struct Persistence { /* private fields */ }

Implementations§

Source§

impl Persistence

Source

pub fn new<P>(db_path: P) -> Result<Persistence, Error>
where P: AsRef<Path>,

Create or open the database at the provided path and run migrations.

Source

pub fn with_instance_id<P>( db_path: P, instance_id: String, ) -> Result<Persistence, Error>
where P: AsRef<Path>,

Create with a specific instance_id

Source

pub fn instance_id(&self) -> &str

Get the instance ID for this persistence instance

Source

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.

Source

pub fn new_default() -> Result<Persistence, Error>

Creates or opens the default database at ~/.spec-ai/agent_data.duckdb

Source

pub fn conn(&self) -> MutexGuard<'_, Connection>

Get access to the pooled database connection. Returns a MutexGuard that provides exclusive access to the connection.

Source

pub fn insert_message( &self, session_id: &str, role: MessageRole, content: &str, ) -> Result<i64, Error>

Source

pub fn list_messages( &self, session_id: &str, limit: i64, ) -> Result<Vec<Message>, Error>

Source

pub fn get_message(&self, message_id: i64) -> Result<Option<Message>, Error>

Source

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.

Source

pub fn insert_memory_vector( &self, session_id: &str, message_id: Option<i64>, embedding: &[f32], ) -> Result<i64, Error>

Source

pub fn recall_top_k( &self, session_id: &str, query_embedding: &[f32], k: usize, ) -> Result<Vec<(MemoryVector, f32)>, Error>

Source

pub fn list_sessions(&self) -> Result<Vec<String>, Error>

List known session IDs ordered by most recent activity

Source

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>

Source

pub fn policy_upsert(&self, key: &str, value: &Value) -> Result<(), Error>

Source

pub fn policy_get(&self, key: &str) -> Result<Option<PolicyEntry>, Error>

Source§

impl Persistence

Source

pub fn insert_graph_node( &self, session_id: &str, node_type: NodeType, label: &str, properties: &Value, embedding_id: Option<i64>, ) -> Result<i64, Error>

Source

pub fn get_graph_node(&self, node_id: i64) -> Result<Option<GraphNode>, Error>

Source

pub fn list_graph_nodes( &self, session_id: &str, node_type: Option<NodeType>, limit: Option<i64>, ) -> Result<Vec<GraphNode>, Error>

Source

pub fn count_graph_nodes(&self, session_id: &str) -> Result<i64, Error>

Source

pub fn update_graph_node( &self, node_id: i64, properties: &Value, ) -> Result<(), Error>

Source

pub fn delete_graph_node(&self, node_id: i64) -> Result<(), Error>

Source

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>

Source

pub fn get_graph_edge(&self, edge_id: i64) -> Result<Option<GraphEdge>, Error>

Source

pub fn list_graph_edges( &self, session_id: &str, source_id: Option<i64>, target_id: Option<i64>, ) -> Result<Vec<GraphEdge>, Error>

Source

pub fn count_graph_edges(&self, session_id: &str) -> Result<i64, Error>

Source

pub fn delete_graph_edge(&self, edge_id: i64) -> Result<(), Error>

Source

pub fn find_shortest_path( &self, session_id: &str, source_id: i64, target_id: i64, max_hops: Option<usize>, ) -> Result<Option<GraphPath>, Error>

Source

pub fn traverse_neighbors( &self, session_id: &str, node_id: i64, direction: TraversalDirection, depth: usize, ) -> Result<Vec<GraphNode>, Error>

Source

pub fn insert_transcription( &self, session_id: &str, chunk_id: i64, text: &str, timestamp: DateTime<Utc>, ) -> Result<i64, Error>

Source

pub fn update_transcription_embedding( &self, transcription_id: i64, embedding_id: i64, ) -> Result<(), Error>

Source

pub fn list_transcriptions( &self, session_id: &str, limit: Option<i64>, ) -> Result<Vec<(i64, i64, String, DateTime<Utc>)>, Error>

Source

pub fn get_full_transcription(&self, session_id: &str) -> Result<String, Error>

Source

pub fn delete_transcriptions(&self, session_id: &str) -> Result<(), Error>

Source

pub fn get_transcription_by_embedding( &self, embedding_id: i64, ) -> Result<Option<String>, Error>

Source

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.

Source

pub fn get_tokenized_file( &self, session_id: &str, path: &str, ) -> Result<Option<TokenizedFileRecord>, Error>

Source

pub fn list_tokenized_files( &self, session_id: &str, ) -> Result<Vec<TokenizedFileRecord>, Error>

Source

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

Source

pub fn mesh_message_exists(&self, message_id: &str) -> Result<bool, Error>

Check if a message with this ID already exists (for duplicate detection)

Source

pub fn mesh_message_update_status( &self, message_id: i64, status: &str, ) -> Result<(), Error>

Update message status (e.g., delivered, failed)

Source

pub fn mesh_message_get_pending( &self, target_instance: &str, ) -> Result<Vec<MeshMessageRecord>, Error>

Get pending messages for a target instance

Source

pub fn mesh_message_get_history( &self, instance_id: Option<&str>, limit: usize, ) -> Result<Vec<MeshMessageRecord>, Error>

Get message history for analytics

Source

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

Source

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

Source

pub fn graph_changelog_prune(&self, days_to_keep: i64) -> Result<usize, Error>

Prune old changelog entries (keep last N days)

Source

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

Source

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

Source

pub fn graph_set_sync_enabled( &self, session_id: &str, graph_name: &str, enabled: bool, ) -> Result<(), Error>

Enable or disable sync for a graph

Source

pub fn graph_get_sync_enabled( &self, session_id: &str, graph_name: &str, ) -> Result<bool, Error>

Check if sync is enabled for a graph

Source

pub fn graph_list(&self, session_id: &str) -> Result<Vec<String>, Error>

List all graphs for a session

Source

pub fn graph_get_node_with_sync( &self, node_id: i64, ) -> Result<Option<SyncedNodeRecord>, Error>

Get a node with its sync metadata

Source

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

Source

pub fn graph_get_edge_with_sync( &self, edge_id: i64, ) -> Result<Option<SyncedEdgeRecord>, Error>

Get an edge with its sync metadata

Source

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

Source

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

Source

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

Source

pub fn graph_mark_node_deleted( &self, node_id: i64, vector_clock: &str, deleted_by: &str, ) -> Result<(), Error>

Mark a node as deleted (tombstone pattern)

Source

pub fn graph_mark_edge_deleted( &self, edge_id: i64, vector_clock: &str, deleted_by: &str, ) -> Result<(), Error>

Mark an edge as deleted (tombstone pattern)

Trait Implementations§

Source§

impl Clone for Persistence

Source§

fn clone(&self) -> Persistence

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

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
Source§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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