Emotional Valence
Relevant source files
The following files were used as context for generating this wiki page:
The Emotional Valence system provides multi-dimensional emotional context for memories within the CORTEX cognitive architecture. It replaces simple integer-based priority levels with a 6-dimensional emotional vector that influences how memories are stored, retrieved, and pruned. This system ensures that emotionally salient events resist forgetting and receive higher priority during recall, mimicking biological amygdala modulation of hippocampal consolidation.
Sources: src/valence/index.ts:1-10, README.md, benchmarks/cogbench/tasks/emotional-recall.ts:8-13
Core Architecture
The system analyzes memory content to produce an EmotionalVector and calculates EmotionalSalience metrics. These metrics modulate the memory lifecycle across ingestion, the Dream Cycle, and search retrieval.
The diagram shows the flow of emotional data from initial analysis to its impact on system-wide cognitive functions.
Sources: src/valence/analyzer.ts:108-149, src/mcp/server.ts:340-357
Emotional Dimensions
CORTEX uses an extended version of Russell's circumplex model of affect. Each dimension is normalized to a specific range.
| Dimension | Range | Description |
|---|---|---|
| Valence | [-1, 1] | Positive/negative affect (pleasure vs. displeasure). |
| Arousal | [-1, 1] | Activation intensity (calm vs. intense). |
| Dominance | [-1, 1] | Sense of agency or control (helpless vs. empowered). |
| Certainty | [-1, 1] | Epistemic confidence (speculative vs. verified). |
| Relevance | [0, 1] | Centrality to the agent's core mission. |
| Urgency | [0, 1] | Temporal salience or time pressure. |
Sources: src/valence/types.ts:7-38
Valence Analysis Logic
The analyzeValence function performs lexicon-based heuristic analysis. This approach provides zero-latency signal detection across all dimensions without requiring external API calls.
Signal Detection
The analyzer counts matches for predefined signal groups (e.g., POSITIVE_SIGNALS, HIGH_AROUSAL, URGENCY_SIGNALS) within the text. It normalizes these counts based on word density per 100 words to ensure consistent scoring across different chunk lengths.
The diagram illustrates the internal processing steps of the valence analyzer.
Sources: src/valence/analyzer.ts:15-106, src/valence/analyzer.ts:114-118
Salience Metrics
EmotionalSalience is derived from the vector to provide actionable values for other cognitive subsystems:
- Intensity: Calculated as the L2 norm of the vector, representing the overall emotional charge.
- Decay Resistance: Protects memories from pruning during the Dream Cycle. It is influenced by absolute valence, arousal, relevance, and urgency.
- Recall Boost: Enhances retrieval priority during hybrid search.
- Dominant Dimension: Identifies the dimension with the highest absolute magnitude.
Sources: src/valence/analyzer.ts:157-195
System Integration
Ingestion Pipeline
During the cortex_ingest process, the system analyzes every memory chunk for valence. The resulting vector and salience data are stored in the emotional_valence database table, linked to the corresponding memory_node.
Sources: src/mcp/server.ts:340-357, scripts/backfill-valence.ts:60-75
Search and Retrieval
CORTEX uses a 7-factor hybrid scoring system. Emotional valence contributes specifically through the recall_boost factor, which typically accounts for 10% of the total hybrid score. This ensures that relevant, emotionally charged memories surface faster than neutral ones.
The sequence shows how emotional data is integrated into the real-time search scoring logic.
Sources: src/mcp/server.ts:78-100, README.md
Dream Cycle (Pruning)
The phasePruning stage of the Dream Cycle uses decay_resistance to protect memories. Even if a memory has low resonance, it will not be deleted or archived if it possesses high emotional salience (e.g., decay_resistance > 0.5).
Sources: src/dream/dream-cycle.ts:228-232, src/dream/dream-cycle.ts:243-247
Data Structures
EmotionalVector
export interface EmotionalVector {
valence: number;
arousal: number;
dominance: number;
certainty: number;
relevance: number;
urgency: number;
}
Sources: src/valence/types.ts:24-38
EmotionalSalience
export interface EmotionalSalience {
intensity: number;
decayResistance: number;
recallBoost: number;
dominantDimension: keyof EmotionalVector;
}
Sources: src/valence/types.ts:41-50
Implementation Summary
The Emotional Valence system transforms raw text into a structured emotional fingerprint. By integrating this fingerprint into both retrieval (Recall Boost) and maintenance (Decay Resistance), the architecture ensures that the agent's "lived experience" is prioritized by significance rather than just recency or keyword matching. This provides a robust mechanism for long-term behavioral consistency and relevant recall in complex, high-stakes environments.
Sources: README.md, src/valence/analyzer.ts:7-13