pub struct MemoryRepository { /* private fields */ }
Implementations§
Source§impl MemoryRepository
impl MemoryRepository
pub fn new(pool: PgPool) -> Self
pub fn with_trigger_engine( pool: PgPool, trigger_engine: Arc<EventTriggeredScoringEngine>, ) -> Self
pub fn pool(&self) -> &PgPool
pub async fn create_memory( &self, request: CreateMemoryRequest, ) -> Result<Memory>
pub async fn create_memory_with_user_context( &self, request: CreateMemoryRequest, user_id: Option<&str>, ) -> Result<Memory>
pub async fn get_memory(&self, id: Uuid) -> Result<Memory>
pub async fn update_memory( &self, id: Uuid, request: UpdateMemoryRequest, ) -> Result<Memory>
pub async fn delete_memory(&self, id: Uuid) -> Result<()>
Sourcepub async fn search_memories_enhanced(
&self,
request: MemoryAwareSearchRequest,
) -> Result<MemoryAwareSearchResponse>
pub async fn search_memories_enhanced( &self, request: MemoryAwareSearchRequest, ) -> Result<MemoryAwareSearchResponse>
Enhanced search method with memory-aware features for Story 9
pub async fn search_memories( &self, request: SearchRequest, ) -> Result<SearchResponse>
pub async fn search_memories_simple( &self, request: SearchRequest, ) -> Result<Vec<SearchResult>>
pub async fn get_memories_by_tier( &self, tier: MemoryTier, limit: Option<i64>, ) -> Result<Vec<Memory>>
pub async fn migrate_memory( &self, id: Uuid, to_tier: MemoryTier, reason: Option<String>, ) -> Result<Memory>
pub async fn get_expired_memories(&self) -> Result<Vec<Memory>>
pub async fn cleanup_expired_memories(&self) -> Result<u64>
pub async fn get_migration_candidates( &self, tier: MemoryTier, limit: i64, ) -> Result<Vec<Memory>>
pub async fn get_statistics(&self) -> Result<MemoryStatistics>
Sourcepub async fn get_consolidation_analytics(
&self,
) -> Result<Vec<ConsolidationAnalytics>>
pub async fn get_consolidation_analytics( &self, ) -> Result<Vec<ConsolidationAnalytics>>
Get consolidation analytics for all tiers
Sourcepub async fn get_consolidation_events(
&self,
) -> Result<Vec<ConsolidationEventSummary>>
pub async fn get_consolidation_events( &self, ) -> Result<Vec<ConsolidationEventSummary>>
Get consolidation event summary for the last week
Sourcepub async fn find_migration_candidates(
&self,
tier: MemoryTier,
limit: i32,
) -> Result<Vec<Memory>>
pub async fn find_migration_candidates( &self, tier: MemoryTier, limit: i32, ) -> Result<Vec<Memory>>
Find memories ready for tier migration based on recall probability
Sourcepub async fn update_consolidation(
&self,
memory_id: Uuid,
consolidation_strength: f64,
decay_rate: f64,
recall_probability: Option<f64>,
) -> Result<()>
pub async fn update_consolidation( &self, memory_id: Uuid, consolidation_strength: f64, decay_rate: f64, recall_probability: Option<f64>, ) -> Result<()>
Update memory consolidation parameters
Sourcepub async fn log_consolidation_event(
&self,
memory_id: Uuid,
event_type: &str,
previous_strength: f64,
new_strength: f64,
previous_probability: Option<f64>,
new_probability: Option<f64>,
recall_interval: Option<PgInterval>,
context: Value,
) -> Result<()>
pub async fn log_consolidation_event( &self, memory_id: Uuid, event_type: &str, previous_strength: f64, new_strength: f64, previous_probability: Option<f64>, new_probability: Option<f64>, recall_interval: Option<PgInterval>, context: Value, ) -> Result<()>
Log a consolidation event
Sourcepub async fn freeze_memory(
&self,
memory_id: Uuid,
reason: Option<String>,
) -> Result<FreezeMemoryResponse>
pub async fn freeze_memory( &self, memory_id: Uuid, reason: Option<String>, ) -> Result<FreezeMemoryResponse>
Freeze a memory by moving it to compressed storage using zstd compression
Sourcepub async fn unfreeze_memory(
&self,
frozen_id: Uuid,
target_tier: Option<MemoryTier>,
) -> Result<UnfreezeMemoryResponse>
pub async fn unfreeze_memory( &self, frozen_id: Uuid, target_tier: Option<MemoryTier>, ) -> Result<UnfreezeMemoryResponse>
Unfreeze a memory and restore it to active status with zstd decompression
Sourcepub async fn get_frozen_memories(
&self,
limit: i32,
offset: i64,
) -> Result<Vec<FrozenMemory>>
pub async fn get_frozen_memories( &self, limit: i32, offset: i64, ) -> Result<Vec<FrozenMemory>>
Get all frozen memories with pagination
Sourcepub async fn search_frozen_memories(
&self,
query: &str,
limit: i32,
) -> Result<Vec<FrozenMemory>>
pub async fn search_frozen_memories( &self, query: &str, limit: i32, ) -> Result<Vec<FrozenMemory>>
Search frozen memories by content or metadata
Sourcepub async fn get_tier_statistics(&self) -> Result<Vec<MemoryTierStatistics>>
pub async fn get_tier_statistics(&self) -> Result<Vec<MemoryTierStatistics>>
Get tier statistics for monitoring
Sourcepub async fn update_tier_statistics(&self) -> Result<()>
pub async fn update_tier_statistics(&self) -> Result<()>
Update tier statistics (typically called by a background job)
Sourcepub async fn search_by_consolidation(
&self,
request: ConsolidationSearchRequest,
) -> Result<Vec<Memory>>
pub async fn search_by_consolidation( &self, request: ConsolidationSearchRequest, ) -> Result<Vec<Memory>>
Search memories with consolidation criteria
Sourcepub async fn update_memory_scores(
&self,
memory_id: Uuid,
recency_score: f64,
relevance_score: f64,
) -> Result<()>
pub async fn update_memory_scores( &self, memory_id: Uuid, recency_score: f64, relevance_score: f64, ) -> Result<()>
Update three-component scores for specific memory
Sourcepub async fn batch_update_three_component_scores(&self) -> Result<i64>
pub async fn batch_update_three_component_scores(&self) -> Result<i64>
Batch update three-component scores for all active memories
Sourcepub async fn get_memories_by_combined_score(
&self,
tier: Option<MemoryTier>,
limit: Option<i32>,
recency_weight: Option<f64>,
importance_weight: Option<f64>,
relevance_weight: Option<f64>,
) -> Result<Vec<Memory>>
pub async fn get_memories_by_combined_score( &self, tier: Option<MemoryTier>, limit: Option<i32>, recency_weight: Option<f64>, importance_weight: Option<f64>, relevance_weight: Option<f64>, ) -> Result<Vec<Memory>>
Get memories ranked by three-component combined score using generated column
Sourcepub async fn get_memories_for_consolidation(
&self,
tier: Option<MemoryTier>,
batch_size: usize,
min_hours_since_last_processing: f64,
) -> Result<Vec<Memory>>
pub async fn get_memories_for_consolidation( &self, tier: Option<MemoryTier>, batch_size: usize, min_hours_since_last_processing: f64, ) -> Result<Vec<Memory>>
Get memories for consolidation processing with batch optimization
Sourcepub async fn batch_update_consolidation(
&self,
updates: &[(Uuid, f64, f64)],
) -> Result<usize>
pub async fn batch_update_consolidation( &self, updates: &[(Uuid, f64, f64)], ) -> Result<usize>
Batch update consolidation values for multiple memories
Sourcepub async fn batch_migrate_memories(
&self,
migrations: &[(Uuid, MemoryTier)],
) -> Result<usize>
pub async fn batch_migrate_memories( &self, migrations: &[(Uuid, MemoryTier)], ) -> Result<usize>
Batch migrate memories to new tiers
Sourcepub async fn get_simple_consolidation_candidates(
&self,
tier: Option<MemoryTier>,
threshold: f64,
limit: usize,
) -> Result<Vec<Memory>>
pub async fn get_simple_consolidation_candidates( &self, tier: Option<MemoryTier>, threshold: f64, limit: usize, ) -> Result<Vec<Memory>>
Get migration candidates using simple consolidation formula
Sourcepub async fn log_simple_consolidation_event(
&self,
memory_id: Uuid,
previous_strength: f64,
new_strength: f64,
previous_probability: Option<f64>,
new_probability: f64,
processing_time_ms: u64,
) -> Result<()>
pub async fn log_simple_consolidation_event( &self, memory_id: Uuid, previous_strength: f64, new_strength: f64, previous_probability: Option<f64>, new_probability: f64, processing_time_ms: u64, ) -> Result<()>
Log simple consolidation event with performance metrics
Sourcepub async fn get_simple_consolidation_stats(
&self,
) -> Result<SimpleConsolidationStats>
pub async fn get_simple_consolidation_stats( &self, ) -> Result<SimpleConsolidationStats>
Get simple consolidation statistics
Sourcepub async fn get_trigger_metrics(&self) -> Option<TriggerMetrics>
pub async fn get_trigger_metrics(&self) -> Option<TriggerMetrics>
Get trigger metrics if trigger engine is available
Sourcepub async fn reset_trigger_metrics(&self) -> Result<()>
pub async fn reset_trigger_metrics(&self) -> Result<()>
Reset trigger metrics if trigger engine is available
Sourcepub async fn add_user_trigger_customization(
&self,
user_id: String,
customizations: HashMap<TriggerEvent, TriggerPattern>,
) -> Result<()>
pub async fn add_user_trigger_customization( &self, user_id: String, customizations: HashMap<TriggerEvent, TriggerPattern>, ) -> Result<()>
Add user-specific trigger customization
Sourcepub fn has_trigger_engine(&self) -> bool
pub fn has_trigger_engine(&self) -> bool
Check if trigger engine is enabled
Sourcepub async fn batch_freeze_by_recall_probability(
&self,
max_batch_size: Option<usize>,
) -> Result<BatchFreezeResult>
pub async fn batch_freeze_by_recall_probability( &self, max_batch_size: Option<usize>, ) -> Result<BatchFreezeResult>
Batch freeze memories that meet migration criteria (P(recall) < 0.2)
Sourcepub async fn batch_unfreeze_memories(
&self,
frozen_ids: Vec<Uuid>,
target_tier: Option<MemoryTier>,
) -> Result<BatchUnfreezeResult>
pub async fn batch_unfreeze_memories( &self, frozen_ids: Vec<Uuid>, target_tier: Option<MemoryTier>, ) -> Result<BatchUnfreezeResult>
Batch unfreeze memories
Auto Trait Implementations§
impl Freeze for MemoryRepository
impl !RefUnwindSafe for MemoryRepository
impl Send for MemoryRepository
impl Sync for MemoryRepository
impl Unpin for MemoryRepository
impl !UnwindSafe for MemoryRepository
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> 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