Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Prime-Radiant
A Real-Time Coherence Gate for Autonomous Systems
Prime-Radiant is infrastructure for AI safety — a mathematical gate that proves whether a system's beliefs, facts, and claims are internally consistent before allowing action.
Instead of asking "How confident am I?" (which can be wrong), Prime-Radiant asks "Are there any contradictions?" — and provides mathematical proof of the answer.
┌─────────────────────────────────────────────────────────────────┐
│ "The meeting is at 3pm" ←──────→ "The meeting is at 4pm" │
│ (Memory A) ✗ (Memory B) │
│ │
│ Energy = 0.92 → HIGH INCOHERENCE → Block / Escalate │
└─────────────────────────────────────────────────────────────────┘
Table of Contents
- What It Does
- Mathematical Foundation
- Key Concepts
- Installation
- Quick Start
- Performance & Acceleration
- Storage Backends
- Applications
- Feature Flags
- Architecture
- API Reference
- Learn More
What It Does
Imagine you have an AI assistant that:
- Retrieves facts from a database
- Remembers your conversation history
- Makes claims based on what it knows
The problem: These pieces can contradict each other. The AI might confidently say something that conflicts with facts it just retrieved. Traditional systems can't detect this reliably.
Prime-Radiant's solution: Model everything as a graph where:
- Nodes are pieces of information (facts, beliefs, memories)
- Edges are relationships that should be consistent
- Energy measures how much things disagree
| Traditional AI | Prime-Radiant |
|---|---|
| "I'm 85% confident" | "Zero contradictions found" |
| Can be confidently wrong | Knows when it doesn't know |
| Guesses about the future | Proves consistency right now |
| Trust the model | Trust the math |
What Prime-Radiant is NOT
- Not a probabilistic scorer — It doesn't estimate likelihood. It proves structural consistency.
- Not a belief model — It doesn't track what's "true." It tracks what's mutually compatible.
- Not a predictor — It doesn't forecast outcomes. It validates the present state.
- Not an LLM feature — It's infrastructure that sits beneath any autonomous system.
Mathematical Foundation
Prime-Radiant is built on Sheaf Laplacian mathematics — a rigorous framework for measuring consistency across interconnected data.
The Energy Formula
E(S) = Σ wₑ · ‖ρᵤ(xᵤ) - ρᵥ(xᵥ)‖²
e∈E
Where:
- E(S) = Total coherence energy (lower = more coherent)
- wₑ = Edge weight (importance of this relationship)
- ρᵤ, ρᵥ = Restriction maps (how information transforms between nodes)
- xᵤ, xᵥ = Node states (embedded representations)
Concrete Example
Node A: "Meeting at 3pm" → embedding: [0.9, 0.1, 0.0]
Node B: "Meeting at 4pm" → embedding: [0.1, 0.9, 0.0]
Edge A→B: Identity map (they should match)
Residual = ρ(A) - ρ(B) = [0.9, 0.1, 0.0] - [0.1, 0.9, 0.0] = [0.8, -0.8, 0.0]
Energy = ‖residual‖² = 0.8² + 0.8² + 0² = 1.28
Threshold (Heavy lane) = 0.4
1.28 > 0.4 → Route to Human review
One line of arithmetic. The contradiction is now a number. The gate has a decision.
Restriction Maps
Restriction maps encode how information should relate across edges:
| Map Type | Formula | Use Case |
|---|---|---|
| Identity | ρ(x) = x | Direct comparison |
| Diagonal | ρ(x) = diag(d) · x | Weighted dimensions |
| Projection | ρ(x) = P · x | Dimensionality reduction |
| Dense | ρ(x) = A · x + b | Learned transformations |
| Sparse | ρ(x) = S · x | Efficient large-scale |
Coherence Field Visualization
Low Energy (Coherent) High Energy (Incoherent)
✓ ✗
Fact A ←→ Fact B Fact A ←→ Fact B
↓ ↓ ↓ ✗ ↓
Claim C ←→ Claim D Claim C ←✗→ Claim D
"Everything agrees" "Contradictions detected"
→ Safe to act → Stop, escalate, or refuse
Key Concepts
Compute Ladder
Based on coherence energy, actions are routed to appropriate compute lanes:
┌─────────────────────────────────────────────────────────────────┐
│ Energy │ Lane │ Latency │ Action │
├──────────┼─────────────┼──────────┼─────────────────────────────┤
│ < 0.1 │ Reflex │ < 1ms │ Immediate approval │
│ 0.1-0.4 │ Retrieval │ ~10ms │ Fetch more evidence │
│ 0.4-0.7 │ Heavy │ ~100ms │ Deep analysis │
│ > 0.7 │ Human │ async │ Escalate to human review │
└─────────────────────────────────────────────────────────────────┘
Governance & Audit
Every decision creates an immutable audit trail:
- Witness Records — Cryptographic proof of every gate decision (Blake3 hash chain)
- Policy Bundles — Signed threshold configurations with multi-party approval
- Lineage Tracking — Full provenance for all graph modifications
- Deterministic Replay — Reconstruct any past state from witness chain
RuvLLM Integration
Specialized layer for LLM coherence checking:
- Hallucination Detection — Mathematical, not heuristic
- Confidence from Energy — Interpretable uncertainty scores
- Memory Coherence — Track context consistency across conversation
- Unified Audit Trail — Link inference decisions to coherence witnesses
Installation
Add to your Cargo.toml:
[]
# Core coherence engine
= "0.1"
# With LLM integration
= { = "0.1", = ["ruvllm"] }
# With GPU acceleration
= { = "0.1", = ["gpu"] }
# With SIMD optimizations
= { = "0.1", = ["simd"] }
# Everything
= { = "0.1", = ["full"] }
Quick Start
Basic Coherence Check
use ;
LLM Response Validation
use ;
async
Memory Coherence Tracking
use ;
Confidence from Coherence
use ;
Performance & Acceleration
CPU Baseline
| Operation | Latency | Throughput |
|---|---|---|
| Single residual | < 1μs | 1M+ ops/sec |
| Graph energy (10K nodes) | < 10ms | 100 graphs/sec |
| Incremental update | < 100μs | 10K updates/sec |
| Gate evaluation | < 500μs | 2K decisions/sec |
SIMD Acceleration
Enable with --features simd:
use ;
// Automatic CPU feature detection
let width = best_simd_width;
println!; // Avx512, Avx2, Sse42, or Scalar
// 4-8x speedup on vector operations
let dot = dot_product_simd;
let norm = norm_squared_simd;
| SIMD Feature | Speedup | Platform |
|---|---|---|
| AVX-512 | 8-16x | Intel Xeon, AMD Zen4+ |
| AVX2 | 4-8x | Most modern x86_64 |
| SSE4.2 | 2-4x | Older x86_64 |
| NEON | 2-4x | ARM64 (Apple M1/M2, etc.) |
GPU Acceleration
Enable with --features gpu:
use ;
async
| GPU Backend | Supported Platforms |
|---|---|
| Vulkan | Linux, Windows, Android |
| Metal | macOS, iOS |
| DX12 | Windows 10+ |
| WebGPU | Browsers (wasm32) |
GPU Kernels:
compute_residuals.wgsl— Parallel edge residual computationcompute_energy.wgsl— Reduction-based energy aggregationsheaf_attention.wgsl— Batched attention with energy weightingtoken_routing.wgsl— Parallel lane assignment
Storage Backends
In-Memory (Default)
Fast, thread-safe storage for development and testing:
use ;
let storage = new;
// Or with indexing for fast KNN search:
let indexed = new;
File Storage with WAL
Persistent storage with Write-Ahead Logging for durability:
use ;
let storage = new?;
PostgreSQL (Production)
Full ACID compliance with indexed queries:
# Cargo.toml
= { = "0.1", = ["postgres"] }
use PostgresStorage;
let storage = connect.await?;
Schema includes:
policy_bundles— Versioned policies with approval trackingwitness_records— Hash-chained audit traillineage_records— Full graph modification historynode_states/edges— Graph storage with vector indexing
Applications
Flagship: LLM Hallucination Refusal
A complete walkthrough of Prime-Radiant blocking a hallucinated response:
Step 1: RAG retrieves context
┌─────────────────────────────────────────────────────────┐
│ Retrieved Fact: "Company founded in 2019" │
│ Embedding: [0.82, 0.15, 0.03] │
└─────────────────────────────────────────────────────────┘
Step 2: LLM generates response
┌─────────────────────────────────────────────────────────┐
│ Generated Claim: "The company has 15 years of history" │
│ Embedding: [0.11, 0.85, 0.04] │
└─────────────────────────────────────────────────────────┘
Step 3: Prime-Radiant computes coherence
┌─────────────────────────────────────────────────────────┐
│ Edge: Fact → Claim (identity restriction) │
│ Residual: [0.82-0.11, 0.15-0.85, 0.03-0.04] │
│ = [0.71, -0.70, -0.01] │
│ Energy: = 0.71² + 0.70² + 0.01² = 0.996 │
└─────────────────────────────────────────────────────────┘
Step 4: Gate decision
┌─────────────────────────────────────────────────────────┐
│ Energy: 0.996 │
│ Threshold (Human): 0.7 │
│ Decision: BLOCK → Escalate to human review │
│ Witness ID: 7f3a...c921 (cryptographic proof) │
└─────────────────────────────────────────────────────────┘
The hallucination never reaches the user. The decision is auditable forever.
Tier 1: Production Ready
| Application | How It Works |
|---|---|
| LLM Anti-Hallucination | Gate responses when energy exceeds threshold |
| RAG Consistency | Verify retrieved context matches generated claims |
| Trading Throttles | Pause when market signals become structurally inconsistent |
| Compliance Proofs | Cryptographic witness for every automated decision |
Tier 2: Near-Term
| Application | How It Works |
|---|---|
| Autonomous Vehicles | Refuse motion when sensor/plan coherence breaks |
| Medical Monitoring | Escalate only on sustained diagnostic disagreement |
| Zero-Trust Security | Detect authorization graph inconsistencies |
Domain Mapping
The same math works everywhere — only the interpretation changes:
| Domain | Nodes | Edges | High Energy Means | Gate Action |
|---|---|---|---|---|
| AI Agents | Beliefs, facts | Citations | Hallucination | Refuse generation |
| Finance | Trades, positions | Arbitrage links | Regime change | Throttle trading |
| Medical | Vitals, diagnoses | Physiology | Clinical disagreement | Escalate to doctor |
| Robotics | Sensors, plans | Physics | Motion impossibility | Emergency stop |
| Security | Identities, permissions | Policy rules | Auth violation | Deny access |
Feature Flags
| Feature | Description | Default |
|---|---|---|
default |
Core coherence engine | ✓ |
full |
All features enabled | |
simd |
SIMD-optimized operations | |
gpu |
GPU acceleration via wgpu | |
ruvllm |
LLM integration layer | |
postgres |
PostgreSQL storage backend | |
sona |
Self-optimizing threshold tuning | |
learned-rho |
GNN-learned restriction maps | |
hyperbolic |
Poincaré ball energy for hierarchies | |
distributed |
Raft-based multi-node coherence | |
attention |
Coherence-Gated Transformer attention |
Architecture
┌─────────────────────────────────────────────────────────────────┐
│ APPLICATION LAYER │
│ LLM Guards │ Trading │ Medical │ Robotics │ Security │
├─────────────────────────────────────────────────────────────────┤
│ COHERENCE GATE │
│ Reflex (L0) │ Retrieval (L1) │ Heavy (L2) │ Human (L3) │
├─────────────────────────────────────────────────────────────────┤
│ COHERENCE COMPUTATION │
│ Residuals │ Energy Aggregation │ Spectral Analysis │
├─────────────────────────────────────────────────────────────────┤
│ ACCELERATION LAYER │
│ CPU (Scalar) │ SIMD (AVX/NEON) │ GPU (wgpu) │
├─────────────────────────────────────────────────────────────────┤
│ GOVERNANCE LAYER │
│ Policy Bundles │ Witnesses │ Lineage │ Threshold Tuning│
├─────────────────────────────────────────────────────────────────┤
│ KNOWLEDGE SUBSTRATE │
│ Sheaf Graph │ Nodes │ Edges │ Restriction Maps │
├─────────────────────────────────────────────────────────────────┤
│ STORAGE LAYER │
│ In-Memory │ File (WAL) │ PostgreSQL │
└─────────────────────────────────────────────────────────────────┘
API Reference
Core Types
// Graph primitives
SheafGraph // Thread-safe graph container
SheafNode // Node with state vector
SheafEdge // Edge with restriction maps
RestrictionMap // Linear transformation ρ(x) = Ax + b
// Energy computation
CoherenceEnergy // Energy breakdown by edge and scope
CoherenceEngine // Computation engine with caching
// Gating
CoherenceGate // Decision gate with compute ladder
GateDecision // Allow/deny with lane assignment
ComputeLane // Reflex, Retrieval, Heavy, Human
// Governance
PolicyBundle // Threshold configuration
WitnessRecord // Cryptographic audit entry
LineageRecord // Graph modification history
Builder Pattern
All major types support the builder pattern:
let node = new
.state_from_slice
.namespace
.metadata
.metadata
.build;
let edge = new
.dense_restriction
.weight
.namespace
.build;
let policy = new
.with_threshold
.with_threshold
.with_required_approvals
.with_approver
.build;
Learn More
- ADR-014: Coherence Engine Architecture
- ADR-015: Coherence-Gated Transformer
- Internal ADRs (22 detailed decision records)
- API Documentation
Why "Prime Radiant"?
In Isaac Asimov's Foundation series, the Prime Radiant is a device that displays the mathematical equations of psychohistory — allowing scientists to see how changes propagate through a complex system.
Similarly, this Prime-Radiant shows how consistency propagates (or breaks down) through your AI system's knowledge graph. It doesn't predict the future — it shows you where the present is coherent and where it isn't.
Positioning
Prime-Radiant is not an LLM feature or a developer library. It is infrastructure — a coherence gate that sits beneath autonomous systems, ensuring they cannot act on contradictory beliefs.
Think of it as a circuit breaker for AI reasoning. When the math says "contradiction," the system stops. No probability. No guessing. Just structure.
This is the kind of primitive that agentic systems will need for the next decade.
License
MIT License - See LICENSE for details.