Ontology in the Prompt: +0.725 on Computed Financial Metrics, −0.225 on Multi-Condition Lookups
Paired Stage A evaluation (1,600 runs) plus public upstream operational findings: why static ontology injection lifts Tier 2 (+0.725 via curated SQL attributes) while regressing Tier 3 (-0.225 via template/entity shifts), and why Stage B DB benchmarks remain withheld per AUP.
Headline result: Tier 2 +0.725 (p=4.74e-15) vs Tier 3 -0.225 (p=4.01e-05) on Postgres
On this page (7 sections)
- 1. Motivation: Why Static Ontology Injection Backfires
- 2. Tier Definitions & Real Paired Examples (cq_dataset.jsonl)
- 3. Environment & Statistical Protocol
- 4. Visual Evidence & Quantitative Results
- 5. Mechanism Breakdown: Why Aggregate Accuracy Masks Two Opposite Regimes
- 6. Key Findings & Transferable Insights
- 7. Scope Limits & Next Experiment
Pre-registered Hypothesis, Falsification Criteria & Environment Manifest
- Hypothesis
- Supplying explicit ontology context improves query accuracy uniformly across all five reasoning tiers on both Postgres and Neo4j.
- Falsification Criteria
- Any statistically significant accuracy drop (paired McNemar p < 0.05) in any reasoning tier under ontology grounding refutes uniform improvement.
- Host / Compute
- Local benchmark harness (~/lab/auto-ontology-bench)
- Runtime
- Postgres 16 (local) + Neo4j (Stage A Text2SQL/Cypher only; DB-only Stage B withheld per Neo4j AUP)
- Workload / Dataset
- 5 reasoning tiers × 40 questions × 2 temp=0 repeats per condition (Tier 5 tests unanswerable abstention)
- Sample Size / Repeats
- 1,600 Stage A LLM+DB requests (400/condition across 2 repeats; Stage B DB benchmarks omitted per AUP)
1. Motivation: Why Static Ontology Injection Backfires
When Text2SQL or Text2Cypher pipelines return wrong numbers, teams reflexively append full domain ontologies, type hierarchies, and column rules into the system prompt. On paper this removes ambiguity; in practice, stuffing 1,400–1,600 extra tokens of schema rules into every request alters query generation differently depending on question topology.
2. Tier Definitions & Real Paired Examples (cq_dataset.jsonl)
Stage A evaluated four conditions (neo-no-onto, neo-onto, pg-no-onto, pg-onto) across 5 query tiers (80 paired requests per tier; 1,600 total). Here is what each tier tests and what flipped in actual records.jsonl runs:
- Tier 1 (Direct 1-hop entity lookup): “Who sits on TSMC’s board of directors?”
- Tier 2 (Computed ratio / derived metric — Biggest Ontology Win): “What was Albemarle’s return on equity in fiscal year 2024?” (
cq2_085)- Without ontology (
pg-no-onto→ empty): guessed a literal rowWHERE md.name ILIKE '%return on equity%'that does not exist inmetric_definitions. - With ontology (
pg-onto→ correct): knew ROE is computed fromnet_income÷stockholders_equityand synthesized joinedCTEs overmetric_code = 'net_income'.
- Without ontology (
- Tier 3 (Multi-condition similarity / attribute filter — Ontology Regression): “Which other companies disclose risk factors in the ‘Operations and manufacturing’ risk category, as TSMC does?” (
cq3_133)- Without ontology (
pg-no-onto→ correct): resolvedWHERE ticker = 'TSM'cleanly. - With ontology (
pg-onto→ empty): emittedWHERE name ILIKE '%TSMC%'(missing rows stored under full legal nameTaiwan Semiconductor...) and extra column constraints, dropping matched rows to zero.
- Without ontology (
- Tier 4 (Multi-hop / supply-chain traversal): “As of 2026-06-30, which companies within two supply tiers upstream of SpaceX did Renaissance Technologies hold?” (
cq4_163)- With ontology (
pg-onto→ syntax error): synthesized self-referencing CTEWITH upstream AS (... FROM upstream up ...)omittingWITH RECURSIVE, triggering PostgreSQLUndefinedTableError.
- With ontology (
- Tier 5 (Unanswerable abstention): “Give Caterpillar’s most recent number of patents granted.” (Expected: decline).
3. Environment & Statistical Protocol
Both conditions ran paired evaluation over 40 test questions × 2 temperature-0 repeats per tier (80 pairs/tier, 1,600 Stage A requests total; gold items remain pending-human-review), scoring lenient gold-set match on Tiers 1–4 and correct abstention on Tier 5. Significance uses two-sided paired McNemar tests; bracketed ranges denote 95% bootstrap confidence intervals. Per Neo4j’s Acceptable Use Policy (FINDINGS.md §3), Stage B DB-only throughput and latency sweeps are withheld and not published.
4. Visual Evidence & Quantitative Results
Full Size ↗
| Condition | Tier 1 | Tier 2 | Tier 3 | Tier 4 | Tier 5 | Overall (n=400) |
|---|---|---|---|---|---|---|
neo-no-onto | 0.39 [0.28–0.50] | 0.07 [0.03–0.14] | 0.28 [0.19–0.38] | 0.16 [0.09–0.24] | 0.86 [0.79–0.94] | 0.35 [0.31–0.40] |
neo-onto | 0.36 [0.26–0.47] | 0.60 [0.50–0.71] | 0.15 [0.07–0.24] | 0.12 [0.05–0.20] | 0.88 [0.80–0.95] | 0.42 [0.37–0.47] |
pg-no-onto | 0.78 [0.68–0.86] | 0.17 [0.10–0.26] | 0.49 [0.38–0.60] | 0.26 [0.17–0.36] | 0.90 [0.82–0.96] | 0.52 [0.47–0.57] |
pg-onto | 0.78 [0.68–0.86] | 0.90 [0.82–0.96] | 0.26 [0.16–0.36] | 0.15 [0.07–0.24] | 0.86 [0.79–0.94] | 0.59 [0.54–0.64] |
Inspecting per-tier outcome records (records.jsonl) reveals where each failure shift actually happened alongside Stage A context/latency overhead:
Full Size ↗
| Condition | Correct (T1–4) | Empty | Wrong Answer | Syntax + Exec Err | e2e p50 (ms) | LLM Total p50 (ms) | Prompt Tokens |
|---|---|---|---|---|---|---|---|
neo-no-onto | 72 / 320 | 205 | 26 | 6 + 1 | 7,567 | 7,443 | 881 |
neo-onto | 99 / 320 | 198 | 11 | 2 + 0 | 10,341 | 10,153 | 2,517 |
pg-no-onto | 136 / 320 | 136 | 34 | 13 + 0 | 5,698 | 5,697 | 1,357 |
pg-onto | 167 / 320 | 97 | 15 | 38 + 3 | 7,901 | 7,836 | 2,788 |
5. Mechanism Breakdown: Why Aggregate Accuracy Masks Two Opposite Regimes
- Ontology fixes missing derived formulas via curated attributes (Tier 2): Without derived metric definitions (
net_income/stockholders_equity), the LLM invents nonexistent metric names (wronganswers drop from 28 to 1 on Postgres, 18 to 6 on Neo4j). Crucially,FINDINGS.md §2notes Auto-Ontology’s automatic layer compiled 0 SQL attributes from row-stored metrics (metric_definitions × financial_metrics)—the42human-curated SQL attributes drove the Tier 2 jump. - Aggregate +0.070 hides Tier 3 template/grounding drift and Tier 4 recursion bugs: Tier 3 did not break because of syntax errors (only 1 syntax error in Tier 3). Auditing
31Postgres regressions revealed two concrete causes: matched concept-level query templates induced per-row rather than distinct outputs, and the extra context shifted entity linking away from canonical tickers (152 → 105queries) toward loose name filters likeILIKE '%TSMC%'. Syntax errors happened in Tier 4, where abstract path semantics pushed self-referencing CTEs withoutWITH RECURSIVE. Meanwhile, Text2Cypher trailed Text2SQL by0.17across both arms due to exact property lookups{name: '...'}(122–146of~320queries/arm at~0%accuracy vs0.45–0.67when ticker-anchored). - LLM inference, not local Postgres latency, dominates E2E cost: Local Postgres DB time remained under
0.05%of E2E latency (1.1 → 2.6ms vs5,697 → 7,836ms LLM); doubling prompt size added~2.2–2.7seconds to median LLM inference, plus54s median oncheck_answerable.
6. Key Findings & Transferable Insights
Distilled via multi-agent deliberation (Codex systems practitioner + Claude evidence gate) from FINDINGS.md §1–§2:
- Curate row-stored metrics explicitly; automatic schema ingestion misses semantic metrics: Auto-Ontology compiled
0SQL attributes frommetric_definitionsrows, whereas42curated attributes drove+0.725. Rule: Inspect compiled attribute yield directly instead of trustingschema ingested = covered. - Do not run uncalibrated
check_answerableinline on concurrent paths:_run_lockserializedcheck_answerableat~1 call/53 s(79/80timed out past180 satc=8), and answerable Tier 2 questions scored only0.20–0.33coverage—forcing dev calibration to choose no abstention gate. - Assert non-empty context (
ctx_chars,ctx_matched_sql) in request telemetry: Candidate IDs turned out to be attribute IDs, not term IDs—causing silent 404s that passed empty ontology contexts (*-buggyruns), while incompatiblelightning-30bthrew HTTP 400 × 3 (~89 s) before silently falling back to the raw prompt. - Anchor entities canonically before query generation & restrict ingested catalog views: Ticker-anchored Cypher (
0.45–0.67) massively beat ungrounded exact{name: ...}matches (~0%), and naivepg_catalogintrospection ingested internal monitoring views likepg_stat_statements.
7. Scope Limits & Next Experiment
- Dependent repeats & review status: The
80pairs/tier represent40questions ×2temperature-0 repeats, all250gold items remainpending-human-review, and Tier 2 curation itself can favor the ontology arm (FINDINGS.md §6). Stage B Aura DB throughput sweeps are withheld behind Neo4j AUP (yw-pow.6). - Next step: Test tier-gated selective ontology injection—supply curated metric definitions only on computed signatures, resolve canonical ticker/entity IDs deterministically before filter generation, and supply explicit
WITH RECURSIVEtemplates for Tier 4 path queries.