-
Notifications
You must be signed in to change notification settings - Fork 5
Cognitive Architecture
cortex-engine implements a neuroscience-grounded cognitive architecture. The mechanisms below aren't biological metaphors — they implement the same mathematics that biological memory systems use, converging because the optimization problem is identical: retain useful information under finite storage with noisy input.
Biological brains use two parallel surprise signals. cortex-engine implements both:
When a new observation arrives, cortex computes 1 - max_similarity against existing memories. High PE means the graph was surprised — sparse coverage in that region.
- PE < 0.15 → merge into existing memory
- PE 0.15-0.50 → link as related
- PE > 0.50 → SURPRISE signal, candidate for new memory
The goal_set tool creates desired future states. Forward PE measures the gap between current beliefs and goal states: 1 - nearest_belief_score. This value signal biases:
- Consolidation — goal-relevant observations get priority processing
- Exploration — wander walks toward goal-adjacent memories
- Attention — high forward PE means "this goal is far from achieved"
Called via dreamPhaseA(). Run during or after sessions.
- Cluster — route observations to nearest memories (temporal order, schema congruence scoring, adaptive thresholds)
- Refine — update memory definitions from clustered evidence (+ re-validate edges)
- Create — promote unclustered observations to new memories
Called via dreamPhaseB(). Run in cron/background sessions.
- Connect — discover edges between recently active memories
- Score — FSRS review (interval-filtered, only due memories)
- Abstract — cross-domain pattern synthesis with provenance edges
- Report — narrative summary + Fiedler value + PE saturation status
dreamConsolidate() runs both phases for backward compatibility.
Standard path. Embeds the query, finds nearest neighbors, then traverses graph edges with scores weighted by ACTIVATION_DECAY * edge.weight * cos_sim(query, neighbor). This biases walks toward query-relevant branches.
aggregatedRetrieval(). For each candidate, computes an aggregated embedding: 0.6 * self + 0.4 * mean(neighbors). Re-scores against query. Memories in well-connected, contextually rich neighborhoods score higher.
multiAnchorRetrieval(). Generates 3 query rephrasings via LLM, runs parallel retrievals, uses Borda count voting. Memories that appear across multiple query formulations are ranked higher.
Fixed similarity thresholds are information-geometrically inconsistent — the embedding manifold has variable curvature. cortex-engine computes local embedding density and adjusts thresholds:
- Dense regions (specialized content): lower threshold → cluster more aggressively
- Sparse regions (generic content): higher threshold → be conservative
Additionally, schema congruence scoring checks the matched memory's edge density. Sparse neighborhoods (< 2 edges) with borderline similarity hold observations as episodic rather than prematurely clustering.
After each dream cycle, cortex computes the second-smallest eigenvalue of the graph Laplacian. This measures how integrated vs. compartmentalized knowledge is:
- High Fiedler → tightly connected graph, memories inform each other
- Low Fiedler → disconnected clusters, isolated knowledge
- Declining trend → dreams are fragmenting rather than integrating
Tracks prediction error trends on identity/reflective observations over 14-day windows. If mean PE drops below threshold, signals schema saturation — the system stops flagging its own inconsistencies. Triggers recommendation for adversarial rumination.
The wander tool uses information-gain-weighted exploration rather than random walks:
| Signal | Weight | Why |
|---|---|---|
| Under-explored (access_count < 3) | +0.3 | Haven't looked here enough |
| Low confidence (< 0.5) | +0.2 | Uncertain, worth revisiting |
| Goal-adjacent (category = goal) | +0.4 | Moves toward desired states |
| Stale (> 14 days since access) | +0.2 | Forgotten knowledge |
| Random | +0.3 | Preserve serendipity |
Memories use the FSRS-6 spaced repetition algorithm with cortex-specific enhancements:
- Interval-aware filtering — only reviews memories actually due (elapsed >= stability * 0.8)
- Composite rating — retrieval score, hop count, and contradiction signals affect rating
- Consolidation-aware decay — learning/relearning use shorter minimum thresholds (0.5 days vs 1.0 days)
When dream Phase 2 rewrites a memory definition, existing edges may become stale. cortex re-validates up to 5 non-generic edges per refined memory:
- Asks the LLM whether the relationship still holds given the new definition
- Invalid edges are severely downweighted (weight × 0.3), not deleted
- Evidence field is annotated with
[invalidated]and the reason
- Synapse (arXiv:2601.02744) — query-conditioned activation, SOTA on LoCoMo
- Nemori (arXiv:2508.03341) — FEP-based memory gating, SOTA on LongMemEval
- van Kesteren et al. 2024 — schema congruence in memory consolidation
- Bhatter et al. 2025 — LC-hippocampus prediction error and memory formation
- RnR Hypothesis (SLEEP Advances 2025) — REM as signal-to-noise refinement
- Geometric Theory of Cognition (arXiv:2512.12225) — Fisher-Rao metric on cognitive manifolds