Skip to main content

TransitionMap

Struct TransitionMap 

Source
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

Source

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.

Source

pub fn reinforce(&mut self, from: &str, to: &str)

Source

pub fn decay(&mut self, from: &str, to: &str)

Source

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.

Source

pub fn learn_canonical(&mut self, raw: &str, canonical: &str)

Store a learned mapping from a raw topic to its canonical label.

Source

pub fn get_canonical(&self, raw: &str) -> Option<&String>

Look up a cached canonical label for a raw topic.

Source

pub fn known_topics(&self) -> Vec<String>

Returns the list of known canonical topic labels (deduped).

Source

pub fn topic_cache_size(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn total_transitions(&self) -> usize

Source

pub fn save(&self, path: &Path, min_count: u32) -> Result<()>

Save the transition map to a JSON file. Prunes transitions with count below min_count to keep the file from growing unbounded. Uses atomic write (temp file + rename) to avoid corruption.

Source

pub fn load(&mut self, path: &Path) -> Result<()>

Load a transition map from a JSON file, merging counts into the current map so that patterns accumulate across sessions. Supports both v1 (no topic_cache) and v2 (with topic_cache) formats.

Trait Implementations§

Source§

impl Clone for TransitionMap

Source§

fn clone(&self) -> TransitionMap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TransitionMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TransitionMap

Source§

fn default() -> TransitionMap

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for TransitionMap

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TransitionMap

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,