pub struct CoactivationTracker {
pub config: CoactivationConfig,
}Expand description
Stateless tracker — borrows a rusqlite::Connection for each operation.
All state lives in the coactivation_edges database table.
Fields§
§config: CoactivationConfigConfiguration controlling Hebbian dynamics.
Implementations§
Source§impl CoactivationTracker
impl CoactivationTracker
Sourcepub fn with_config(config: CoactivationConfig) -> Self
pub fn with_config(config: CoactivationConfig) -> Self
Create a tracker with custom configuration.
Sourcepub fn record_coactivation(
&self,
conn: &Connection,
memory_ids: &[i64],
_session_id: &str,
) -> Result<usize>
pub fn record_coactivation( &self, conn: &Connection, memory_ids: &[i64], _session_id: &str, ) -> Result<usize>
Record that a set of memories were retrieved together in one session.
For every unordered pair (a, b) in memory_ids (where a < b) the
function upserts a coactivation_edges row, applying the Hebbian
update:
strength ← min(1.0, strength + lr × (1 − strength))Returns the number of edges updated (i.e. n × (n−1) / 2 where n is
the number of unique IDs, assuming no self-loops).
session_id is informational only — it is not stored but could be used
by callers for audit logging.
Sourcepub fn strengthen(
&self,
conn: &Connection,
from_id: i64,
to_id: i64,
) -> Result<f64>
pub fn strengthen( &self, conn: &Connection, from_id: i64, to_id: i64, ) -> Result<f64>
Apply a single Hebbian update to the edge from_id → to_id.
Creates the edge if it does not exist yet. Returns the new strength.
Sourcepub fn weaken_unused(
&self,
conn: &Connection,
decay_rate: f64,
min_age_days: u32,
) -> Result<usize>
pub fn weaken_unused( &self, conn: &Connection, decay_rate: f64, min_age_days: u32, ) -> Result<usize>
Decay edges that have not been co-activated in at least min_age_days.
Each qualifying edge has its strength multiplied by (1 − decay_rate).
Edges that fall below CoactivationConfig::min_strength are deleted.
Returns the number of edges affected (updated or deleted).
Sourcepub fn get_coactivation_graph(
&self,
conn: &Connection,
memory_id: i64,
) -> Result<Vec<CoactivationEdge>>
pub fn get_coactivation_graph( &self, conn: &Connection, memory_id: i64, ) -> Result<Vec<CoactivationEdge>>
Return all edges incident to memory_id, sorted by strength descending.
Both from_id = memory_id and to_id = memory_id rows are returned,
normalized so that from_id is always memory_id in the result.
Return the top_k strongest co-activation partners for memory_id.
Result tuples are (neighbor_id, strength) sorted by strength
descending.
Sourcepub fn report(&self, conn: &Connection) -> Result<CoactivationReport>
pub fn report(&self, conn: &Connection) -> Result<CoactivationReport>
Compute aggregate statistics over the entire coactivation graph.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CoactivationTracker
impl RefUnwindSafe for CoactivationTracker
impl Send for CoactivationTracker
impl Sync for CoactivationTracker
impl Unpin for CoactivationTracker
impl UnsafeUnpin for CoactivationTracker
impl UnwindSafe for CoactivationTracker
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