ENGRAM: KV Cache Fingerprinting Protocol
You Don't Need Adapters: Cross-Model Document Retrieval via Intrinsic KV Cache Geometry
ENGRAM extracts Fourier fingerprints from LLM KV caches, stores them as compact binary certificates (.eng files, ~800 bytes), and retrieves them via HNSW approximate nearest neighbor search. This enables persistent cross-session memory for large language models with zero training.
Key Results
Metric Value Recall@1 (N=200) 100.0% (post Stage-4)Raw Fourier recall 98.0% (f0+f1 DFT)HNSW search latency 51.8 us HNSW speedup 5.7x vs brute-forceCross-model transfer +0.124 margin (FCDB, no adapter)CKA isomorphism 0.975 within-family, 0.927 cross-familyCertificate size ~800 bytes per documentArchitectures llama, gemma, gemma4/ISWA, phi, qwen, mistral Tests 220 passing
How It Works
KV cache blob --> layer key extraction --> DFT(f0+f1) --> fingerprint (~800 bytes)
|
Query fingerprint --> HNSW search --> geodesic retrieval --> matched session/document
The Fourier Fingerprint
ENGRAM decomposes per-layer key trajectories using a 2-component DFT:
f0 (DC component): captures the mean activation level per layer
f1 (first harmonic): captures the dominant oscillation pattern
The resulting fingerprint is a compact, deterministic signature of the KV cache state that is:
Model-intrinsic : derived from the model's own geometry, not learned embeddings
Cross-model transferable : via Frechet Cross-Domain Bridge (FCDB)
Compression-robust : 0.99998 cosine similarity after INT8 quantization
4-Stage Geodesic Retrieval
Stage 0: Prior preemption (IndexC chronic failure -> skip HNSW)
Stage 1: HNSW search -> HIGH / MEDIUM confidence
Stage 2: Trajectory correction -> MEDIUM (interpolation w=0.3)
Stage 3: Negative constraints -> LOW (apophatic layer)
Stage 4: Metadata disambig -> LOW + stage4_used=True
Install
1 # Python (core library)
2 pip install engram-kv
3
4 # Node.js (MCP client)
5 npm install engram-kv-mcp
From source
1 git clone https://github.com/infraax/engram.git
2 cd engram
3 python3 -m venv .venv && source .venv/bin/activate
4 pip install -e ".[dev]"
5
6 # Run tests
7 KMP_DUPLICATE_LIB_OK = TRUE OMP_NUM_THREADS = 1 PYTHONPATH = . pytest tests/ -x -q
Architecture Support
Architecture Attention Type Status Llama (1B-70B) Standard MHA Fully supported Gemma (2B-27B) Standard MHA Fully supported Gemma 4 (26B) ISWA (sliding + global) Fully supported Phi (3.8B) Standard MHA Fully supported Qwen (1.8B-72B) GQA Fully supported Mistral (7B) GQA + sliding window Fully supported
Cross-Model Transfer
9 strategies evaluated. FCDB (Frechet Cross-Domain Bridge) wins:
Strategy Margin Method FCDB +0.124 Frechet mean of cross-model fingerprints TruncAlign +0.098 Truncate to min shared layers ZeroPad +0.067 Pad shorter fingerprint with zeros SpectralInterp +0.045 Interpolate in frequency domain
No adapter training required. The geometry is intrinsic.
MCP Server (Claude Code Integration)
ENGRAM includes an MCP server for persistent session memory in Claude Code:
1 claude mcp add --global engram-memory \
2 -e ENGRAM_SESSIONS_DIR =~ /.engram/sessions \
3 -- python3 mcp/engram_memory.py
7 tools : write_session_engram, get_last_session, retrieve_relevant_sessions, get_relevant_context, list_indexed, index_knowledge
EIGENGRAM Binary Format (v1.2)
Compact, versioned binary certificates:
Header: magic(4B) + version(2B) + flags(2B) + dimensions
Vectors: vec_perdoc + vec_fcdb + joint_center + vec_fourier + vec_fourier_v2
Meta: corpus_hash + model_id + metrics + task_description
~800 bytes per document. Deterministic encoding. Cross-platform portable.
Theoretical Contributions
Margin Power Law : margin ~ A * N^alpha where alpha = -0.207 (graceful degradation, no cliff)
CKA Manifold Isomorphism : within-family 0.975, cross-family 0.927 (geometry is intrinsic)
Frequency Ablation : f0+f1 is the sweet spot (f0-only: -23% recall, f0+f1+f2: -0.3% margin)
FCDB Scaling Law : cross-model recall drops from 100% (N<=20) to 0% (N=200) -- adapter-free has limits
Citation
1 @article{enigma2026engram,
2 title={You Don't Need Adapters: Cross-Model Document Retrieval
3 via Intrinsic KV Cache Geometry},
4 author={ENIGMA},
5 year={2026},
6 url={https://github.com/infraax/engram}
7 }
Links
License
Apache-2.0