Once the Transformer encoder produces an L2-normalized embedding for a user, Neural Vault converts it into a deterministic 256-bit cryptographic key. The derivation pipeline has three stages: quantization of the continuous-valued embedding to a reproducible integer representation, serialization to raw bytes that serve as HKDF input keying material, and key stretching via HKDF-SHA256 with a domain-specificDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Skieriya/fMRI-key-generation-with-TRIBEv2/llms.txt
Use this file to discover all available pages before exploring further.
info string. The same embedding always produces the same key — identity is the entropy source, not randomness.
derive_key — main.py
The production version in main.py gracefully handles environments where the cryptography package is unavailable, falling back to a raw hashlib.sha256 digest:
derive_key — model.py
The model.py variant assumes the cryptography package is always present (it is listed as a required dependency) and omits the fallback branch:
cryptography package is installed.
Step-by-Step Derivation
Step 1 — Quantize to int16
NeuralVaultFewShot.forward is L2-normalized and lies on the unit hypersphere, so each component is a float in [-1.0, 1.0]. Multiplying by 1000 maps this range to [-1000, 1000], well within the int16 range of [-32768, 32767]. The scale factor of 1000 preserves three decimal places of precision — enough to distinguish embeddings while discarding floating-point noise below the millisecond threshold that would destabilize key reproduction across inference runs.
Step 2 — Serialize to bytes (IKM)
np.ndarray.tobytes() serializes the int16 array to a raw byte sequence in native memory order. For a latent_dim=128 embedding, this produces 128 × 2 = 256 bytes of Input Keying Material (IKM) passed into HKDF.
Step 3 — HKDF-SHA256
- Extract —
HMAC-SHA256(salt, IKM)compresses the input bytes into a pseudorandom key. Withsalt=None, the RFC specifies a zero-filled salt ofHashLenbytes. - Expand — iteratively applies
HMAC-SHA256with theinfocontext string to produce the requested output length.
info parameter b"neural-vault-few-shot-v1" domain-separates this derivation from any other HKDF usage in the same application. If the system is updated with a new model version, bumping the info string to b"neural-vault-few-shot-v2" produces completely different keys from the same embeddings, preventing cross-version key collisions.
Step 4 — Fallback (no cryptography)
cryptography package is absent, a single SHA-256 hash of the IKM is used. This loses HKDF’s domain separation and extract-then-expand structure but retains the core determinism property for environments where installing additional dependencies is not possible.
Class Prototype Computation
Keys are derived from class prototype vectors rather than from individual sample embeddings. A prototype is the centroid of all embeddings belonging to one class:Benchmark Prototype Keys
Running the full pipeline on5classpreds.csv produces the following 256-bit prototype keys (hex-encoded):
| Class | Key (hex) |
|---|---|
| 0 | 1eaa2877f253315cecb77828e30f707d8fe381b07ba83851725c84a2e240c69b |
| 1 | 5f4da41c3524a593bd6a9cec804a75e2167b33aa324c1d73daa2479adbd2eef4 |
Avalanche Effect
A cryptographic key derivation function should exhibit the avalanche property: a small perturbation to the input should change approximately 50% of the output bits. Neural Vault’s derivation chain satisfies this because HKDF’s SHA-256 backbone has strong avalanche characteristics. From themodel.py benchmark section:
0.05 to a single component of the prototype vector — a perturbation spanning 50 quantization steps (one step = 0.001) — causes approximately 50% of the 256 output bits to flip. This confirms that the key output has no exploitable correlation with small embedding perturbations.