pub struct TransitionMap { /* private fields */ }Expand description
Tracks topic transitions as a Markov chain. Maps from_topic -> (to_topic -> frequency_count).
Also maintains a learned topic cache that maps raw user messages to canonical topic labels, so repeated patterns skip the LLM.
Implementations§
Source§impl TransitionMap
impl TransitionMap
Sourcepub fn record(&mut self, from: &str, to: &str)
pub fn record(&mut self, from: &str, to: &str)
Record a transition, applying the topic cache if available. If a canonical label exists for a raw topic, uses that instead.
pub fn reinforce(&mut self, from: &str, to: &str)
pub fn decay(&mut self, from: &str, to: &str)
Sourcepub fn predict_from(&self, topic: &str, limit: usize) -> Vec<(String, u32)>
pub fn predict_from(&self, topic: &str, limit: usize) -> Vec<(String, u32)>
Returns the top N predicted topics from a given topic, sorted by frequency descending.
Sourcepub fn learn_canonical(&mut self, raw: &str, canonical: &str)
pub fn learn_canonical(&mut self, raw: &str, canonical: &str)
Store a learned mapping from a raw topic to its canonical label.
Sourcepub fn get_canonical(&self, raw: &str) -> Option<&String>
pub fn get_canonical(&self, raw: &str) -> Option<&String>
Look up a cached canonical label for a raw topic.
Sourcepub fn known_topics(&self) -> Vec<String>
pub fn known_topics(&self) -> Vec<String>
Returns the list of known canonical topic labels (deduped).
pub fn topic_cache_size(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn total_transitions(&self) -> usize
Trait Implementations§
Source§impl Clone for TransitionMap
impl Clone for TransitionMap
Source§fn clone(&self) -> TransitionMap
fn clone(&self) -> TransitionMap
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TransitionMap
impl Debug for TransitionMap
Source§impl Default for TransitionMap
impl Default for TransitionMap
Source§fn default() -> TransitionMap
fn default() -> TransitionMap
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for TransitionMap
impl<'de> Deserialize<'de> for TransitionMap
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for TransitionMap
impl RefUnwindSafe for TransitionMap
impl Send for TransitionMap
impl Sync for TransitionMap
impl Unpin for TransitionMap
impl UnsafeUnpin for TransitionMap
impl UnwindSafe for TransitionMap
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
Mutably borrows from an owned value. Read more