The Mathematics of AI Memory Ingestion: Optimizing Storage and Context in the Remember Pipeline

When an AI agent interacts with the world, it encounters a continuous stream of interaction text, facts, and experiences. If we store every single interaction with equal weight, the agent's long-term memory quickly degenerates into an expensive, cluttered noise chamber.
To solve this, Spector Memory models the ingestion process (the remember pipeline) using mathematical representations of human cognition. By fusing qualitative metadata with quantitative statistical surprise, Spector calculates context priority, emotional charge, and retention eligibility.
In this deep dive, we explore the individual mathematical components that govern Spector's ingestion pipeline and present the Grand Unified Ingestion Equation that binds them together.
1. The Individual Components of Ingestion
Memory ingestion in Spector is a multi-stage pipeline. The process determines a memory's core cognitive metadata, including its final priority, valence (emotional sentiment), arousal (intensity), and retention configuration.
1.1 Spatial Working Memory Novelty
Before lookups are made, Spector measures how unique the incoming memory vector $\vec{x}_i$ is relative to the agent's recent context (represented by the active working memory set $W$):
$$N_i = \min\left( \frac{\min_{\vec{w} \in W} \|\vec{x}_i - \vec{w}\|_2}{d_{\text{max\_novelty}}}, 1.0 \right)$$
- Cognitive Concept: Humans automatically ignore repetitive environmental stimuli. If a memory is highly similar to what the agent has processed recently, its novelty drops toward zero.
- Parameter: $d_{\text{max\_novelty}}$ represents the distance boundary where a concept is considered completely unique (default:
2.0).
1.2 Subjective LLM Hints: The ICNU Model
Attention in the human brain is driven by factors such as Interest, Challenge, Novelty, and Urgency. These indicators allow our system to combine qualitative signals (Interest, Challenge, Urgency) with empirical novelty computed directly from the context history:
$$I_{\text{raw}} = 0.05 + 9.95 \cdot \left( w_I \cdot x_I + w_C \cdot x_C + w_N \cdot N_i + w_U \cdot x_U \right)$$
The weights are normalized ($\sum w = 1.0$) with default values:
- Interest ($w_I = 0.30$): Agent interest signal.
- Challenge ($w_C = 0.10$): Task complexity.
- Novelty ($w_N = 0.40$): The strongest indicator of future context value.
- Urgency ($w_U = 0.20$): Time-criticality.
This maps $I_{\text{raw}}$ cleanly to the range $[0.05, \, 10.0]$.
1.3 Dopamine-Inspired Surprise (Online Centroid Variance)
When qualitative hints are not available, the system uses a biologically inspired surprise calculation. It monitors how much incoming information deviates from the historical average:
$$M_{1, n} = M_{1, n-1} + \frac{d_n - M_{1, n-1}}{n}$$ $$S_n = S_{n-1} + (d_n - M_{1, n-1})(d_n - M_{1, n}) \implies \sigma_{\text{dist}} = \sqrt{\frac{S_n}{n - 1}}$$
The surprise of the current memory is then computed as a Z-score of its distance $d = \|\vec{x}_i - \vec{\mu}\|_2$ against the running history:
$$I_{\text{dopamine}} = \alpha_{\text{dop}} \cdot \sigma\left( \frac{d - \mu_{\text{dist}}}{\sigma_{\text{dist}}} \right) + \beta_{\text{dop}} \cdot \text{temporalNovelty}$$
Where $\sigma(x)$ is the standard sigmoid function, and $\text{temporalNovelty}$ represents the time elapsed since the last memory with similar topics was stored.
1.4 Amygdala Valence & Arousal Modulation
Spector colorizes memories with emotional properties:
- Valence ($V_i$): A value scaled from
-128(highly negative/error) to+127(highly positive/success) representing outcome quality: $$V_i = \text{clamp}(V_{\text{sentiment}} + \text{ValenceBias}_P, \, -128, \, 127)$$ - Arousal ($A_i$): Emotional intensity scaled from
0to255. If not explicitly set, it is derived directly from the valence magnitude: $$\text{arousal}_{\text{raw}} = \begin{cases} A_{\text{hint}} & \text{if } A_{\text{hint}} > 0 \\ \min(255, \, |V_i| \times 2) & \text{otherwise} \end{cases}$$ - Persona Self-Regulation: Arousal is compressed around the neutral midpoint (
128) to model executive control: $$\text{arousal}_{\text{modulated}} = (\text{arousal}_{\text{raw}} - 128) \cdot \text{arousalCompression}_P$$ $$A_i = \text{clamp}(\text{round}(128 + \text{arousal}_{\text{modulated}}), \, 0, \, 255)$$
1.5 Dynamic Salience Fields & Attentional Priming
In human neuroscience, the brain uses selective salience (Crick's Attentional Searchlight Hypothesis) to amplify sensory inputs relevant to active goals.
In Spector Memory, when an agent or user defines active salience topics ($T_B$), incoming memory vector $\vec{x}_i$ is evaluated against salience topic embeddings $\vec{t} \in T_B$:
$$B_{\text{salience}} = \max\left(1.0, \, \max_{\vec{t} \in T_B} \left( \text{multiplier}_t \cdot \cos(\vec{x}_i, \vec{t}) \cdot \mathbb{I}(\cos(\vec{x}_i, \vec{t}) > \theta) \right) \right)$$
- Cognitive Function: If an agent is operating in "Security Audit" focus mode, any memory describing cryptographic keys, permissions, or vulnerabilities receives an immediate multiplicative salience boost ($B_{\text{salience}} \ge 1.5$).
- Threshold: $\theta$ (default:
0.5) filters out semantic noise, ensuring only genuinely salient experiences are amplified.
1.6 The Soul Vector & Autobiographical Self-Model
A conscious mind is anchored by a persistent identity. Grounded in Antonio Damasio's Neurobiology of the Self (Proto-Self, Core Self, and Autobiographical Self), Spector incorporates an immutable or slowly evolving Soul Vector $\vec{S}_{\text{identity}} \in \mathbb{R}^d$ for every agent or human persona.
The Soul Alignment Factor ($A_{\text{soul}}$) measures how strongly an ingested experience reflects the entity's core values, moral axioms, and autobiographical identity:
$$A_{\text{soul}} = \frac{\vec{x}_i \cdot \vec{S}_{\text{identity}}}{\|\vec{x}_i\|_2 \|\vec{S}_{\text{identity}}\|_2} = \cos(\vec{x}_i, \, \vec{S}_{\text{identity}})$$
The total Self-Relevance Contribution ($S_{\text{soul}}$) fuses this cosine alignment with entity-level persona weights:
$$S_{\text{soul}} = w_{\text{soul}} \cdot A_{\text{soul}} \cdot 10.0 + \sum_{e \in E_P} \Delta I_e \cdot \mathbb{I}(e \in T_i)$$
- Long-Term Immortality: Experiences with high soul resonance ($A_{\text{soul}} > 0.75$) are flagged as core autobiographical relics. During Circadian Sleep Consolidation, they are permanently graduated to the Semantic Core, ensuring the persona never loses its core essence over time.
2. The Grand Unified Ingestion Equation
By linking these biological subsystems, we define the complete mathematical mapping of memory $i$ during ingestion. Given query vector $\vec{x}_i$, active salience field $T_B$, and the identity Soul Vector $\vec{S}_{\text{identity}}$, the stored properties are calculated via:
- Working Memory Novelty: $$N_i = \min\left( \frac{\min_{\vec{w} \in W} \|\vec{x}_i - \vec{w}\|_2}{2.0}, 1.0 \right)$$
- Raw LLM Importance: $$I_{\text{raw}} = 0.05 + 9.95 \cdot (w_I \cdot I_{\text{hint}} + w_C \cdot C_{\text{hint}} + w_N \cdot N_i + w_U \cdot U_{\text{hint}})$$
- Salience Multiplier: $$B_{\text{salience}} = \max\left(1.0, \, \max_{\vec{t} \in T_B} \left( \text{multiplier}_t \cdot \cos(\vec{x}_i, \vec{t}) \cdot \mathbb{I}(\cos(\vec{x}_i, \vec{t}) > 0.5) \right) \right)$$
- Soul & Self-Relevance Offset: $$S_{\text{soul}} = w_{\text{soul}} \cdot \cos(\vec{x}_i, \, \vec{S}_{\text{identity}}) \cdot 10.0 + \sum_{e \in E_P} \Delta I_e \cdot \mathbb{I}(e \in T_i)$$
- Combined Importance: $$I_{\text{combined}} = I_{\text{raw}} \cdot B_{\text{salience}} + S_{\text{soul}}$$
- Surprise Z-Score (Dopamine Deviation): $$Z_i = \frac{\|\vec{x}_i - \vec{\mu}\|_2 - \mu_{\text{dist}}}{\sigma_{\text{dist}}}$$
The final properties registered in storage are:
- Importance: $$I_i = \begin{cases} 10.0 & \text{if } Z_i \ge 3.0 \\ \text{clamp}(I_{\text{combined}}, \, 0.05, \, 10.0) & \text{otherwise} \end{cases}$$
- Pinned State (Flashbulb Memory): $$P_i = \begin{cases} 1 & \text{if } Z_i \ge 3.0 \\ 0 & \text{otherwise} \end{cases}$$
- Valence: $$V_i = \text{clamp}(V_{\text{sentiment}} + \text{ValenceBias}_P, \, -128, \, 127)$$
- Raw Arousal: $$\text{Arousal}_{\text{raw}} = \begin{cases} A_{\text{hint}} & \text{if } A_{\text{hint}} > 0 \\ \min(255, \, |V_i| \cdot 2) & \text{otherwise} \end{cases}$$
- Final Modulated Arousal: $$A_i = \text{clamp}\left(\text{round}\left(128.0 + (\text{Arousal}_{\text{raw}} - 128.0) \cdot \text{arousalCompression}_P\right), \, 0, \, 255\right)$$
Note: High statistical surprise ($Z_i \ge 3.0$) triggers a Flashbulb Memory response, locking the importance at a maximum value of 10.0 and pinning the memory to protect it from temporal decay.
3. Ingestion Pipeline Flow
By enforcing these calculations at ingestion, Spector ensures that every memory begins its lifecycle with a precise representation of its relevance, sentiment, and retention priority:
min L2 distance vs. short-term context"] B --> C["🔬 Fuse LLM Hints: ICNU Model
Interest, Challenge, Urgency + Novelty"] C --> D["⚡ Surprise Estimation (Welford's)
Z-Score of distance vs running centroid"] D --> E["🎯 Apply Dynamic Salience Field
Attentional focus boost B_salience"] E --> F["✨ Project Soul Vector (Damasio Self)
Compute identity cosine resonance S_soul"] F --> G["🎭 Emotional Valence & Arousal Modulate
Valence bias + midpoint 128 compression"] G --> H{"🚨 Flashbulb Check?
Z-Score ≥ 3.0"} H -->|"Yes"| I["📌 Pin Memory
Exempt from decay, importance = 10.0"] H -->|"No"| J["📝 Save Modulated Importance
0.05 – 10.0 range"] I --> K["💾 Write to Off-Heap Memory Substrate
Store vector, metadata, valence, arousal, and soul resonance"] J --> K