core/ingest/gate.py

38 lines
1.2 KiB
Python

"""
The single injection gate.
The ONLY point where raw data enters the versor manifold.
normalize_to_versor() is called here and nowhere else in production code.
Contract:
Input: raw token sequence + VocabManifold
Output: FieldState with F satisfying versor_condition(F) < 1e-6
"""
from algebra.versor import normalize_to_versor, versor_condition
from algebra.holonomy import holonomy_encode
from field.state import FieldState
def inject(tokens: list, vocab) -> FieldState:
"""
Encode a token sequence and inject into the versor manifold.
Steps:
1. Look up each token's versor in the vocab manifold
2. Encode via holonomy walk
3. Normalize to versor (the single allowed normalization call)
4. Assert versor condition before returning
"""
word_versors = [vocab.get_versor(t) for t in tokens]
H = holonomy_encode(word_versors)
F = normalize_to_versor(H)
cond = versor_condition(F)
if cond > 1e-5:
raise RuntimeError(
f"Injection produced non-versor field: condition={cond:.2e}. "
"Check holonomy_encode() and normalize_to_versor()."
)
return FieldState(F=F, node=0, step=0)