Skip to main content

Storage

Struct Storage 

Source
pub struct Storage { /* private fields */ }
Expand description

SQLite-backed storage for Codemem memories, embeddings, and graph data.

Implementations§

Source§

impl Storage

Source

pub fn open(path: &Path) -> Result<Self, CodememError>

Open (or create) an Codemem database at the given path.

Source

pub fn open_in_memory() -> Result<Self, CodememError>

Open an in-memory database (for testing).

Source

pub fn content_hash(content: &str) -> String

Compute SHA-256 hash of content for deduplication.

Source

pub fn insert_memory(&self, memory: &MemoryNode) -> Result<(), CodememError>

Insert a new memory. Returns Err(Duplicate) if content hash already exists.

Source

pub fn get_memory(&self, id: &str) -> Result<Option<MemoryNode>, CodememError>

Get a memory by ID. Updates access_count and last_accessed_at.

Source

pub fn update_memory( &self, id: &str, content: &str, importance: Option<f64>, ) -> Result<(), CodememError>

Update a memory’s content and re-hash.

Source

pub fn delete_memory(&self, id: &str) -> Result<bool, CodememError>

Delete a memory by ID.

Source

pub fn list_memory_ids(&self) -> Result<Vec<String>, CodememError>

List all memory IDs.

Source

pub fn list_memory_ids_for_namespace( &self, namespace: &str, ) -> Result<Vec<String>, CodememError>

List memory IDs scoped to a specific namespace.

Source

pub fn list_namespaces(&self) -> Result<Vec<String>, CodememError>

List all distinct namespaces.

Source

pub fn memory_count(&self) -> Result<usize, CodememError>

Get memory count.

Source

pub fn store_embedding( &self, memory_id: &str, embedding: &[f32], ) -> Result<(), CodememError>

Store an embedding for a memory.

Source

pub fn get_embedding( &self, memory_id: &str, ) -> Result<Option<Vec<f32>>, CodememError>

Get an embedding by memory ID.

Source

pub fn insert_graph_node(&self, node: &GraphNode) -> Result<(), CodememError>

Insert a graph node.

Source

pub fn get_graph_node( &self, id: &str, ) -> Result<Option<GraphNode>, CodememError>

Get a graph node by ID.

Source

pub fn delete_graph_node(&self, id: &str) -> Result<bool, CodememError>

Delete a graph node by ID.

Source

pub fn all_graph_nodes(&self) -> Result<Vec<GraphNode>, CodememError>

Get all graph nodes.

Source

pub fn insert_graph_edge(&self, edge: &Edge) -> Result<(), CodememError>

Insert a graph edge.

Source

pub fn get_edges_for_node( &self, node_id: &str, ) -> Result<Vec<Edge>, CodememError>

Get all edges from or to a node.

Source

pub fn all_graph_edges(&self) -> Result<Vec<Edge>, CodememError>

Get all graph edges.

Source

pub fn delete_graph_edges_for_node( &self, node_id: &str, ) -> Result<usize, CodememError>

Delete all graph edges connected to a node (as src or dst).

Source

pub fn graph_edges_for_namespace( &self, namespace: &str, ) -> Result<Vec<Edge>, CodememError>

Get all graph edges where both src and dst nodes belong to the given namespace.

Source

pub fn delete_graph_edge(&self, id: &str) -> Result<bool, CodememError>

Delete a graph edge by ID.

Source

pub fn stats(&self) -> Result<StorageStats, CodememError>

Get database statistics.

Source

pub fn insert_consolidation_log( &self, cycle_type: &str, affected_count: usize, ) -> Result<(), CodememError>

Record a consolidation run.

Source

pub fn last_consolidation_runs( &self, ) -> Result<Vec<ConsolidationLogEntry>, CodememError>

Get the last consolidation run for each cycle type.

Source

pub fn connection(&self) -> &Connection

Get a reference to the underlying connection (for advanced use).

Source

pub fn get_repeated_searches( &self, min_count: usize, namespace: Option<&str>, ) -> Result<Vec<(String, usize, Vec<String>)>, CodememError>

Find repeated search patterns (Grep/Glob) by extracting the “pattern” field from memory metadata JSON. Returns (pattern, count, memory_ids) tuples where count >= min_count, ordered by count descending.

Source

pub fn get_file_hotspots( &self, min_count: usize, namespace: Option<&str>, ) -> Result<Vec<(String, usize, Vec<String>)>, CodememError>

Find file hotspots by extracting the “file_path” field from memory metadata. Returns (file_path, count, memory_ids) tuples where count >= min_count, ordered by count descending.

Source

pub fn get_tool_usage_stats( &self, namespace: Option<&str>, ) -> Result<HashMap<String, usize>, CodememError>

Get tool usage statistics from memory metadata. Returns a map of tool_name -> count, ordered by count descending.

Source

pub fn get_decision_chains( &self, min_count: usize, namespace: Option<&str>, ) -> Result<Vec<(String, usize, Vec<String>)>, CodememError>

Find decision chains: files with multiple Edit/Write memories over time. Returns (file_path, count, memory_ids) tuples ordered by count descending.

Source

pub fn ensure_session_column(&self) -> Result<(), CodememError>

Ensure session_id column exists on memories table.

Source

pub fn start_session( &self, id: &str, namespace: Option<&str>, ) -> Result<(), CodememError>

Start a new session. Inserts a row into the sessions table.

Source

pub fn end_session( &self, id: &str, summary: Option<&str>, ) -> Result<(), CodememError>

End a session by setting ended_at and optionally a summary.

Source

pub fn list_sessions( &self, namespace: Option<&str>, ) -> Result<Vec<Session>, CodememError>

List sessions, optionally filtered by namespace.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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.