pub trait StorageBackend: Send + Sync {
Show 22 methods
// Required methods
fn create_memory(
&self,
input: CreateMemoryInput,
) -> Result<Memory, EngramError>;
fn get_memory(&self, id: MemoryId) -> Result<Option<Memory>, EngramError>;
fn update_memory(
&self,
id: MemoryId,
input: UpdateMemoryInput,
) -> Result<Memory, EngramError>;
fn delete_memory(&self, id: MemoryId) -> Result<(), EngramError>;
fn create_memories_batch(
&self,
inputs: Vec<CreateMemoryInput>,
) -> Result<BatchCreateResult, EngramError>;
fn delete_memories_batch(
&self,
ids: Vec<MemoryId>,
) -> Result<BatchDeleteResult, EngramError>;
fn list_memories(
&self,
options: ListOptions,
) -> Result<Vec<Memory>, EngramError>;
fn count_memories(&self, options: ListOptions) -> Result<i64, EngramError>;
fn search_memories(
&self,
query: &str,
options: SearchOptions,
) -> Result<Vec<SearchResult>, EngramError>;
fn create_crossref(
&self,
from_id: MemoryId,
to_id: MemoryId,
edge_type: EdgeType,
score: f32,
) -> Result<CrossReference, EngramError>;
fn get_crossrefs(
&self,
memory_id: MemoryId,
) -> Result<Vec<CrossReference>, EngramError>;
fn delete_crossref(
&self,
from_id: MemoryId,
to_id: MemoryId,
) -> Result<(), EngramError>;
fn list_tags(&self) -> Result<Vec<(String, i64)>, EngramError>;
fn get_memories_by_tag(
&self,
tag: &str,
limit: Option<usize>,
) -> Result<Vec<Memory>, EngramError>;
fn list_workspaces(&self) -> Result<Vec<(String, i64)>, EngramError>;
fn get_workspace_stats(
&self,
workspace: &str,
) -> Result<HashMap<String, i64>, EngramError>;
fn move_to_workspace(
&self,
ids: Vec<MemoryId>,
workspace: &str,
) -> Result<usize, EngramError>;
fn get_stats(&self) -> Result<StorageStats, EngramError>;
fn health_check(&self) -> Result<HealthStatus, EngramError>;
fn optimize(&self) -> Result<(), EngramError>;
fn backend_name(&self) -> &'static str;
fn schema_version(&self) -> Result<i32, EngramError>;
}Expand description
Core storage backend trait for Engram (ENG-14)
This trait defines the interface for all storage operations, allowing for multiple backend implementations (SQLite, Turso, Meilisearch).
Required Methods§
Sourcefn create_memory(&self, input: CreateMemoryInput) -> Result<Memory, EngramError>
fn create_memory(&self, input: CreateMemoryInput) -> Result<Memory, EngramError>
Create a new memory
Sourcefn get_memory(&self, id: MemoryId) -> Result<Option<Memory>, EngramError>
fn get_memory(&self, id: MemoryId) -> Result<Option<Memory>, EngramError>
Get a memory by ID
Sourcefn update_memory(
&self,
id: MemoryId,
input: UpdateMemoryInput,
) -> Result<Memory, EngramError>
fn update_memory( &self, id: MemoryId, input: UpdateMemoryInput, ) -> Result<Memory, EngramError>
Update a memory
Sourcefn delete_memory(&self, id: MemoryId) -> Result<(), EngramError>
fn delete_memory(&self, id: MemoryId) -> Result<(), EngramError>
Delete a memory (soft delete)
Sourcefn create_memories_batch(
&self,
inputs: Vec<CreateMemoryInput>,
) -> Result<BatchCreateResult, EngramError>
fn create_memories_batch( &self, inputs: Vec<CreateMemoryInput>, ) -> Result<BatchCreateResult, EngramError>
Create multiple memories in a single transaction
Sourcefn delete_memories_batch(
&self,
ids: Vec<MemoryId>,
) -> Result<BatchDeleteResult, EngramError>
fn delete_memories_batch( &self, ids: Vec<MemoryId>, ) -> Result<BatchDeleteResult, EngramError>
Delete multiple memories in a single transaction
Sourcefn list_memories(
&self,
options: ListOptions,
) -> Result<Vec<Memory>, EngramError>
fn list_memories( &self, options: ListOptions, ) -> Result<Vec<Memory>, EngramError>
List memories with filters
Sourcefn count_memories(&self, options: ListOptions) -> Result<i64, EngramError>
fn count_memories(&self, options: ListOptions) -> Result<i64, EngramError>
Count memories matching filters
Sourcefn search_memories(
&self,
query: &str,
options: SearchOptions,
) -> Result<Vec<SearchResult>, EngramError>
fn search_memories( &self, query: &str, options: SearchOptions, ) -> Result<Vec<SearchResult>, EngramError>
Search memories using hybrid search
Sourcefn create_crossref(
&self,
from_id: MemoryId,
to_id: MemoryId,
edge_type: EdgeType,
score: f32,
) -> Result<CrossReference, EngramError>
fn create_crossref( &self, from_id: MemoryId, to_id: MemoryId, edge_type: EdgeType, score: f32, ) -> Result<CrossReference, EngramError>
Create a cross-reference between memories
Sourcefn get_crossrefs(
&self,
memory_id: MemoryId,
) -> Result<Vec<CrossReference>, EngramError>
fn get_crossrefs( &self, memory_id: MemoryId, ) -> Result<Vec<CrossReference>, EngramError>
Get cross-references for a memory
Sourcefn delete_crossref(
&self,
from_id: MemoryId,
to_id: MemoryId,
) -> Result<(), EngramError>
fn delete_crossref( &self, from_id: MemoryId, to_id: MemoryId, ) -> Result<(), EngramError>
Delete a cross-reference
List all tags with usage counts
Sourcefn get_memories_by_tag(
&self,
tag: &str,
limit: Option<usize>,
) -> Result<Vec<Memory>, EngramError>
fn get_memories_by_tag( &self, tag: &str, limit: Option<usize>, ) -> Result<Vec<Memory>, EngramError>
Get memories with a specific tag
Sourcefn list_workspaces(&self) -> Result<Vec<(String, i64)>, EngramError>
fn list_workspaces(&self) -> Result<Vec<(String, i64)>, EngramError>
List all workspaces with memory counts
Sourcefn get_workspace_stats(
&self,
workspace: &str,
) -> Result<HashMap<String, i64>, EngramError>
fn get_workspace_stats( &self, workspace: &str, ) -> Result<HashMap<String, i64>, EngramError>
Get detailed statistics for a workspace
Sourcefn move_to_workspace(
&self,
ids: Vec<MemoryId>,
workspace: &str,
) -> Result<usize, EngramError>
fn move_to_workspace( &self, ids: Vec<MemoryId>, workspace: &str, ) -> Result<usize, EngramError>
Move memories to a different workspace
Sourcefn get_stats(&self) -> Result<StorageStats, EngramError>
fn get_stats(&self) -> Result<StorageStats, EngramError>
Get storage statistics
Sourcefn health_check(&self) -> Result<HealthStatus, EngramError>
fn health_check(&self) -> Result<HealthStatus, EngramError>
Check storage health
Sourcefn optimize(&self) -> Result<(), EngramError>
fn optimize(&self) -> Result<(), EngramError>
Run optimization (e.g., VACUUM)
Sourcefn backend_name(&self) -> &'static str
fn backend_name(&self) -> &'static str
Get backend name identifier
Sourcefn schema_version(&self) -> Result<i32, EngramError>
fn schema_version(&self) -> Result<i32, EngramError>
Get current schema version