Expand description
Format v2 “knowledge without forgetting” (spec §9.2–§9.5): a FROZEN genome, skill records v2 that own their tensors over it, and the backbone-gated router policy.
Three required_features bits carry the semantics, each DERIVED by the
writers from header content and checked both ways on open:
GENOME⇔header.genome— the reader recomputestrunk_hashfrom the directory and refuses a file whose trunk changed without a new genome;SKILLS_V2⇔ someskills[i].kind— every v2 record is validated against the genome it is bound to and against the directory;ROUTER_V2⇔header.router— only the declaredbackbone_gatedpolicy may auto-route; the legacy argmin-of-skills is not a fallback.
Everything here is pure metadata logic (no I/O): format.rs calls
validate_knowledge from open(), from every writer and from the
tail append, so a file the writer produced is a file the reader accepts.
Modules§
- expert_
leaf - Per-expert tensor leaves of an MoE layer
(
model.layers.{l}.mlp.experts.{e}.{leaf}), in the order a record lists them. - lookup_
leaf - Tensor leaves of a lookup record (
skill.{id}.+ leaf). - lookup_
policy - Values of
LookupInfo.policy(spec §9.5.2). - skill_
kind - Skill-record kinds (
SkillRecord.kind). - state_
switch StateEffect.switchvalues.
Structs§
- Exec
Hashes - hash64 of the execution-relevant sections outside the directory: the
DTG-MA mask catalog and the sparse index derived from it (
None= the section is absent). - Expert
Append - Parameters of a
kind = "expert_append"record (SkillRecord.experts):countnew experts in EACH ofSkillRecord.layers(the grown MoE layers, any non-empty subset), appended after the experts already present in that layer. The per-layer index of the new experts is not stored — the reader computes it (expert_append_base). - Expert
Tensor Spec - One tensor an
expert_appendrecord carries. - Genome
Info - The frozen genome the file carries (
header.genome, bitGENOME). - Genome
Parent - Lineage
Event - One journal entry (
header.lineage):birth|skill_committed|skill_retired|requant|recalibrate|compact|rollback.seqis strictly increasing. - Lookup
Info - Parameters of a
kind = "lookup"record (SkillRecord.lookup, spec §9.5.2):entriescards, each with one text slot per language oflangs(slotentry · L + lang), reached throughkeysnormalised, hashed keys. The table itself is the four tensors oflookup_leaf; a lookup record has nooverrides, noexperts, nolayersand the transparentlookup_state_effect— it never touches the network. - PhiSpec
- Canonical φ(q) of a user message q:
ids = prefix_ids ++ encode(q) ++ suffix_ids(encode without BOS or special handling), run the backbone throughlayer, take the hidden AFTER that layer, mean over the positions ofencode(q)only (span_mean), unit-normalize (unit). - Router
Policy header.router(bitROUTER_V2): the per-request backbone-gated policy. The backbone is the default; a skill runs only when the calibrated decision says so (cortiq-enginerouter::decide_backbone_gated).- Segment
- Data-range ownership after tail appends (
header.segments). Offsets are relative todata_off, like directory offsets. A full rewrite is a compaction and clears the table. - Skill
Bound - The genome a v2 skill is bound to.
- Skill
Override - A base tensor a v2 skill replaces.
- State
Effect - What switching this skill does to the O(1) sequence state.
Constants§
- BACKBONE_
CLASS_ ID - Row id of the backbone class in router-v2 decisions. No skill may use it.
- GENOME_
STATUSES genome.statusvalues.- KEY_
NORM - The key normalisation a
lookuprecord declares (LookupInfo.key_norm):KEY_NORM_V2,normalize_key. This reader knows exactly one. - KEY_
NORM_ V1 - The pre-release key normalisation (NFC → lowercase → every
non-alphanumeric char → space): it split a word at a combining stress
mark or a soft hyphen (
Рома́шка→рома шка) and kept Latin diacritics (Pínus≠Pinus). No table was released under it; this reader refuses the id with a rebuild hint. - KEY_
NORM_ V2 cmf-key-v2:normalize_key— the rule every table is built and read with. A new rule is a new id, never a silent change.- KNOWLEDGE_
BITS - Knowledge bits (all three are derived from content).
- LOOKUP_
MAX_ NGRAM - Longest key the runtime can match, in words of the normalised form:
the user message is searched as n-grams of
1..=LOOKUP_MAX_NGRAMwords (cortiq_engine::lookup::MAX_NGRAMis this value), so the builder drops a longer key as unreachable instead of storing it. - METRIC_
MSE_ UNIT - The metric every router-v2 descriptor uses (unit-normalized φ).
- RESERVED_
SKILL_ IDS - Ids a v2 skill may not take: the CLI and the route reports spell the
backbone and the automatic decision with them (
--skill none,--route backbone|auto,target: "backbone"), so a skill with such an id would be unreachable or indistinguishable from the backbone. - SEGMENT_
KINDS segments[i].kindvalues.- SKILL_
STATUSES skills[i].statusvalues (v2 records).
Functions§
- canonical_
json - Canonical JSON bytes of a value: object keys sorted bytewise at every
depth, no whitespace. Independent of map insertion order and of
serde_json’s
preserve_orderfeature (which the engine enables and a core-only build does not). - check_
lookup_ policies - The writers’ rule: every lookup record’s
lookup.policy, when present, is one this writer knows —append_skill,update_header_appendand the full writers refuse anything else before a byte is written (open()only warns,unknown_lookup_policies). - expert_
append_ base - First expert index the
expert_appendrecord at positionatofheader.skillsowns inlayer— the per-layer chain rule:E0 + Σ countof the expert_append records BEFOREatthat growlayer. Its experts arebase + k,k in 0..count; a layer the record does not grow keeps its experts.at == header.skills.len()plans a record about to be appended. - expert_
append_ layout - Every tensor (name and shape) the
expert_appendrecordrecordmust carry when it sits at positionatofheader.skills— exactly these, no others: per grown layerlandk in 0..count, experte = expert_append_base(l) + k:gate_proj.weight,up_proj.weight,down_proj.weightshaped like the trunk’s expert 0 ofl,desc.mu [hidden],desc.ushaped like the trunk’s expert 0desc.u(absent whenrank == 0),desc.bias [1]anddesc.shell [1](both f32). - expert_
append_ state_ effect - The state effect of an
expert_appendrecord: the grown experts are part of the organism from the first grown layer on and are never switched, sosequence_start(the least permissive) and no state added. - expert_
append_ tensor_ name skill.{id}.model.layers.{layer}.mlp.experts.{expert}.{leaf}.- expert_
tensor_ name model.layers.{layer}.mlp.experts.{expert}.{leaf}— a trunk expert tensor; a record’s copy isskill.{id}.+ this (expert_append_tensor_name).- f32_
le_ head - First f32 (LE) of a payload.
- ffn_
replace_ state_ effect - The state effect of replacing the FFN of
layers, computed by the WRITER fromarch.layer_types: the FFN output of layer l feeds every layer j > l, so switching istransparentiff no layer aftermin(layers)carries sequence state (and the stack is not looped — a loop feeds layer l back into layer 0). The MTP head is not counted: its state only steers drafts that the main model verifies. - genome_
moe_ experts E0of a genome:genome.moe_experts, or — on a file written before the field existed —arch.moe.num_expertsof a resonance-routed MoE (the value the writer would fill). Errors: no genome, or the genome is not a resonance-routed MoE (a gated MoE cannot take appended experts: its gate tensor fixesE).- hex64
{:016x}of a hash64.- is_
trunk_ tensor - Is this directory entry part of the trunk (not a skill or router tensor)?
- key_
hash - hash64 of
normalize_key(key)— the value stored inkeys.hash. - knowledge_
bits - The knowledge bits this header’s content requires.
- layer_
type_ is_ stateful - Does this layer type carry sequence state (KV, ring, recurrent)? Exhaustive on purpose: a new operator must decide here.
- lookup_
state_ effect - The state effect of a lookup record: it never touches the network, so
first_affected_layer 0,transparent, no state added — and the validator requires exactly this. - lookup_
tensor_ name skill.{id}.{leaf}for one oflookup_leaf.- lookup_
tensors - The four tensors of the lookup record
idfrom hashed keys and slot texts:keys=(key_hash, entry)in any order,slots[entry · L + lang]= the JSON object text of that card in that language (E · Lof them,L = info.langs.len()). Sorts the keys by hash and refuses a duplicate hash (two keys that normalise alike — the builder drops and reports them BEFORE calling this), an entry≥ E, a key count or slot count that disagrees withinfo, a slot that is not a JSON object. What comes back passes the record validation by construction. - moe_
layers - The layers whose trunk carries expert tensors
(
model.layers.{l}.mlp.experts.0.gate_proj.weight), ascending — the layers anexpert_appendrecord may grow (the trainer’s default: all). - normalize_
key cmf-key-v2(KEY_NORM): NFC → every combining mark and every invisible format character is dropped WITHOUT ending the word (a stress mark over a Cyrillic vowel has no precomposed form, so NFC leaves U+0301 standing:Рома́шка→ромашка; soft hyphen, zero-width space / joiner / non-joiner, word joiner, BOM:ромашка→ромашка) → a precomposed LATIN letter loses its diacritics (Pínus→pinus,école→ecole; a Cyrillic letter keeps its mark —й,ё,ўare letters, not accents) → lowercase → every other char that is not alphanumeric (Unicode) becomes a space → runs of spaces collapse → trim. Shared by the builder (keys) and the runtime (n-grams of the user message), sonormalize_key("Пихта бальзамическая (Abies balsamea)")=="пихта бальзамическая abies balsamea". Idempotent.- normalized_
key_ hash - hash64 of the UTF-8 bytes of an ALREADY normalised key (the runtime normalises the whole message once and hashes its n-grams).
- parse_
hex64 - Parse a hex hash64 (as written by
hex64). - read_
u32_ le - Little-endian
u32words of a raw payload (u32tensors). - read_
u64_ le - Little-endian
u64words of a raw payload (u64tensors). - trunk_
expert_ rank - Rank of the trunk’s expert 0 descriptor subspace in
layer(experts.0.desc.uelements /hidden_size), 0 when the trunk has nodesc.uthere. Errors:layeris not an MoE layer of the trunk, or it has no per-expert descriptors (experts.0.desc.mu) — the legacy stackedmlp.desc.*form cannot be grown per expert. - trunk_
hash - hash64 of the genome’s trunk. Input, in order:
- trunk_
hash_ exec trunk_hashwith the mask / sparse-index sections (NF-1): when the file carries either,0x1e b"exec" 0x00+ per section (tag u8 + hash64 LE) is appended to the hash input. A file with neither hashes exactly astrunk_hash(so genomes born without masks keep their hash), and a mask catalog added to a genome later changes the trunk hash — the reader refuses it unless it is a new genome.- trunk_
hash_ json trunk_hashover the rawarch/tokenizer_configJSON values of a header (Value::Nullfor an absent bundle) — the reader’s form.- trunk_
hash_ json_ exec trunk_hash_jsonwith the mask / sparse-index sections (trunk_hash_exec).- unknown_
lookup_ policies (skill id, value)of every lookup record whoselookup.policythis reader does not know (lookup_policy::ALL).open()accepts such a file and warns; the runtime reads the record aslookup_policy::DEFAULT— the conservative reading, the one a reader from before the field existed applies (review KF-6).- utc_
now_ rfc3339 - Current UTC time as RFC 3339 (
YYYY-MM-DDTHH:MM:SSZ), no dependency. - validate_
expert_ append_ values - The value rules of
expert_appenddescriptors, which the directory cannot express: everydesc.biasis finite (the trainer freezes it — 0.0 or the source’s balancing bias,origin.bias_mode; NaN/inf would buy or lose every token) and everydesc.shellis finite (+inf would mean “no shell”, NaN would never fire).f32_ofyields the first f32 of an entry’s payload (None= not available → refused). Called byopen()(mmap) and by every writer (the payload it writes) aftervalidate_knowledge, which fixed the dtype to f32. - validate_
knowledge - Every knowledge rule (§9.2–§9.5) over a header + directory: the bits ⇔
content in both directions, the genome’s trunk hash, the lineage order,
segment bounds, every v2 skill record and the router policy. Called by
open()(with the envelope’s bits) and by every writer before a byte is written. Files carrying none of the new bits and no v2 content pass untouched. - validate_
lookup_ values - The value rules of lookup tables, which the directory cannot express:
keys.hashstrictly ascending (sorted, unique — the runtime binary-searches it), everykeys.entry < E,entries.offmonotone and within the blob, the blob valid UTF-8 with every slot boundary on a character boundary, every slot shaped as a JSON object (first non-blank byte{, last}). Withdeepevery slot is also parsed as JSON: what a WRITER does with the payload it is about to commit;open()passesfalse— the runtime reads a slot lazily and reports a slot that does not parse at that request, so parsing every card of a table of hundreds of MB on every open of the file would only cost time.bytes_ofyields an entry’s payload (None= not available → refused). Called aftervalidate_knowledge, which fixed dtypes and shapes. One pass over the table: O(K + N).