# THRPY EMC² (Emotional Memory Cloud Squared) **Mathematical Blueprint & Architectural Documentation** This document details the architecture and computational basis for the **EMC² Engine** (The Subconscious Undercurrent). EMC² acts as a multi-metric cluster cloud within the `eKG` (Emotional Knowledge Graph), drawing up deep, unstructured memories and tracking the "Energy" of a therapy session. --- ## 1. The Subconscious Vector Abstraction Unlike conscious semantic memories (facts like "My dog died last Tuesday"), the EMC² models the *subconscious* by extracting pure emotional concepts from speech and stripping away entity specifics. It measures the raw **Energy** of a conversation by using deeply abstract multi-metric clustering. ### Step 1: Generating the Semantic Silhouette The input text $T$ from `useRealFlowPipeline` is ingested into the local `Transformers.js` embedding matrix (`Xenova/all-MiniLM-L6-v2` or similar dense vector models). - $E(T)$ = Multidimensional Float32 Vector map (typically $D = 384$ or $768$). This vector does not act as a search query for identical nouns, but rather an **Emotional Silhouette** ($S$) that captures the *shape* of the sentiment. --- ## 2. Multi-Metric Vector Resonance (The "Undercurrent") The core math behind the "Subconscious Undercurrent" relies on calculating the Cosine Similarity ($\text{CosSimilarity}$) between the live user turn vector $S_L$ and historic unstructured memory vectors $S_H$ scattered in the database (or the browser `IndexedDB`). $$ \text{CosSimilarity}(S_L, S_H) = \frac{S_L \cdot S_H}{||S_L|| \times ||S_H||} $$ The result is a `resonance` score from `[-1.0, 1.0]`. ### Resonance Thresholds 1. **High Resonance ($> 0.85$):** This means the patient is unconsciously revisiting the same emotional state or theme (e.g., *Anxiety*, *Grief*) that they exhibited in a previous session, even if the words are completely different. 2. **Medium Resonance ($0.65 - 0.84$):** Represents an "echo" of a past theme, often contributing to background VAD adjustments (see: RealFuel). 3. **Divergent Resonance ($< 0.4$):** A completely new emotional trajectory. **Epiphanies (breakthrough moments)** are *not* defined by cosine alone. The live pipeline treats an epiphany as a **clinical/behavioral** event: vocal/UI telemetry, explicit language, and (when the model uses `synthesize_multi_modal_hypothesis` with `test_epiphany_hypothesis`) follow-up VAD. **EMC² cosine resonance** is **supporting context**—it flags that the current utterance’s silhouette *echoes* past thematic vectors (continuity), which can accompany insight but is not a standalone proof of an “aha.” --- ## 3. The Fusion with RealFuel The EMC² output is not presented directly as text, but instead fed into the VAD Fusion system (RealFeel + RealVoice). The `Resonance Score` modifies the **Confidence** multiplier for the Attractor-Detractor Framework (ADF). If the Subconscious Undercurrent perfectly aligns with a past moment of High-Risk Depression, the overall `EmotionConfidence` of the current VAD detection spikes, allowing the system to preemptively flag a risk even before explicit crisis words are spoken. ## 4. Why This Architecture Matters This is where the platform transcends a simple chatbot. By caching thousands of tiny emotional "moments" as abstract numerical vectors, the system can feel the "vibe" of a conversation, realizing a user is anxious because of their abstract silhouette, rather than waiting for them to explicitly type "I am anxious."