Elffuss BraidHub

kikocis/utopia public

dev · 4.8 KiBSourceRawPermalink

0006 · Ontology scale and the extraction prompt

The problem

The extraction prompt inlined the whole ontology once per chunk; extraction.rs called entity_types(kb) with no selection step. After importing schema.org (968 classes, 1034 relations, 599 attributes) each chunk cost 108,133 tokens. 0001 P3 had guessed "800 classes blows the prompt" and got the shares wrong: classes 38%, relations 34%, attributes 28%.

Decisions

  1. Switch by budget. If the ontology fits, inline it all, unchanged: a forty-class ontology is 2k characters and retrieval would be a wasted round trip. If not, each chunk retrieves its own candidates with chunk.embedding (already loaded for entity resolution), falling back to the full list when nothing is retrieved. The budget is in characters because description lengths differ by orders of magnitude, and it measures the text build_lists actually lays out. It is a deployment setting because tuning it needs paired runs per level, and nobody reruns a curve that needs a server restart per point.
  2. Three details that exist only once there is a choice. Signatures may name only inlined classes (an absent class in works_at (person → organization) teaches the model a type that does not exist; an unselected side becomes *); attributes follow their domain class; both paths share one build_lists, or the prompt stops matching what the code accepts.
  3. Ancestor completion (2026-09-02): whatever retrieval hits, its subClassOf ancestors are inlined too, breadth-first with a visited set. The chain is the ontology's own declaration of generalization; no hand-kept list of "general classes". The only detail forced by real data.

The bench (scripts/bench/corpora/pharma.json, 5 Chinese pharmaceutical documents, one run each) showed no degradation up to 58,651 characters of ontology (about 15k tokens, 202 classes): entities per run swung 23–28 with no trend, so 24,000 is conservative. Full inline has a ceiling unrelated to quality: at 394 classes (169,380 characters) it hit the vendor's per-minute token limit (429) and never finished; retrieval did. With schema.org, correctly typed entities went 2 of 19 with seeds only, 7 with the large ontology in post-hoc resolution, 12 with per-chunk retrieval. Caveats: single runs (the same input has produced 25 and 18 entities) and alphabetical subsets (subset.mjs takes the first N classes), hence no hit rate.

Dead ends

Revisions

Open questions