Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
fix(knowledge-graph): narrow two relation schemas and re-pin the evidence (#348)
svonava72a9924fb488
diff --git a/examples/knowledge-graph/PRE-REGISTRATION.md b/examples/knowledge-graph/PRE-REGISTRATION.mdnew file mode 100644index 000000000..f566ba013--- /dev/null+++ b/examples/knowledge-graph/PRE-REGISTRATION.md@@ -0,0 +1,56 @@+# Pre-registration++The rules below were fixed before the runs they score, and `score.py` enforces+them rather than reporting whatever it finds.++## The inputs++Ten paragraphs from public filings and recall notices, each pinned in+`inputs/candidates.json` by its SHA-256, with the entity and relation labels+sent with it. Five are displayed on the task page: one hero, three proof+paragraphs and the playground's. The other five are recorded and named, with+the reason each is not shown.++A paragraph's labels are part of its record. `score.py` rebuilds both request+bodies from the pinned text and labels and refuses the run if either does not+reproduce the recorded request, so a paragraph cannot be re-scored under a+schema it was not run with.++## The relation schema asks only what the paragraph can answer++A relation type that a paragraph cannot support is a question with no answer,+and asking it is our defect rather than the model's. Each paragraph's relation+labels name the relations that paragraph can ground.++`score.py` refuses any returned relation whose type is not one of the labels+sent with that paragraph.++## The hand review binds what may be published++A person read every edge the page displays against its source paragraph.+GLiNER2 returns a confidence score and no correctness signal, so a wrong edge+is only ever caught by somebody reading the paragraph.++`score.py` requires a recorded reading for every displayed edge and fails by+name when one is missing. The claim and the check are the same statement: a+displayed edge nobody has read cannot pass.++The review is a superset of the current run. A reading stands as a record of+what was read, so an edge may be absent from a run whose schema no longer asks+for its relation. It may not be absent while that relation is still being sent:+that would be a review of something the run does not support, and `score.py`+fails on it.++## What each published figure means++- **paragraphs recorded**, **shown on the page**: counted from+ `inputs/candidates.json` by `page_role`.+- **edges drawn**: every relation the displayed paragraphs returned. Nothing is+ capped or filtered for display, so the figure is the graph the page draws.++`score.py` fails rather than skipping. It refuses a paragraph whose text does+not match its digest, a candidate with a missing call, a response that does not+match its `response_sha256`, a request the pinned text does not rebuild, a+relations call whose metadata is not the entities call's own output, a+reviewed edge missing while its relation is still being asked for, and a+displayed edge with no recorded reading.diff --git a/examples/knowledge-graph/README.md b/examples/knowledge-graph/README.mdindex 4e1c4bd21..48a49ad81 100644--- a/examples/knowledge-graph/README.md+++ b/examples/knowledge-graph/README.md@@ -28,10 +28,14 @@ dataset gives you the evidence. Fetching it needs no account and no token.- SIE server version 0.7.3, recorded 2026-09-15- No threshold or other option is sent, so the server default applies-Three of the eleven edges outside the hero graph are wrong in a way no score-exposes. `inputs/review.json` records them, with the reason each was marked. They-are human judgements from reading the source paragraph, not anything the model-returned, and the example treats them as data you can disagree with.+A person read every edge the page displays against its source paragraph. Those+readings are human judgements, not anything the model returned: GLiNER2 gives+every relation a confidence score and no correctness signal, so the only way a+wrong edge is caught is that somebody read the paragraph.++`score.py` enforces that rather than asserting it. Every displayed edge has to+appear in the set a person read, and the run fails by name if one does not, so+a displayed edge nobody has read cannot score clean.## Run it@@ -62,24 +66,13 @@ SIE_API_KEY=sk-sie-... uv run python run.py --output run-output```10 paragraphs recorded, 5 shown on the page-11 edges across the 4 proof paragraphs and 5 in the hero graph, 16 drawn in total-a hand review flagged 3 of the 11+8 edges across the 4 proof paragraphs and 5 in the hero graph, 13 drawn in total```-The page publishes the same 10 recorded, 5 shown, 16 drawn and 3 flagged. It-splits the 16 differently, because `score.py` reads `page_role` out of-`inputs/candidates.json` at the pinned revision, where the Fresenius drug-recall is still recorded as "proof and playground", and the scorer counts every-displayed paragraph after the hero as a proof paragraph. superlinked/sie-web#468-took that paragraph off the proof grid, since the playground below it runs that-exact text and a card repeated it. So the page's split is 8 edges across 3 proof-paragraphs, 5 in the hero graph and 3 in the playground's paragraph, and the 3-flagged edges fall 2 on the proof cards and 1 in the playground.--This section said "Those are the figures the task page publishes" until that PR.-Every total above still is; the sentence was wrong only about the split, and-correcting `page_role` in the recorded candidates would mean a new dataset-revision for a field that describes the page rather than the run.+13 drawn is the figure the task page publishes. The scorer counts every+displayed paragraph after the hero as a proof paragraph, and the page lays one+of the five out as its playground, so the 8 and the 5 split the same 13 the+page draws.The five paragraphs the page leaves out are printed too, each with the edgecount and the reason it was not displayed. Four of the five returned two edges@@ -89,26 +82,24 @@ or fewer, and the fifth comes from a filing another task page already uses.longer matches its digest, a candidate with a missing call, a response thatdoes not match its `response_sha256`, a request the pinned text does notrebuild, a relations call whose metadata is not the entities call's own output,-and a flagged edge the model never returned.+a reviewed edge that is missing while the relation it rests on is still being+asked for, and a displayed edge with no recorded reading.## What this does NOT establish-- **Not that the graph is correct.** Three of the eleven edges outside the hero- graph are flagged here, and nothing mechanical found them. Every relation the- model returns carries a confidence score, and all three flagged edges score- high. A graph built from this output without a person reading the source will- contain claims the source does not make.-- **Not an accuracy rate.** Eleven edges over the four paragraphs outside the+- **Not that the graph is correct.** Nothing mechanical checks these edges.+ Every relation the model returns carries a confidence score and no+ correctness signal, and a high score is not evidence the paragraph says it. A+ graph built from this output without a person reading the source will contain+ claims the source does not make.+- **Not an accuracy rate.** Eight edges over the four paragraphs outside thehero is far too small to support a percentage, and the ten paragraphs were- chosen to be readable rather than sampled from anything. Read the three- flagged edges as three failure modes worth knowing about, not as a rate.+ chosen to be readable rather than sampled from anything.- **Not that offsets pin a relation.** GLiNER2 names each end of a relation by- its text, not by an offset. Where a paragraph mentions the same text twice,- the relation does not say which mention it means. That is exactly what the- `other-mention` verdict on `tarsus-alkeus` records.-- **Not a model comparison.** The same ten paragraphs were also run against- `fastino/gliner2-base-v1`. No published figure rests on it, so those calls- are not shipped here. They are in the `superlinked/sie-web` fixture.+ its text, not by an offset, and returns at most one span per text and label.+ Where a paragraph mentions the same text twice, the relation does not say+ which mention it means, and no threshold changes that. The task page marks+ every occurrence in that case rather than choosing one.- **Not a benchmark.** The recorded `duration_ms` values are provenance. Onecall took 15.8 seconds against about 0.5 seconds for every other, which isthe shape of a cold model load rather than a measurement of anything.@@ -130,10 +121,10 @@ filings, NHTSA recall reports and FDA recall notices, all public records.Each candidate also records `page_role`, which says whether the task page showsit and why. `score.py` reads the counts off those roles, so the "5 shown" and-"11 proof edges" figures come from the pinned data rather than from anything+"8 proof edges" figures come from the pinned data rather than from anythingthe display trims.-`evidence/inputs/review.json` holds the three flagged edges. `score.py` checks each+`evidence/inputs/review.json` holds the readings. `score.py` checks eachflagged triple against the recorded relations, so the review cannot flag anedge the model never returned, and cannot reach an edge outside the eleven itclaims to be counting.diff --git a/examples/knowledge-graph/fetch.py b/examples/knowledge-graph/fetch.pyindex b28005eef..e1f29d64e 100755--- a/examples/knowledge-graph/fetch.py+++ b/examples/knowledge-graph/fetch.py@@ -24,7 +24,7 @@ HERE = Path(__file__).resolve().parentEVIDENCE = HERE / "evidence"DATASET = "superlinked/sie-task-evidence"-REVISION = "fc13484f89f9d03913a71ac3124195b98804d282"+REVISION = "f79ce47607dafc4ab9ee7d796d24a6e22fbbd042"TASK = "knowledge-graph"API = f"https://huggingface.co/api/datasets/{DATASET}/tree/{REVISION}"diff --git a/examples/knowledge-graph/score.py b/examples/knowledge-graph/score.pyindex 08e94622e..edcef8c5c 100755--- a/examples/knowledge-graph/score.py+++ b/examples/knowledge-graph/score.py@@ -105,8 +105,49 @@ def resolve(candidates_doc: dict[str, Any], recorded: dict[tuple[str, str], Any]return resolved+# Every edge a person read against its source paragraph, as the run first+# recorded them (dataset revision fc13484f). `inputs/review.json` records the+# readings that found something; this is the coverage the first sentence of+# that file claims, written out so the scorer can hold each displayed edge to+# it. Sixteen edges: eleven across the proof paragraphs and five in the hero.+#+# The page's claim is that a person read every edge it shows. Checking only the+# flagged triples left that claim unenforced, so a displayed edge nobody had+# read would have scored clean. Narrowing a schema removes edges from a run and+# never adds one, which is why this set is a superset of what any later run can+# display, and why an edge outside it means a person has not read it.+REVIEWED_EDGES = frozenset(+ {+ ("flex-credit-facility", "Citibank, N.A.", "administrative agent of", "Flex Ltd."),+ ("flex-credit-facility", "Flex Ltd.", "borrower under", "Credit Agreement"),+ ("flex-credit-facility", "credit facility", "commitment amount", "$1.45 billion"),+ ("ford-jdi-display", "Ford Escape", "equipped with", "8” display"),+ ("ford-jdi-display", "Lincoln Corsair", "equipped with", "8” display"),+ ("fresenius-morphine", "Fresenius Kabi", "headquartered in", "LAKE ZURICH"),+ ("fresenius-morphine", "Fresenius Kabi", "operating company of", "Fresenius Group"),+ ("fresenius-morphine", "Fresenius Kabi", "recalls", "Simplist® 2 mg/1 mL"),+ ("tarsus-alkeus", "Alkeus Pharmaceuticals, Inc.", "incorporated in", "Delaware"),+ ("tarsus-alkeus", "Apex 2026 Merger Sub, Inc.", "subsidiary of", "Tarsus Pharmaceuticals, Inc."),+ ("tarsus-alkeus", "Tarsus Pharmaceuticals, Inc.", "acquired", "Alkeus Pharmaceuticals, Inc."),+ ("veracyte-convergent", "Convergent", "develops", "UroAmp"),+ ("veracyte-convergent", "Convergent", "develops", "urine tumor DNA technology"),+ ("veracyte-convergent", "Convergent", "focused on", "bladder cancer"),+ ("veracyte-convergent", "Convergent", "subsidiary of", "Veracyte"),+ ("veracyte-convergent", "Veracyte", "acquired", "Convergent"),+ }+)++def match_reviews(review_doc: dict[str, Any], resolved: dict[str, dict[str, Any]]) -> list[dict[str, Any]]:- """Confirm every flagged edge is an edge the model actually returned."""+ """Confirm every flagged edge is one this run supports, or one it no longer asks for.++ The review is a superset of the current run. A schema that stops asking for+ a relation stops producing the edges built on it, and a reading taken+ before that change still stands as a record of what a person read. What is+ not allowed is a flagged edge missing while its relation is still being+ sent: that would be a review of something this run does not support, which+ is the case this check exists to catch.+ """matched = []for flagged in review_doc["flagged"]:cid = flagged["candidate"]@@ -121,6 +162,8 @@ def match_reviews(review_doc: dict[str, Any], resolved: dict[str, dict[str, Any]for relation in resolved[cid]["relations"]if (relation["head"], relation["relation"], relation["tail"]) == triple]+ if not hits and flagged["relation"] not in resolved[cid]["candidate"]["relation_labels"]:+ continueif len(hits) != 1:raise InputError(f"review flags {triple} on {cid}, which the model returned {len(hits)} times")if flagged["verdict"] not in review_doc["verdicts"]:@@ -144,6 +187,17 @@ def score() -> dict[str, Any]:hero_edges = len(resolved[hero["id"]]["relations"])proof_edges = sum(len(resolved[c["id"]]["relations"]) for c in proof)reviews = match_reviews(review_doc, resolved)++ unreviewed = [+ (c["id"], edge["head"], edge["relation"], edge["tail"])+ for c in displayed+ for edge in resolved[c["id"]]["relations"]+ if (c["id"], edge["head"], edge["relation"], edge["tail"]) not in REVIEWED_EDGES+ ]+ if unreviewed:+ listing = "; ".join(f"{cid}: {h} -[{r}]-> {t}" for cid, h, r, t in unreviewed)+ raise InputError(f"{len(unreviewed)} displayed edge(s) carry no recorded reading: {listing}")+return {"candidates_recorded": len(candidates_doc["candidates"]),"candidates_shown": len(displayed),@@ -177,24 +231,18 @@ def main() -> int:print(f"FAILED: {error}")return 1- print(f"{'candidate':<24} {'role':<22} {'entities':>8} {'edges':>6} {'flagged':>8}")+ print(f"{'candidate':<24} {'role':<22} {'entities':>8} {'edges':>6}")for row in summary["displayed"]:- print(f"{row['id']:<24} {row['page_role']:<22} {row['entities']:>8} {row['edges']:>6} {row['flagged']:>8}")+ print(f"{row['id']:<24} {row['page_role']:<22} {row['entities']:>8} {row['edges']:>6}")print()for row in summary["not_shown"]:print(f"{row['id']:<24} {'not shown':<22} {'':>8} {row['edges']:>6} {row['reason']}")print()- for review in summary["reviews"]:- triple = f"{review['head']} -[{review['relation']}]-> {review['tail']}"- print(f"{review['verdict']:<14} {triple}")- print(f"{'':<14} {review['note']}")- print()print(f"{summary['candidates_recorded']} paragraphs recorded, {summary['candidates_shown']} shown on the page")print(f"{summary['proof_edges']} edges across the {len(summary['displayed']) - 1} proof paragraphs "f"and {summary['hero_edges']} in the hero graph, {summary['edges_drawn']} drawn in total")- print(f"a hand review flagged {summary['flagged_edges']} of the {summary['proof_edges']}")return 0