Skip to content

Cognitive Architecture

idapixl edited this page Mar 25, 2026 · 2 revisions

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.

Prediction Error — Two Channels

Biological brains use two parallel surprise signals. cortex-engine implements both:

Novelty PE (LC/Norepinephrine analog)

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

Forward PE (VTA/Dopamine analog)

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"

Dream Consolidation — Two Phases

Phase A: NREM (Compression)

Called via dreamPhaseA(). Run during or after sessions.

  1. Cluster — route observations to nearest memories (temporal order, schema congruence scoring, adaptive thresholds)
  2. Refine — update memory definitions from clustered evidence (+ re-validate edges)
  3. Create — promote unclustered observations to new memories

Phase B: REM (Integration)

Called via dreamPhaseB(). Run in cron/background sessions.

  1. Connect — discover edges between recently active memories
  2. Score — FSRS review (interval-filtered, only due memories)
  3. Abstract — cross-domain pattern synthesis with provenance edges
  4. Report — narrative summary + Fiedler value + PE saturation status

dreamConsolidate() runs both phases for backward compatibility.

Retrieval — Three Mechanisms

1. Query-Conditioned Spreading Activation

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.

2. GNN Neighborhood Aggregation

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.

3. Multi-Anchor Retrieval (Thousand Brains)

multiAnchorRetrieval(). Generates 3 query rephrasings via LLM, runs parallel retrievals, uses Borda count voting. Memories that appear across multiple query formulations are ranked higher.

Adaptive Clustering (Information Geometry)

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.

Graph Health Metrics

Fiedler Value (Algebraic Connectivity)

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

PE Saturation Detection

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.

Epistemic Foraging

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

FSRS Scheduling

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)

Post-Refinement Edge Re-Validation

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:

  1. Asks the LLM whether the relationship still holds given the new definition
  2. Invalid edges are severely downweighted (weight × 0.3), not deleted
  3. Evidence field is annotated with [invalidated] and the reason

References

  • 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

Clone this wiki locally