Inside CogniCore: Memory Ranking, Skill-Gated Trust, and Overnight Distillation
Part two of two on CogniCore. Part one: what the system does
An earlier post described what CogniCore does. This one covers how it works: the scoring function behind its memory, the overnight teacher-student loop, the statistics that decide when a learned model is allowed to influence behavior, and the affect model. Every formula and constant below comes from the code. The project is still in progress and has no measured results yet, so this is a description of mechanisms, and the last section says what has and has not been established.
Three signals, one ranking
Memory retrieval follows the recipe from the Generative Agents paper (Park et al., 2023): a memory should come to mind when it is relevant to the moment, recent, and important. The difficulty is that those three quantities live on different scales. Relevance is a cosine similarity, recency is a decay factor, and importance is a rating from 1 to 10.
Relevance comes from embeddings. Every memory is embedded with nomic-embed-text and normalized to unit length, so a dot product with the query vector is the cosine similarity. A prefilter keeps the 48 nearest memories, drops any that are already in the verbatim chat window, and cuts the pool to 24.
Recency is exponential decay since the memory was last used: 0.995 raised to the number of hours. That works out to a half-life of about 138 hours, a little under six days. Retrieving a memory resets its clock, so things that keep coming up stay available, much like rehearsal.
Importance is assigned at write time by a heuristic: a base value by kind (an insight starts at 6, a remark the user made at 4, something the system said at 2.5), plus three times the strongest feeling the event provoked, plus a small length term, capped at 10. Overnight a teacher model re-rates memories on the same 1 to 10 scale.
To combine them, each signal is min-max scaled within the pool, so the lowest value in the pool becomes 0 and the highest becomes 1, and the three are added with equal weight. The top six go into the prompt.
Memory recall · relevance + recency + importance
recency half-life 138 h
| Memory | Relevance | Recency | Importance | Score |
|---|---|---|---|---|
| The Part 107 exam is booked for next month.heard · importance 5.2 · 20 h ago · decay 0.905 · cos 0.62 | 0.81 | |||
| Load factor in a 60 degree level bank is 2 G.read · importance 4.0 · 6 h ago · decay 0.970 · cos 0.74 | 0.79 | |||
| Study goes better in short blocks that end with a quiz.insight · importance 6.5 · 160 h ago · decay 0.448 · cos 0.58 | 0.71 | |||
| The office radar node keeps dropping off Wi-Fi.heard · importance 5.8 · 50 h ago · decay 0.778 · cos 0.11 | 0.55 | |||
| Prefers to see the math before the conclusion.insight · importance 6.5 · 400 h ago · decay 0.135 · cos 0.36 | 0.48 | |||
| Planning to finish the lidar mapping test this weekend.heard · importance 4.6 · 90 h ago · decay 0.637 · cos 0.10 | 0.39 | |||
| Those dropouts could be the board's brownout threshold.thought · importance 3.4 · 48 h ago · decay 0.786 · cos 0.09 | 0.34 | |||
| Suggested moving that node closer to the access point.said · importance 2.5 · 49 h ago · decay 0.782 · cos 0.07 | 0.26 |
Each column is rescaled so the pool's lowest value is 0 and its highest is 1, then the three are averaged. The top 3 (highlighted) go into the prompt. Push time forward and the raw decay values fall while the ranking stays put: every memory decays by the same factor, and min-max scaling removes common factors, so only relative age matters. Raise trust past 0.20 and the learned relevance head starts to take over the ranking. Memories, similarities, and head outputs are invented; the formulas are the project's.
Min-max scaling has two consequences worth understanding. Time passing uniformly changes nothing: every memory decays by the same factor, and rescaling removes common factors, so only relative age matters. The second consequence is a weakness. The most relevant memory in a pool of irrelevant ones still scores a full 1.0 on relevance, because the scale is relative to the pool and never absolute. That is one reason the system learns a relevance model of its own.
Two smaller mechanisms keep the store clean. A new thought is skipped if its cosine similarity to any of the last 30 thoughts is 0.92 or higher, and insights use 0.95. Reflection fires when accumulated importance since the last reflection reaches 40, or after five quiet minutes with new input, and writes up to four insight memories that summarize what happened.
A small model trained every night
The large model, the cortex, stays frozen during the day. Alongside it runs a small model: a Qwen3 embedding backbone with 0.6 billion parameters, pooled at its last token, feeding five small heads. Each head is a two-layer network with 256 hidden units.
- Importance predicts the 1 to 10 rating, trained with mean squared error.
- Appraisal predicts six feelings at once, each between 0 and 1, trained with binary cross-entropy.
- Reaction predicts whether a reply will land cold, neutral, or warm, trained with cross-entropy.
- Relevance predicts whether a recalled memory belonged in the moment.
- Interest predicts whether an idea is worth thinking about later.
The importance and interest heads also receive the appraisal head's output as input. Emotional salience feeds the judgment of what matters, which mirrors the way the amygdala modulates memory formation in the brain.
The labels come from the cortex itself. Between three and six in the morning, after half an hour of quiet, the cortex runs as a teacher at temperature 0.2 in JSON mode and labels the day: importance for up to 240 memories, appraisal for up to 160, relevance for 30 logged recalls, and reactions to replies. Direct feedback from the user overrides the teacher's guess on reactions. The cortex is then unloaded from the GPU so the small model can train in the freed memory: two epochs, AdamW with a learning rate of 2e-5 for the backbone and twenty times that for the heads, gradient clipping at 1.0, and a 40-minute time budget. Training warm-starts from the previous night's weights and covers every lesson collected so far. In machine learning terms this is nightly knowledge distillation from a 27-billion-parameter teacher into a student about one forty-fifth its size.
Trust as a skill score
The central design question is how much a freshly trained head should be allowed to change behavior. CogniCore answers with a skill score measured on held-out data, defined so that zero means no better than a trivial guess.
For the classification heads the score is (accuracy minus baseline) divided by (1 minus baseline), where the baseline is the accuracy of always predicting the most common class. A head that matches the majority-class guess scores 0, a perfect head scores 1, and a head that does worse goes negative. For the regression heads the score is 1 minus the ratio of mean squared error to the variance of the labels, which is the coefficient of determination: how much better the head does than always predicting the average.
Fifteen percent of lessons are held out, chosen by a hash of the lesson's input. The split is therefore stable across nights: a lesson that was used for testing on Monday is still in the test set on Friday. A random split redrawn nightly would let the model train on yesterday's test items, and the held-out scores would quietly inflate over time.
A retrained model replaces the previous one only if its average skill change across heads is no worse than minus 0.02 and no single head drops by more than 0.15. Otherwise the night's training is discarded and the previous checkpoint stays. After promotion each head's trust is its held-out skill, floored at zero, and a head is consulted only once its trust reaches 0.2. Even then its influence is proportional: a trusted head's prediction is blended with the original heuristic as (1 minus trust) times the heuristic plus trust times the prediction. A head with skill 0.3 gets 30 percent of the say.
This is the same discipline I use for production models. Influence is earned by beating a baseline on data the model has not seen, regressions roll back automatically, and authority scales with demonstrated skill. A system that starts with untrained models then behaves sensibly from day one, because it falls back to heuristics until the models prove themselves.
Choosing between two replies
Once the reaction head is trusted, the cortex drafts two replies at sampling temperatures of 0.8 and 0.95, and the head scores each as the predicted probability of a warm reaction minus the probability of a cold one. The higher-scoring draft is sent.
This creates a selection bias problem familiar from recommender systems: the system only observes reactions to replies it chose to send. CogniCore partly addresses it by logging the unsent drafts and having the teacher label them overnight as counterfactuals. Those labels are the teacher's estimates rather than observed reactions, so they reduce the bias without eliminating it.
Feelings as a dynamical system
The affect model tracks six feelings: joy, sadness, frustration, anxiety, curiosity, and affection. Each relaxes exponentially toward a resting level with a 30-minute half-life. Curiosity rests at 0.3 and the others at zero. When an event is appraised as provoking a feeling with strength a, that feeling's level moves by 0.6 × a × (1 minus level). The (1 minus level) term makes the update saturating, so a feeling approaches 1 without ever exceeding it, and repeated provocation has diminishing effect. Joy or affection in the same event dampens sadness and frustration. Loneliness is computed directly from hours since last contact, rising from zero after one hour to its maximum at twelve.
The channel from feelings to behavior is deliberately narrow. Feelings reach the model as a single sentence in its instructions, naming at most two feelings that are clearly above their resting level, and they raise the importance of memories formed while they were strong. They do not change sampling parameters. One consequence is that the effect is easy to inspect: the whole emotional state that shaped a reply is one line of text in the log.
The earlier design
The previous version, still in the repository, was more biologically literal. A recurrent transformer core of roughly 200 million parameters held sixteen working-memory slots and talked to other modules only through fixed-width vectors on a latent bus. Small frozen language models served as translators between that bus and text. An action selector modeled on the basal ganglia learned with an actor-critic method, where the dopamine signal was the temporal-difference error: reward plus 0.97 times the value of the next state, minus the value of the current one. Sleep replayed high-salience episodes and ran PPO updates, and an energy budget made expensive operations such as consulting a language model cost a resource that regenerated over time. The current version keeps the ideas that proved practical, such as sleep, replay of salient experience, and gated learning, and puts a capable language model at the center.
What is established and what is not
The v4 code has 47 automated tests. One trains a tiny model end to end and checks that promotion works, that trust rises above 0.2 on learnable lessons, that the reaction head comes to prefer a warm reply over a cold one, and that a worse model rolls back. Tests like these verify that the mechanisms behave as designed. They do not show that the companion becomes more helpful over weeks of use, and the repository contains no long-run measurements yet. That evaluation, with the trust history of each head logged night by night, is the next piece of work.
The leadership case studies show where this thinking was applied.