# Thermogram π§
**Living knowledge files with embedded SNN plasticity**
Thermogram is a plastic memory capsule that combines:
- **Dirty/Clean dual states** - Fast mutable deltas + consolidated snapshots
- **Embedded SNN plasticity engine** - STDP, homeostasis, competition, decay
- **Hash-chained audit trail** - Cryptographic verification of all changes
- **Optional neuromod sync** - Colony-wide chemical balance coordination
- **Consolidation cycles** - Brain-like sleep/replay
- **Engram export** - Archive to immutable format without deletion
## The Problem
Traditional storage is either:
- **Mutable** (databases, files) - Fast but no audit trail, hard to prove integrity
- **Immutable** (Git, Engram) - Auditable but can't evolve organically
Brains don't work like either - they're **plastic with constraints**. Connections strengthen and weaken based on rules (STDP, homeostasis), not arbitrary writes.
## The Solution
Thermogram is a **single file** that contains:
1. **Clean state** - Consolidated snapshot (prototypes, weights, indexes)
2. **Dirty state** - Append-only delta log (hash-chained)
3. **Plasticity engine** - Small SNN that generates deltas via spiking dynamics
4. **Neuromodulation** - Optional sync with external chemical balance
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Thermogram: llm_clusters.thermo β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Clean State (Consolidated) β
β ββ Concept Prototypes [100 x 2048] β
β ββ Associative Weights (sparse) β
β ββ Indexes (ANN, routing tables) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Dirty State (Append-Only Deltas) β
β ββ DELTA_PROTO(cluster_5, Ξvector, lr, evidence) β
β ββ DELTA_EDGE(12, 34, Ξw, stdp, evidence) β
β ββ DECAY(epoch, params) β
β ββ ... (hash-chained) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Plasticity Engine (Embedded SNN) β
β ββ 100 neurons (spiking) β
β ββ STDP: cells that fire together wire together β
β ββ Homeostasis: prevent runaway strengthening β
β ββ Competition: winner-take-most β
β ββ Decay: natural forgetting β
β ββ Gating: context-dependent activation β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Neuromodulation (Synced or Independent) β
β ββ Dopamine: 0.6 (learning rate β) β
β ββ Serotonin: 0.5 (decay rate β) β
β ββ Norepinephrine: 0.4 (competition β) β
β ββ Acetylcholine: 0.7 (attention β) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
## Colony Architecture
Multiple Thermograms can coexist as **independent organisms** or **sync neuromodulation** for colony-wide coordination:
```
Astromind (Central)
ββ InnerPilot SNN
β ββ Neuromodulation: {dopamine, serotonin, norepinephrine, acetylcholine}
β
ββ Thermogram Colony
ββ llm_clusters.thermo β syncs neuromod
ββ dialogue_patterns.thermo β syncs neuromod
ββ trust_graph.thermo β independent
ββ code_knowledge.thermo β independent
// Dopamine spike in Astromind β all synced Thermograms increase learning rate
// Stress β all synced Thermograms increase decay, prune weak connections
```
## Installation
Add to your `Cargo.toml`:
```toml
[dependencies]
thermogram = "0.1"
```
Or with optional Engram integration:
```toml
[dependencies]
thermogram = { version = "0.1", features = ["engram-export"] }
```
## Usage
### Basic Example
```rust
use thermogram::{Thermogram, PlasticityRule, Delta};
// Create Thermogram for LLM activation clusters
let mut thermo = Thermogram::new("llm_clusters", PlasticityRule::stdp_like());
// Apply delta (e.g., cluster centroid update from LLM mining)
let new_centroid = vec![0.5_f32; 2048];
let delta = Delta::update(
"cluster_0",
bincode::serialize(&new_centroid)?,
"llm_mining",
0.8, // strength
thermo.dirty_chain.head_hash.clone(),
);
thermo.apply_delta(delta)?;
// Read current state (dirty + clean merged)
let cluster = thermo.read("cluster_0")?;
// Manual consolidation (or auto-trigger after N deltas)
let result = thermo.consolidate()?;
println!("Consolidated {} entries", result.entries_consolidated);
// Save to disk (hot file)
thermo.save("data/llm_clusters.thermo")?;
// Export to JSON
thermo.export_to_json("exports/llm_knowledge_v1.json")?;
```
### With Embedded SNN Plasticity
```rust
use thermogram::{EmbeddedSNN, EmbeddedSNNConfig, NeuromodState, PlasticityEngine};
// Create SNN plasticity engine
let config = EmbeddedSNNConfig::default(); // 100 neurons
let mut snn = EmbeddedSNN::new(config);
// Process activation from LLM layer
let activation = vec![0.5; 2048]; // From layer 16 hidden state
let neuromod = NeuromodState::baseline();
// SNN generates deltas via plasticity rules:
// - STDP strengthens co-firing neurons
// - Homeostasis prevents runaway
// - Competition enforces sparsity
// - Decay prunes weak connections
let deltas = snn.process(&activation, &neuromod)?;
// Apply deltas to Thermogram
for delta in deltas {
thermo.apply_delta(delta)?;
}
```
### Colony with Neuromod Sync
```rust
use thermogram::{EmbeddedSNN, EmbeddedSNNConfig, NeuromodState, NeuromodSyncConfig, PlasticityEngine};
// Central neuromodulation state (from Astromind)
let mut central_neuromod = NeuromodState::baseline();
// SNN 1: Full sync with central state
let config1 = EmbeddedSNNConfig::default();
let mut snn1 = EmbeddedSNN::new(config1);
// SNN 2: Independent (sync_rate = 0.0)
let config2 = EmbeddedSNNConfig::default();
let mut snn2 = EmbeddedSNN::new(config2);
// Reward signal β increase dopamine
central_neuromod.reward(0.3);
// Sync to colony
snn1.sync_neuromod(¢ral_neuromod); // Picks up dopamine spike
// snn2 runs independently with NeuromodState::baseline()
// Process activations with synchronized neuromod
let activation = vec![0.5; 2048];
let deltas1 = snn1.process(&activation, ¢ral_neuromod)?; // Uses synced state
let deltas2 = snn2.process(&activation, &NeuromodState::baseline())?; // Independent
```
## Key Features
### 1. Plastic Memory with Audit Trail
- Every change is a **rule-governed delta** (not arbitrary overwrites)
- Hash-chained for tamper evidence
- Can replay full history to verify integrity
### 2. Brain-Like Plasticity
- **STDP**: Cells that fire together wire together
- **Homeostasis**: Prevent runaway strengthening
- **Competition**: Winner-take-most (enforces sparsity)
- **Decay**: Natural forgetting of unused connections
- **Gating**: Context-dependent activation
### 3. Hot File Format
- Lives on disk as active, processable file
- Can be opened, processed, consolidated, closed
- ThermogramManager handles colony lifecycle
- Automatic consolidation triggers
### 4. Scalable Colonies
- Each Thermogram specializes in a domain
- Independent or synchronized neuromodulation
- Add new Thermograms without touching existing ones
- Colony can scale to hundreds of specialized memories
### 5. Archive Without Deletion
- Export to Engram (immutable) when saturated
- Keep full learning history
- Never lose the "why" and "how"
- Cold storage for non-active knowledge
## Architecture Decisions
See `engineering/` for detailed design rationale:
- **Colony architecture**: Independent organisms with optional chemical sync
- **Embedded SNN**: Why spiking dynamics instead of backprop
- **Dual state**: Why dirty/clean instead of single mutable state
- **Hash chains**: Why cryptographic audit trail matters
- **Plasticity rules**: How STDP/homeostasis/competition interact
## Performance
**CPU-only, production-ready** β‘
| **Read** | 17-59ns | 17M+ ops/sec |
| **Write (delta)** | 660ns | 1.5M ops/sec |
| **Consolidation** | 17Β΅s (1000 deltas) | 60K/sec |
| **SNN tick** | 151Β΅s (100 neurons) | 6.6K/sec |
| **Neuromod sync** | 4ns | 244M/sec |
- **No GPU required** - Pure Rust, runs anywhere
- **Low memory** - 1-10MB per Thermogram
- **Edge-friendly** - Suitable for embedded/offline deployments
See [PERFORMANCE.md](PERFORMANCE.md) for comprehensive benchmarks and scaling analysis.
## Testing & Security
**60/60 tests passing** β
- **36 unit tests** - Core functionality
- **15 adversarial tests** - Hash tampering, invalid chains, corrupted deltas, fork attacks, NaN/Inf protection
- **8 concurrency tests** - Thread safety, race conditions, state isolation
- **1 doc test** - API correctness
**Security verified:**
- β
SHA-256 hash-chained audit trail
- β
Tamper detection at every delta link
- β
Fork attack prevention
- β
Corruption detection through hash recomputation
- β
NaN/Inf protection in SNN
See [HARDENING_SUMMARY.md](HARDENING_SUMMARY.md) for complete testing report.
## Status
**v0.1.0 - Production Ready** π
- β
Core delta/hash chain/consolidation
- β
Embedded SNN with STDP/homeostasis/competition/decay
- β
Neuromodulation with optional sync
- β
Save/load to disk
- β
JSON export
- β
**Comprehensive testing** (60/60 passing)
- β
**Benchmarked** (8 benchmark suites)
- β
**Security verified** (adversarial testing)
- β
**Performance documented** (see PERFORMANCE.md)
- π§ ThermogramManager (colony lifecycle)
- π§ Engram export (requires engram-rs integration)
- π§ Astromind integration (next phase)
## Next Steps
1. **Astromind Integration** - Wire into LLM activation mining pipeline
2. **ThermogramManager** - Manage colony lifecycle, auto-consolidation triggers
3. **Engram Export** - Consolidate to immutable archive format
4. **Real-world testing** - Use for actual LLM knowledge extraction on Qwen-2.5-3B
## License
MIT OR Apache-2.0