Skip to content

The lexeme catalog and the dictionary/delivery architecture

Status: accepted

Date: 2026-08-01

Relates to: ADR-0052 (amends decision 7’s delivery wording and narrows decision 1’s scope — the amendment recorded there: learning referents stay node-only; the lexeme catalog is a service-identity layer, not a second referent space; decision 4’s lazy minting gets its concrete substrate), ADR-0057 (rolling lexicon edition; alias-aware minting), ADR-0058 (event payloads carry lexeme ids), ADR-0056/A3 (personal storage prefix and erasure), docs/design/language-module-phase-2-plan.md (slices 2a-2, 2b-1, 2b-2).

The predecessor’s bingapilookup table plays two fused roles: the machine-translation cache for one provider, and — decisively — the system-wide lexeme identity space: every surface form the segmenter isolates is checked against it (missing forms are minted via external dictionary + translation services), enriched content carries per-surface-form candidate lexeme ids, and every system dictionary’s bespoke ingest parser associates its entries to those ids. Clients download the slim identity index (form + id) per language pair, making offline resolution of arbitrary text possible. Definitions are then delivered per-lexeme through proactive working-set caching plus on-demand backfill — not wholesale, and not via replication.

This identity space cannot be competency_node: a row for every lexeme the system ever encounters is the ~720k-scale service registry ADR-0052 decision 4 explicitly refused to make referents (~41k tracked items for a committed learner). It is enrichment-layer service data with an identity role — so the identity role gets its own first-class layer, bridged to nodes.

Organizations license dictionaries for their people. Real licenses gate who may hold the content while affiliated — never where it may be used; policing use of legitimately held content is the law’s business, not the platform’s.

  1. Three layers.

    • lang_lexeme — the system lexeme catalog, per L2 only (the run lexeme is one row regardless of the learner’s L1; pair-specific content lives in the dictionary layer). Identity is the predecessor’s proven contract: one row per (language, graph) — the canonical written form (the lemma for lemmatizing languages; the word itself for Chinese, where they coincide), Unicode-normalized (NFC) and unique per L2. Senses and parts of speech are dictionary-content structure, never identity splits — the catalog does not model sense-level referents, exactly as bingapilookup did not. Concurrent minting (including the never-seen-form endpoint) converges on that unique key: insert-on-conflict-read, so racing mints of the same form yield one id. Normalization details beyond NFC (width folding, case policy per language) are the 2a-2 implementation contract. Carries legacy_id (the predecessor’s int id — the Phase-7 migration bridge for imported user data and reusable enriched artifacts) and a nullable competency_node_id — the lazy-minting bridge, set by the projector the first time the lexeme is evidenced (ADR-0052 decision 4 executes here; decision 1’s amendment records that this bridge is service-side and lexeme ids never enter the learning contracts). B2’s merge machinery re-points lexeme rows like any other referrer.

      Amendment (2026-08-01, implementation review, maintainer-ruled). Two properties join the catalog: (a) publication state — rows minted by curated ingest (dictionary parsers, list ingest, enrichment of published content) are published and ride the shared resolution index; rows minted by live learner lookups or personal text are unpublished, server-resolvable but never on any shared shape, until an ingest path promotes them. One learner’s pasted tokens (names, typos, private text) must never become platform-enumerable through the index — the predecessor’s everything-public bingapilookup semantics are explicitly not ported. (b) Canonical lexeme per node — several lexemes may bridge to one node after merges, so the lexeme that minted the node carries a canonical flag (partially-unique per node; merge keeps the survivor’s canonical and demotes the loser’s): the client labels node-keyed facts by the canonical row, other bridged lexemes are resolution aliases.

    • lang_surface_form — (L2, form) → lexeme id, one-to-many in both directions (English “ran” → run; ambiguous forms → several candidates). Near-empty for Chinese, where form and lemma coincide.

    • Dictionaries above both, keyed per scope as below.

  2. The resolution index syncs; content never does. Per language, slim column-projected read projections (the B3 defineReadProjection allowlist idiom) carry the resolution index — lang_surface_form as (form, lexeme_id) plus minimal lang_lexeme identity columns — as lazy language-scoped shapes. The predicate is a public per-language constant — identical for every learner of the language: Electric’s cheapest case, one shared shape log. Pursuit scoping (ADR-0060) never enters the predicate — Electric’s shape grammar could not express it (single-table, bare columns) and a person-dependent predicate would fracture the shared log; instead the client’s pursuit rows decide which language shapes it activates, and any server-side authorization happens at subscription time, outside the predicate. A new lexeme is one streamed row, never a refetch. Nothing multi-MB rides replication.

  3. System and org-licensed dictionary content is per-lexeme rows. Each dictionary has a bespoke ingest parser whose output is (dictionary_id, lexeme_id, content) rows — the generalized bingapilookup shape. A batch endpoint serves “entries for lexeme ids [X…] across the dictionaries this person may access”. The uploaded source file may be retained as an ingest artifact; nothing serves from it. Machine translation is one such provider, with content per (lexeme, L1), populated lazily by the enrichment service; the never-seen-form lookup path mints the lexeme server-side and returns id + definitions in one round trip.

    Amendment (2026-09-13, offline plan R7 and S5b). The batch’s size is a deployment’s configuration (LANG_DEFINITION_BATCH_MAX_LEXEMES, default 1000), reported to the client on the accessible-dictionary response and chunked at by it; an over-sized batch is refused naming the cap, never truncated. The batch may also be narrowed to named dictionaries — a filter that only ever subtracts: the entitlement predicate stays joined in unchanged, so an id the person is not entitled to answers nothing and is indistinguishable from a dictionary that has no entry for the lexeme.

    A client writes each chunk as one local transaction, and which one follows from what it already holds. Its coverage state stamps every cached lexeme with the accessible set it was last asked under, and every accessible dictionary with the generation it became reachable at, giving completeness in full: covered(D, L) ⟺ gainedAt(D) ≤ stamp(L).

    • A lexeme it holds nothing for is asked unnarrowed, and the complete answer replaces it wholesale — a DELETE of the answered lexemes’ rows and a COPY of the chunk: an entry the answer no longer carries is one this person can no longer read, and a per-row upsert would leave it behind forever. The never-seen-form mint writes the same way, for the one lexeme it resolved.
    • A lexeme it already holds, made incomplete by a dictionary gained since its stamp, is asked about those dictionaries alone and written as a DELETE scoped to exactly the (lexeme, dictionary) keys the COPY writes — a collision guard against a concurrent writer, never another dictionary’s rows — plus a set-based restamp of the chunk’s lexemes to the current generation. Rows of the dictionaries the lexeme was already covered against are neither re-fetched nor rewritten, and a dictionary that has since lapsed costs the restamp alone, with no request.

    A requested-but-unanswered lexeme keeps its rows (eviction is decision 5’s housekeeping, not this).

  4. Personal dictionaries are storage-object blobs. One lang_dictionary row (identity, scope, content hash) with the payload as a storage object under the A3 per-person key prefix (erasure completeness inherited from the prefix sweep). Surface-form keyed — personal imports get no lexeme association and no bespoke parser. Re-import replaces in place; no versioning (ruled in the Phase-1 grill). Replacement is atomic by protocol: the new payload uploads as a new object under the prefix, the dictionary row’s content hash and object pointer swap in one transaction, and the superseded object is deleted via the A3 compensating-cleanup pattern — a partial failure leaves the old pair fully intact, and the hash can never point at bytes that are not there. The swap writes an audit event (hashes before/after, timestamp — metadata only), satisfying invariant 6’s no-hidden-overwrites without retaining content history: the no-versioning ruling governs content, not the fact of replacement. The client fetches hash-gated and explodes into a local indexed table.

  5. Entitlement is a fetch gate, nothing more. Scope on lang_dictionary is a checked discriminator over three column sets: personal ⇒ person_id NOT NULL, org/offering NULL; org-licensed ⇒ organization_id NOT NULL plus a nullable offering scope whose offering, when set, must belong to that organization; system ⇒ all three NULL — database checks enforce the per-scope shape, making the storage-model split (blob-backed personal vs entry-backed system/org) explicit in the schema rather than implicit in code paths. The access predicates reuse existing machinery, never profile inference (invariant 9): “live standing at the org” is the membership/affiliation predicate with its effective window (invariants 5/8); the offering scope means that offering’s current enrollees (“while signed up for a particular course”). Creation authority per scope: system — platform operator; org-licensed — that organization’s admins; personal — the owner, on their own prefix. Once held, a dictionary is usable everywhere locally, in every context. Entitlement lapse → the client’s next entitlement check deletes the local copy — best-effort housekeeping, explicitly not enforcement. No use-context restriction exists anywhere in the design.

  6. The client definition-cache manager owns two local stores: the (dictionary, lexeme_id)-keyed definition store for entry-backed (system/org) dictionaries, and the surface-form-keyed personal store each personal blob explodes into (personal entries carry no lexeme ids — decision 4 — so they cannot inhabit the lexeme-keyed store). The lookup chain consults the personal store by surface form ahead of lexeme-keyed definitions, preserving the predecessor’s resolution order (personal → curated → machine). The entry store has five population policies, ported from the predecessor’s proven offline model:

    1. the per-language base list (the “10k most common” curated inventory) prefetched at bootstrap for accessible dictionaries;
    2. every list usable by the SRS or referenced by a goal prefetched in full — list switching must work offline;
    3. offline content packages: extract unique lexeme ids from the bundled parse, diff against local, batch-backfill;
    4. live-parse models (extension/webpage path, Phase 8 machinery-compatible): backfill ids missing from local immediately;
    5. lookup fallback chain: local surface-form (+ computed headword) resolution → local definitions → fetch-by-id → server mint for never-seen forms.
  7. Learner source preferences (“which sources, in what order” per activity/content) are tiny person-owned synced rows. The picker offers every dictionary the person currently holds; ordering is the learner’s. (2026-08-01: ruled that both dimensions ship in v1 — the key is (person, activity kind, content ref), each context nullable with a reserved default sentinel; the content reference uses the namespaced-ref format the goal extension_ref validates, populated when the Phase-4 reader surfaces exist.)

    Amendment (2026-09-13, offline plan R8). The picker’s list is LOCAL truth between entitlement checks: decision 6’s coverage state records each accessible dictionary’s identity (title, scope, both language tags) beside the gainedAt it already kept, so a surface seeds its list from the client with no network and lets the entitlement endpoint’s answer replace the seed when it arrives — a failed refresh is only reported when there was no seed either.

  • Lexemes as competency nodes (eager minting): ADR-0052 decision 4’s rejection stands.
  • Normalized shared entry tables for personal dictionaries: 10k learners × 200k-entry imports of data only the owner’s client ever reads.
  • Blob delivery for system dictionary content: defeats the per-lexeme working-set model every offline case requires; a continuously-growing corpus makes whole-blob refresh the wrong shape.
  • Syncing definitions over replication: multi-MB per-person shape logs for content the fetch/cache path delivers better.
  • Use-context-scoped licensing (org dictionaries usable only inside org contexts): retracted by the maintainer — no real license works this way, and it is unenforceable against held bytes; fetch gating + eviction is the honest whole of it.
  • Per-pair lexeme identity (the predecessor’s fusion): splits shared identity by L1 and duplicates the catalog per audience.
  • ADR-0052 decision 7 is amended: the node inventory remains a scoped projection; dictionary content ships via the per-lexeme fetch/cache path (system) and hash-gated blobs (personal); the lexeme resolution index syncs as slim shared shapes. “Hydrate on demand, never a full-lexicon sync” survives as: content on demand per working set — identity index always local.
  • The Phase-7 predecessor import maps user data and enriched artifacts through lang_lexeme.legacy_id.
  • The catalog carries one per-lexeme corpus frequency (frequency_wcpm, words per million; Phase 7 plan R6, 2026-09-10), present on both identity shapes so the ordering policy can rank words outside any curated list.
  • Decision 7’s ordering is also a SELECTION (settings plan R2, 2026-09-11): when a person holds a preference row for a context, a source absent from it is omitted from that context’s definitions, as the predecessor did; a person with no row sees every accessible source. A word’s canonical sound (its transliteration) is not a definition and is not subject to the selection.
  • ADR-0058’s event payloads reference lexeme ids that are guaranteed resolvable client-side (the index is local) and server-side (the catalog is the system of record).
  • Erasure surface: personal dictionaries via the A3 prefix + row delete; the catalog and system entries are not person-linked; preference rows register per convention.

Amendment — 2026-09-17: an offering-narrowed licence is satisfied by membership alone

Section titled “Amendment — 2026-09-17: an offering-narrowed licence is satisfied by membership alone”

Why decision 5 changed. Decision 5 spelled the org-licensed predicate as live standing at the organization AND, when the licence names an offering, current membership of that offering. ADR-0056 hosts every personal offering under the personal-0 sentinel, to which nobody is ever affiliated. A licence held personally (backlog 0014: the maintainer’s ABC dictionaries, org personal-0, narrowed to their personal offering) therefore failed the affiliation half before the offering half was read, and was invisible to the one person it was for.

The amended predicate. When the licence names an offering, CURRENT MEMBERSHIP of that offering is the standing on its own — decision 5’s own words, “while signed up for a particular offering”. An org-wide licence (offering NULL) keeps the live-affiliation test unchanged. Membership of an organization’s offering already implies the relationship for a real organization, so nothing is widened there; the only holders this reaches that it did not before are members of personal-0 offerings, which is the case the sentinel exists for. Everything else in decision 5 stands: the fetch gate, no use-context restriction, no existence leakage.