Expand description
lookup records at run time (CMF_V2_SPEC §9.5.2; the lookup spec §3):
an explicit key → card table appended to a sealed genome, reached
through the request-level resonance router.
LookupTable— the four tensorsskill.{id}.lookup.*of one record as the runtime reads them: sorted key hashes (binary search), entry per key, slot offsets, and the UTF-8 card blob left in the file’s mapping (zero-copy).extract_key— O(len) key extraction from a user message: a Latin binomial in parentheses (the innermost group first), then a capitalisedGenus speciespair anywhere in the ORIGINAL message (capitalised_binomials), then every 1..=MAX_NGRAM-word n-gram of thecmf-key-v2-normalised message against the exact key index (the longest match wins, ties → the first occurrence), then the same n-grams STEMMED (stem_key: a light, deterministic Russian / English suffix stripper) against the table’sStemIndex. A STRONG candidate (is_strong_key: ≥ 2 real words, no digits) wins over any weak one, in every path — the router’s pick,key_first, the conversation memory; without one, the first weak candidate (a weak stem only when nothing matched exactly). The file stores only key hashes, so the stem index is built at open from the key texts the cards themselves spell (recover_key_texts): no format change.LookupTable::find_answer_turns— conversation memory: the key is taken from the most recent of up toMEMORY_TURNSuser turns that holds one; the field and the language come from the LAST turn.select_field/pick_lang— the card field the question asks for (keyword rules) and the language of the answer (script).LookupMode—answer(the table answers, no generation),context(the card — or, when a field was selected, its first sentence plus that field — is prepended to the message and the backbone generates),off(the table is ignored); flag orCMF_LOOKUP_MODE.resolve_lookup— the one step every caller shares: aRouteDecisionwhose target is a lookup record becomes the lookup outcome; no key in the message, an empty card in every language, or modeoffsends the request to the BACKBONE unchanged. A lookup record never has a lane of its own: the backbone pipeline — the same object F0 runs — serves it, so the logits of every non-hit request are bit-identical to F0’s.LookupPolicy/resolve_lookup_gated— the record’s routing policy (LookupInfo.policy):router_and_key(the default) looks a key up only in what the φ router sent;key_firstlets a STRONG key of the message (is_strong_key) take a request the router sent to the backbone — only on a file whose router could pick a skill at all (no fail-closed state). A one-word key (чай,мята) still needs the router; a message without a strong key keeps the router’s decision untouched. An unknown policy value reads asrouter_and_key.
Structs§
- Card
- One slot of the text blob:
{"card": "...", "fields": {name: text}}. - KeyFirst
Gate - What the
key_firstpolicy needs to take a decision (resolve_lookup_gated): that the decision was the ROUTER’s own (a caller that pinned the target passes no gate —--route backbone,--skill noneand a forced record are never overridden) and the conditions the router’s own pick of the record would have met. - KeyHit
- A key found in a user message.
- Lookup
Answer - What the table answered.
- Lookup
Table - One mounted lookup record.
- Lookup
Tables - The lookup tables of a file, opened on first use and kept
(
Sync:serveshares one behind its router). - Stem
Index - The second, sorted hash index of a table: hashes of the STEMMED key
texts (
stem_key), each mapped to its entry. A stem two keys of DIFFERENT entries share is ambiguous and is left out (ambiguous); the same stem from several keys of one entry (ромашка аптечная,ромашки аптечной) is one row. Consulted only when the exact index finds nothing.
Enums§
- Decided
By - Who sent a request to a lookup record —
decided_byin the route summary. - Found
LookupTable::find_answer: what the table found for a message.- KeySource
- Where a key hit came from.
- Lookup
Mode - What a request routed to a lookup record does with the card.
- Lookup
Outcome - What a routed request does once its target is known.
- Lookup
Policy - How a request reaches a lookup record (
LookupInfo.policy, spec §9.5.2). - Match
Via - Which index answered: the exact
cmf-key-v2hashes (primary), or the stem index (StemIndex, consulted only when the primary found nothing). Reported aslookup_matchin the route summary.
Constants§
- CONTEXT_
HEADER - The header line of a
context-mode prompt. - EN_
STEM_ MIN - An English stem keeps at least this many letters.
- FIELDS
- The card fields
select_fieldcan name, in rule order (the first rule that matches wins): the specific ones beforeuses, which almost every question mentions in passing (safe to use,parts used,in what form is it used). - FIRST_
SENTENCE_ MAX Card::first_sentence: the cap when the card has no terminator.- FIRST_
SENTENCE_ MIN Card::first_sentence: a terminator this early is an abbreviation.- LATIN_
STEM_ MIN_ WORD - A Latin-script word shorter than this is never stemmed (
sage,uses,wort,Pinusstay as they are). - LOOKUP_
MODE_ ENV - Environment default of
LookupMode(answer|context|off). - MAX_
NGRAM - Longest n-gram (in words of the normalised message) tried as a key —
LOOKUP_MAX_NGRAMof the core, the number the builder drops longer keys by. - MEMORY_
TURNS - Conversation memory of
serve(LookupTable::find_answer_turns): the key is searched in the last user message and up to this many user turns in total, most recent first. - RU_
STEM_ MIN - A Russian stem keeps at least this many letters (
чай,вид,дубare never shortened). - RU_
SUFFIXES - Russian inflectional endings
stem_wordstrips, longest first (adjective and noun endings of every case and number;йandьso thatзверобой/зверобояandполынь/полыниmeet). - STEM_
UNIGRAM_ MIN - A ONE-word stem candidate shorter than this (in letters) is not looked
up:
виды→вид,чая→чаяnever match by stem. Exact one-word matches are unaffected. - STRONG_
KEY_ MIN_ WORDS - A strong key has at least this many words of ≥
STRONG_WORD_MIN_LETTERSletters (is_strong_key_text). - STRONG_
WORD_ MIN_ LETTERS - Letters a word needs to count towards
STRONG_KEY_MIN_WORDS(st,s,b,pbnever do).
Functions§
- capitalised_
binomials - Every
Genus speciespair of the ORIGINAL (case-kept) message, in order: a capitalised Latin word of ≥ 3 letters followed by a lowercase Latin word of ≥ 3 letters, optionally hyphenated (nux-vomica: ≥ 3 and ≥ 2 letters around the hyphen); punctuation around the words is ignored ((Abies balsamea)?). The pairs are tried as EXACT keys only, before the n-grams; a genus alone is never tried (ambiguous). A capitalised English pair (What plant) is a candidate too — harmless, it is a key or it is not. - context_
excerpt - The text
contextmode prepends for a card: the whole card when no field was selected; otherwise its first sentence and the field as{label}: {text}— a short excerpt that keeps the fact next to the question. A bounded-attention genome (swa_sink, window 128) would otherwise see the family line of a 1 000-char card hundreds of tokens before the question, beyond its window. - context_
prompt - The user message the backbone generates from in
contextmode. - extract_
key extract_key_withagainst the exact index only (no stem index).- extract_
key_ with - The key of
message, O(len): the STRONGEST key when the message holds one (extract_strong_key_with), else the first key of any strength. One rule for every path — the φ router’s pick of a table, thekey_firstpolicy and the conversation memory resolve one message to one entry (review KF-3:чай из ромашки аптечнойis chamomile whoever decided, not tea on the router’s path and chamomile on key_first’s). - extract_
strong_ key_ with - The STRONGEST key of
messagefor thekey_firstpolicy: the same search asextract_key_with(the parenthesised group, the capitalised binomial, the exact n-grams, then the stem n-grams) over strong candidates only (is_strong_key_text) — so a one-word exact key never hides a two-word stem key of the same message (чай из ромашки аптечной).None= no strong key; the result always passesis_strong_key. - field_
label - The human label of a card field in the slot language (
contextmode writes{label}: {text}); an unknown field or language keeps the field name. - has_
cyrillic - Any Cyrillic letter in
s. - is_
strong_ key - Is
hita STRONG key — one thekey_firstpolicy acts on without the router, and one every search prefers over a weak key of the same message? Its text passesis_strong_key_text, whatever its source: an exact or stem n-gram of ≥ 2 real words (ромашки аптечной,pot marigold), a parenthesised Latin group, a capitalisedGenus speciespair. The source does not make a key strong: every exact key a capitalised pair finds is the same text as an n-gram of the message, so a pair rule stricter than the n-gram rule would protect nothing (Common boxinWhy is Common box cutter so popular?is the n-gram keycommon boxtoo — only a stop list removes it) and would only reorder candidates (a binomial the cards spell over the common name typed first:Spring vetchling (Lathyrus vernus (L.) Bernh.)would then answer from a stub entry of the corpus). A one-word key —чай,мята,календулы, a lone(Calendula)— never is strong: such words occur in general chat, and only the router’s decision may send them to a table. - is_
strong_ key_ text - Is the normalised key text
normSTRONG — a name thekey_firstpolicy may act on without the router (review KF-5)? No word with a digit (sts 135,pti 2,a 41988,5f pb 22), and at leastSTRONG_KEY_MIN_WORDSpurely alphabetic words of ≥STRONG_WORD_MIN_LETTERSletters (ромашки аптечной,pot marigold,st john s wort; notthc b, notчай). A general phrase that happens to be a plant’s common name (scrambled eggs,gas plant,live forever) passes this rule — only the builder’s general probe and a stop list remove such a key (lookup-build --general-prompts,--drop-keys). - pick_
lang - The slot language of the answer:
rufor a Cyrillic question, elseen; a language the record lacks falls back toen, then to the record’s first language. Returns the index intolangs. - recover_
key_ texts - The key texts a table’s cards spell — the file stores only key hashes,
so this is where the stem index gets its words from: every
1..=
MAX_NGRAM-word n-gram of every slot’s text (the raw JSON of the card and its fields) whose hash the exact index knows, once per key, with the entry the INDEX maps it to (a card that mentions another entry’s plant recovers that plant’s key correctly). A key no card spells — a synonym only the corpus knew — is not recovered and has no stem; the exact index still serves it. O(blob) at open. - resolve_
lookup - The lookup step after the routing decision: a target that is a lookup
record becomes its outcome under
mode. No key (or modeoff) turns the decision into the BACKBONE with the reason kept; a hit keeps the skill target and notes the key. Any other target passes through asLookupOutcome::NotLookup. One user message, no memory. The decision is taken as given — thekey_firstpolicy needs to know how it was made (resolve_lookup_gated). - resolve_
lookup_ gated resolve_lookup_turnswith the records’ routing policy.key_firstisSomewhendecisionis the router’s own (seeKeyFirstGate).- resolve_
lookup_ turns resolve_lookupwith conversation memory:turnsasLookupTable::find_answer_turnstakes them — the message routed on first, then the earlier user turns (servepasses up toMEMORY_TURNS).- select_
field - The field a question asks for, by keyword (lookup spec §3), in
FIELDSorder:семейств|family → family;части|часть|частей|частям|частях|частью| частями|part|parts → parts(whole words:частухаis a plant,частоan adverb);веществ|соединен|состав|компонент|ингредиент| compound|constituent|ingredient|chemical → compounds;противопоказ| безопас|побочн|опасн|ядовит|токсич|contraindic|toxic|poison|safety| safe|risk|risks|side effect → safety;доказ|исследован|evidence| study|studies|research|clinical|trial|trials → evidence;форм| препарат|дозиров|preparation|dosage|form|forms|dose|doses → preparations;примен|use|uses|used|usage → uses. Stems match a word prefix, the short Latin words match whole words (sobecauseis notuse,informationis notform).None= no field named: the whole card answers. - stem_
key stem_wordof every word of a normalised key or message, joined by single spaces (the form both sides of the stem index hash).- stem_
word - A light, deterministic stem of one normalised word — the same function
on the keys (at open) and on the message (per query), so an inflected
form meets its nominative key. Cyrillic: the longest ending of
RU_SUFFIXESis stripped, repeatedly, while ≥RU_STEM_MINletters remain (тойона→тойон,магнолии→магнол,лекарственной→лекарственн,зверобоя→зверобо→звероб). Latin script, ≥LATIN_STEM_MIN_WORDletters:ies→i,esafterss/x/z/ch/sh, or a finals(not afterss/us/is) is dropped when ≥EN_STEM_MINletters remain; otherwise a finaly→iso thatberrymeetsberries. Latin binomials mostly stay as they are (pinus,officinalis,balsamea). A word with a digit or another script is returned unchanged.