Hebbian Co-Activation with Long-Term Potentiation and Hub-Normalized Spreading Activation
A Learning Loop for Local-First Code Intelligence
Abstract
A method for learning and recalling associations between code entities from ambient developer activity, wherein file edits occurring in close temporal proximity are coalesced into co-activation batches that strengthen weighted edges between the touched entities (Hebbian reinforcement), wherein edge weights undergo wall-clock exponential half-life decay with per-namespace and per-edge learned rates, wherein frequently reinforced edges acquire long-term potentiation (a decay floor and prune immunity), and wherein recall is performed by hub-normalized spreading activation over the merged multi-namespace graph. The loop runs entirely locally over a SQLite store, requires no telemetry or central service, and supplies an AI coding agent with associative context the static call graph cannot express.
Background
AI coding agents retrieve context by embedding similarity or static program analysis. Both miss the associations that only usage reveals:
- Embedding retrieval surfaces textually similar code, not code that changes together — a config file and the handler that consumes it share no vocabulary.
- Static graphs capture declared relations (calls, imports) but not workflow relations — the test fixture always edited alongside a parser, the migration that accompanies a model change.
- Version-history mining captures coupled changes only at commit granularity, offline, and without decay — stale couplings persist forever.
Our approach observes the working session itself: edits within a debounce window co-activate; co-activation strengthens edges; disuse decays them; habitual pairs become durable via long-term potentiation; and recall spreads activation outward from query-relevant seed nodes across the learned graph.
Core Algorithm
1. Co-Activation Capture
A file-activity watcher coalesces filesystem edits into batches. Edits arriving within a debounce window (default 0.75 s) of one another are grouped; a batch is flushed when the window goes quiet and delivered as a single co-activation event. Generated artifacts are excluded to prevent phantom edges. File deletions bypass the debounce and trigger targeted accelerated decay on the dead file's edges — stale memory pointing at refactored-away code is worse than no memory.
2. Hebbian Reinforcement
For a co-activation batch, every unordered pair of nodes receives a weight bump:
w ← min(WEIGHT_CAP, w + Δw) # WEIGHT_CAP = 1.0
Each node's activation counter increments in the same transaction as the edge upserts — a partial commit would skew LTP gating. A separate directed transition signal records sequential order ("A was active, then B") for next-action prediction.
3. Wall-Clock Half-Life Decay
The half-life H resolves per namespace — 30 d personal/branch, 60 d shared team baseline, 1 d ephemeral scratch — with per-edge learned overrides adapted from reinforcement history. Weights below 0.01 are pruned. Age derives from the stored last-activation timestamp, so decay is a pure function of wall-clock time, not pass frequency.
4. Long-Term Potentiation
Edges reinforced at least 5 times acquire durability: decay is floored at 0.20 and pruning skips them. One-off coincidences fade completely; habitual associations survive vacations. The ephemeral namespace is exempt — session scratch must die.
5. Namespaced Storage with Merged Read
Recent branch-local context always wins; the imported team baseline is never louder than the developer's own memory.
6. Hub-Normalized Spreading Activation
propagated = energy × merged_weight × SPREAD_DECAY × hub_factor # SPREAD_DECAY = 0.6
Recall seeds the graph with query-relevant nodes and propagates energy outward for 2 hops by default; energies accumulate additively across paths; the top-K nodes (default 12, seeds excluded) become recall output. The √(50/degree) term suppresses runaway central nodes — a utility module touched by everything would otherwise dominate every recall. An attribution variant tracks per-namespace energy shares, explaining exactly which namespace produced each recalled node.
Properties
Stability–plasticity balance. New associations form after a single co-activation yet vanish within weeks if never repeated; habitual associations (≥5 reinforcements) are permanent-but-quiet at worst.
Bounded and convergent. Weights cap at 1.0; hub normalization bounds per-hop amplification to √d for degree d > 50; with SPREAD_DECAY 0.6 and depth 2, activation strictly attenuates with distance.
Deterministic decay. Running the decay pass hourly or weekly yields identical weights for identical timestamps — the model survives sleeping laptops, sporadic CI, and idle clones.
Complexity. Reinforcement is O(k²) over a small human-editing batch in one transaction; decay is set-based SQL over all edges; spread is O(frontier × avg-degree) per hop, depth-bounded.
Reference Implementation
Python 3.10+ (stdlib-only for the synapse layer). Commit 4256418 (2026-08-06).
neuralmind/synapses.py— reinforce(), decay(), _spread(), record_sequence(), namespace merge weightingneuralmind/watcher.py— debounced co-activation batching, deletion-triggered targeted decayneuralmind/learned_decay.py— per-edge learned half-life adaptationtests/test_synapses.py,test_synapse_namespaces.py,test_watcher.py,test_learned_decay.py
Prior Art Statement
To the best of our knowledge, the specific combination of debounce-windowed filesystem co-activation, capped Hebbian strengthening with transactional activation counting, wall-clock half-life decay with per-namespace policy and learned per-edge overrides, activation-count-gated long-term potentiation, hub-normalized spreading activation over a multiplier-merged multi-namespace graph, and deletion-triggered targeted decay — applied to context retrieval for AI coding agents in a local-first, telemetry-free system — has not been previously published. Related work:
- Hebbian learning (Hebb, 1949) — the co-activation principle, without decay policy, LTP gating, or code-entity application
- Long-term potentiation (Bliss & Lømo, 1973) — biological analogue of the durability mechanism
- Spreading activation (Collins & Loftus, 1975) — semantic-network recall, without hub normalization or namespace merging
- ACT-R declarative memory (Anderson & Lebiere, 1998) — base-level activation with time decay, for cognitive modeling rather than code graphs learned from editor activity
- Mining version histories (Zimmermann et al., 2004) — co-change coupling at commit granularity, offline, without decay or recall-time spread