pub struct RelevanceEngine { /* private fields */ }Expand description
Proactive relevance engine for memory surfacing
Implementations§
Source§impl RelevanceEngine
impl RelevanceEngine
Sourcepub fn set_active_ab_test(&self, test_id: Option<String>)
pub fn set_active_ab_test(&self, test_id: Option<String>)
Set active A/B test for this engine
When set, the engine will use weights from the A/B test based on user assignment.
Sourcepub fn get_active_ab_test(&self) -> Option<String>
pub fn get_active_ab_test(&self) -> Option<String>
Get active A/B test ID
Sourcepub fn get_weights(&self) -> LearnedWeights
pub fn get_weights(&self) -> LearnedWeights
Get current learned weights
Sourcepub fn set_weights(&self, weights: LearnedWeights)
pub fn set_weights(&self, weights: LearnedWeights)
Set learned weights (e.g., loaded from storage)
Sourcepub fn apply_feedback(
&self,
semantic_contributed: bool,
entity_contributed: bool,
tag_contributed: bool,
helpful: bool,
)
pub fn apply_feedback( &self, semantic_contributed: bool, entity_contributed: bool, tag_contributed: bool, helpful: bool, )
Apply feedback to update learned weights
Call this when user indicates a surfaced memory was helpful or not.
Sourcepub fn surface_relevant(
&self,
context: &str,
memory_system: &MemorySystem,
graph_memory: Option<&GraphMemory>,
config: &RelevanceConfig,
feedback_store: Option<&RwLock<FeedbackStore>>,
) -> Result<RelevanceResponse>
pub fn surface_relevant( &self, context: &str, memory_system: &MemorySystem, graph_memory: Option<&GraphMemory>, config: &RelevanceConfig, feedback_store: Option<&RwLock<FeedbackStore>>, ) -> Result<RelevanceResponse>
Surface relevant memories for the given context
This is the main entry point for proactive memory surfacing. Target latency: <30ms
Sourcepub fn surface_relevant_with_momentum(
&self,
context: &str,
memory_system: &MemorySystem,
graph_memory: Option<&GraphMemory>,
config: &RelevanceConfig,
momentum_lookup: &HashMap<Uuid, f32>,
) -> Result<RelevanceResponse>
pub fn surface_relevant_with_momentum( &self, context: &str, memory_system: &MemorySystem, graph_memory: Option<&GraphMemory>, config: &RelevanceConfig, momentum_lookup: &HashMap<Uuid, f32>, ) -> Result<RelevanceResponse>
Surface relevant memories with feedback momentum integration (FBK-5)
This variant incorporates momentum EMA from past feedback into scoring. Memories with positive momentum (consistently helpful) get boosted. Memories with negative momentum (consistently misleading) get penalized.
§Arguments
context: Current context/query textmemory_system: Memory storagegraph_memory: Optional graph memory for entity lookupconfig: Relevance configurationmomentum_lookup: Map of memory_id -> momentum EMA (-1.0 to 1.0)
Sourcepub fn surface_relevant_with_ab_test(
&self,
context: &str,
user_id: &str,
memory_system: &MemorySystem,
graph_memory: Option<&GraphMemory>,
config: &RelevanceConfig,
ab_manager: &ABTestManager,
) -> Result<(RelevanceResponse, Option<ABTestVariant>)>
pub fn surface_relevant_with_ab_test( &self, context: &str, user_id: &str, memory_system: &MemorySystem, graph_memory: Option<&GraphMemory>, config: &RelevanceConfig, ab_manager: &ABTestManager, ) -> Result<(RelevanceResponse, Option<ABTestVariant>)>
Surface relevant memories with A/B test integration
When an A/B test manager is provided, this method:
- Assigns the user to a variant (control or treatment)
- Uses weights from the assigned variant
- Records impressions for the test
Returns the variant used along with the response for tracking.
Sourcepub fn record_ab_click(
&self,
user_id: &str,
memory_id: Uuid,
ab_manager: &ABTestManager,
) -> Result<()>
pub fn record_ab_click( &self, user_id: &str, memory_id: Uuid, ab_manager: &ABTestManager, ) -> Result<()>
Record a click for A/B testing
Call this when a user interacts with a surfaced memory.
Sourcepub fn record_ab_feedback(
&self,
user_id: &str,
positive: bool,
ab_manager: &ABTestManager,
) -> Result<()>
pub fn record_ab_feedback( &self, user_id: &str, positive: bool, ab_manager: &ABTestManager, ) -> Result<()>
Record feedback for A/B testing
Call this when a user provides explicit feedback on a surfaced memory.
Sourcepub fn refresh_entity_index(&self, graph_memory: &GraphMemory) -> Result<()>
pub fn refresh_entity_index(&self, graph_memory: &GraphMemory) -> Result<()>
Refresh the entity index from GraphMemory
This builds an O(1) lookup table from entity names to memory IDs. Call this periodically or when the graph changes significantly.
Performance: O(E * M) where E = entities, M = avg memories per entity Typically completes in <10ms for 1000 entities.
Sourcepub fn get_memories_for_entity(
&self,
entity_name: &str,
graph_memory: Option<&GraphMemory>,
) -> Option<HashSet<Uuid>>
pub fn get_memories_for_entity( &self, entity_name: &str, graph_memory: Option<&GraphMemory>, ) -> Option<HashSet<Uuid>>
Get memory IDs for an entity name using the cached index
Returns None if entity not in index, empty set if entity known but has no memories. Falls back to direct GraphMemory lookup if index is stale or missing.
Sourcepub fn entity_index_needs_refresh(&self, max_age_hours: i64) -> bool
pub fn entity_index_needs_refresh(&self, max_age_hours: i64) -> bool
Check if entity index needs refresh (older than max_age_hours)
Sourcepub fn clear_entity_index(&self)
pub fn clear_entity_index(&self)
Clear the entity index (useful for testing or memory pressure)
Auto Trait Implementations§
impl Freeze for RelevanceEngine
impl !RefUnwindSafe for RelevanceEngine
impl Send for RelevanceEngine
impl Sync for RelevanceEngine
impl Unpin for RelevanceEngine
impl UnsafeUnpin for RelevanceEngine
impl !UnwindSafe for RelevanceEngine
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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