← all documents · raw markdown · 5 KB

KAI Codebase Proofs: Comprehensive Architectural Audit (Volume 3)

Focus: The Epistemic Immune System and Three-Angle Protocol

Continuing the extraction from the Rust backend. This volume provides proof that KAI does not indiscriminately memorize all incoming data (the primary flaw of LLMs context windows). Instead, KAI subjects all incoming waveforms to a rigorous geometric "Immune System."

---

7. The Three-Angle Epistemic Protocol

When a new concept attempts to form a claim in KAI's memory, the RSHL tests its structural integrity against everything KAI already knows.

Proof from src/core/universe.rs (ingest_and_verify)

    /// Implements the Three-Angle Protocol (whitepaper Section 10.3):
    ///   Angle 1 — Query lattice for positive evidence supporting the claim
    ///   Angle 2 — Query lattice for evidence contradicting the claim
    ///   Angle 3 — Compute domain resonance against the target region
    pub fn ingest_and_verify(
        &mut self,
        text: &str,
        region: &str,
        source: &str,
        confidence: f32,
    ) -> bool {
        // Encode the claim text for geometric comparison
        let claim_vec = SparseVec::encode(text);

        const PHYSICS_RESONANCE_FLOOR: f32 = 0.55;
        let coherence_floor = if self.calibration_floor > 0.0 { self.calibration_floor } else { 0.40 };

        // Angle 1 — Direct evidence: query for cells that SUPPORT this claim
        let supporting_hits = self.query_in_regions(text, 10, &[region], "");
        
        // Angle 2 — Adversarial evidence: scan for cells that CONTRADICT this claim.
        // A contradiction is defined as: semantically similar (cosine > 0.65)
        // but conceptually different (keyword overlap < 0.25) with HIGHER confidence.
        let mut angle2_score = 0.0f32;
        for cell in &self.cells {
            if cell.claim.confidence > confidence {
                let sim = claim_vec.cosine(&cell.claim.vec);
                if sim > 0.65 {
                    let kw = keyword_overlap_score(&claim_words, &cell.claim.text);
                    if kw < 0.25 {
                        // This cell contradicts the new claim. Score by confidence.
                        angle2_score = angle2_score.max(
                            sim * (cell.claim.confidence.min(5.0) / 5.0)
                        );
                    }
                }
            }
        }

        // Angle 3 — Domain resonance: how well does this claim fit its target region?
        let region_cells: Vec<&Cell> = self.cells.iter().filter(|c| c.region.as_ref() == region).collect();
        let angle3_resonance = if region_cells.is_empty() { 1.0 } else { /* average cosine sum */ };

        // ── Epistemic Gatekeeper ───────────────────────────────────────────
        if angle3_resonance < coherence_floor {
            log_rejected_claim(text, region, source, confidence, "three-angle coherence floor");
            return false;
        }

        if region == "established-physics" && angle3_resonance < PHYSICS_RESONANCE_FLOOR {
            log_rejected_claim(text, region, source, confidence, "physics resonance floor");
            return false;
        }

Proof Analysis: Standard AI networks append information directly to context or training data without logical verification. KAI executes a full structural check:

1. Adversarial Scanning (Angle 2): KAI hunts for high-confidence cells that conceptually overlap but use conflicting keywords. If KAI knows "E=mc2" at Confidence 5.0, and a user tells it "E=mc3" at Confidence 1.0, the geometric resonance is high (cosine > 0.65) but keyword overlap is low, triggering Angle 2 to flag it as a contradiction.

2. Domain Resonance (Angle 3): The input vector must physically "fit" the geometry of the target region. If a user tries to inject a joke into the "established-physics" region, the structural resonance falls below the 0.55 floor, and KAI physically rejects the claim.

---

8. Dynamic Calibration (Self-Regulating Scepticism)

KAI does not have a static threshold for what it believes. If it is being actively lied to or confused, it raises its internal defenses to protect the lattice topology.

Proof from src/core/universe.rs

        if angle2_score > 0.0 {
            self.recent_contradictions = self.recent_contradictions.saturating_add(1);
            if self.recent_contradictions > 5 {
                self.calibration_floor = (self.calibration_floor + 0.05).min(0.65);
                self.recent_contradictions = 0;
            }
        } else {
            self.calibration_floor = (self.calibration_floor - 0.01).max(0.40);
        }

Proof Analysis: This mathematically proves KAI's self-regulating skepticism. Every time an incoming wave triggers destructive interference (angle2_score > 0.0), KAI tracks the contradiction. If a user tries to aggressively gaslight KAI (>5 contradictions), the calibration_floor dynamically hardens up to 0.65. KAI literally becomes structurally harder to convince when under epistemic attack. When the environment is safe and coherent, the floor relaxes back to 0.40, allowing for faster neuroplastic absorption of concepts.