{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "lab-06-00",
   "metadata": {},
   "source": [
    "# 06 · Choose an evidence source\n",
    "\n",
    "Does a question need document retrieval, a graph, SQL or long context?\n",
    "\n",
    "Compare long-context and retrieval for manual questions using matched budgets. For structured inventory questions, use a semantic view with read-only parameterised SQL. Compare graph traversal on entity-link questions. Report within-family results and one routed aggregate.\n",
    "\n",
    "**Measures** — Citation support, exact numeric answers, routing errors, coverage and input budget by question family.\n",
    "\n",
    "**Evidence** — Evidence router with four case types and a retained source per answer.\n",
    "\n",
    "**Runtime** — CPU data paths, T4 generation. The course bench uses invented facilities, equipment and records."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-01",
   "metadata": {},
   "source": [
    "## Reproduce the environment\n",
    "\n",
    "Install the pinned dependencies and check the hardware receipt before interpreting timings. Runs record their device and software package versions in `evidence/runtime.json`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "lab-06-02",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-27T06:27:33.035957Z",
     "iopub.status.busy": "2026-11-27T06:27:33.035666Z",
     "iopub.status.idle": "2026-11-27T06:27:33.058584Z",
     "shell.execute_reply": "2026-11-27T06:27:33.057699Z"
    }
   },
   "outputs": [],
   "source": [
    "PINS = {'transformers': '4.51.3', 'accelerate': '1.6.0', 'sentence-transformers': '4.1.0', 'bitsandbytes': '0.49.0', 'pypdf': '5.6.1', 'pymupdf': '1.26.1', 'reportlab': '4.4.2', 'rank-bm25': '0.2.2', 'soundfile': '0.13.1'}\n",
    "\n",
    "import importlib.metadata\n",
    "import os\n",
    "import subprocess\n",
    "import sys\n",
    "\n",
    "if os.environ.get(\"COURSE_SMOKE\") != \"1\":\n",
    "    missing = []\n",
    "    for name, version in PINS.items():\n",
    "        try:\n",
    "            matched = importlib.metadata.version(name) == version\n",
    "        except importlib.metadata.PackageNotFoundError:\n",
    "            matched = False\n",
    "        if not matched:\n",
    "            missing.append(f\"{name}=={version}\")\n",
    "    if missing:\n",
    "        try:\n",
    "            import uv\n",
    "        except ImportError:\n",
    "            subprocess.run([sys.executable, \"-m\", \"pip\", \"install\", \"--quiet\", \"uv==0.7.13\"], check=True)\n",
    "        subprocess.run([sys.executable, \"-m\", \"uv\", \"pip\", \"install\", \"--quiet\", \"--python\", sys.executable, *missing], check=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-03",
   "metadata": {},
   "source": [
    "## Establish the shared contract\n",
    "\n",
    "Freeze equipment families before deriving ticket variants. Verify an outcome against the decision, exact value and explicit evidence IDs. Keep the release split closed until the capstone. Read-only tools take tenant and role from trusted request metadata."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "lab-06-04",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-27T06:27:33.062549Z",
     "iopub.status.busy": "2026-11-27T06:27:33.062209Z",
     "iopub.status.idle": "2026-11-27T06:27:33.101938Z",
     "shell.execute_reply": "2026-11-27T06:27:33.101369Z"
    }
   },
   "outputs": [],
   "source": [
    "MODEL_IDS = {'text': ('Qwen/Qwen2.5-1.5B-Instruct', '989aa7980e4cf806f80c7fef2b1adb7bc71aa306'), 'vision': ('Qwen/Qwen2-VL-2B-Instruct', '1860c46f12b7449d0f5b426a7474ab715342bc65'), 'speech': ('openai/whisper-base', 'e37978b90ca9030d5170a5c07aadb050351a65bb'), 'embedding': ('sentence-transformers/all-MiniLM-L6-v2', '1110a243fdf4706b3f48f1d95db1a4f5529b4d41'), 'reranker': ('cross-encoder/ms-marco-MiniLM-L6-v2', '233902d25c440f23af6f7d6e94d2946bac0bee0a')}\n",
    "SPLIT_MANIFEST = {'train': {'sha256': '610cd78bdcc4f92095a511c4c92812eace3bcd25f290604d4641f8338438bc4b', 'n': 180, 'families': 18}, 'dev': {'sha256': '51dbc208b6b20a620237dd76ce0a2db4f10aa75f4f8fc404121e301b8d79a0cf', 'n': 120, 'families': 12}, 'holdout': {'sha256': 'd8c88e29283fe660e86b9bf3b3c67fb810f3cfa75c27e2e7043bccfb42766452', 'n': 300, 'families': 30}}\n",
    "LAB_NUMBER = 6\n",
    "\n",
    "import hashlib\n",
    "import json\n",
    "import os\n",
    "import random\n",
    "import re\n",
    "import sqlite3\n",
    "from functools import lru_cache\n",
    "from pathlib import Path\n",
    "\n",
    "SLICES = (\"manual\", \"numeric\", \"multi_source\", \"ambiguity\", \"boundary\", \"follow_up\")\n",
    "SPLITS = {\"train\": (100, 3), \"dev\": (200, 2), \"holdout\": (300, 5)}\n",
    "TENANTS = (\"north-yard\", \"south-yard\")\n",
    "\n",
    "\n",
    "@lru_cache\n",
    "def _assets(split):\n",
    "    first, count = SPLITS[split]\n",
    "    rows = []\n",
    "    for slice_index, category in enumerate(SLICES):\n",
    "        for offset in range(count):\n",
    "            index = first + slice_index * 10 + offset\n",
    "            prefix = (\"P\", \"F\", \"V\")[index % 3]\n",
    "            result = {\n",
    "                \"family\": f\"F{index}\", \"slice\": category, \"tenant\": TENANTS[index % 2],\n",
    "                \"asset\": f\"{prefix}-{index}\", \"linked\": f\"S-{index + 400}\",\n",
    "                \"team\": (\"mechanical\", \"controls\", \"electrical\")[index % 3],\n",
    "                \"limit\": 67 + (index * 19) % 36,\n",
    "                \"inspection\": f\"2025-{index % 12 + 1:02d}-{index % 27 + 1:02d}\",\n",
    "                \"fault\": (\"seal wear\", \"sensor drift\", \"filter blockage\", \"bearing vibration\")[index % 4],\n",
    "                \"version\": \"r3\",\n",
    "            }\n",
    "            for source in (\"manual\", \"inventory\", \"graph\"):\n",
    "                result[f\"{source}_id\"] = f\"{source}-{result['asset']}-r3\"\n",
    "            rows.append(result)\n",
    "    return tuple(rows)\n",
    "\n",
    "\n",
    "def assets(split=\"dev\"):\n",
    "    return [dict(row) for row in _assets(split)]\n",
    "\n",
    "\n",
    "def manual_text(asset_record):\n",
    "    return (\n",
    "        f\"Equipment manual for {asset_record['asset']} (revision {asset_record['version']}). \"\n",
    "        f\"Maximum operating temperature: {asset_record['limit']} C. \"\n",
    "        f\"Known fault: {asset_record['fault']}. The supporting system is {asset_record['linked']}. \"\n",
    "        f\"Maintenance owner: {asset_record['team']}.\"\n",
    "    )\n",
    "\n",
    "\n",
    "def corpus(split=\"dev\"):\n",
    "    docs = []\n",
    "    for row in assets(split):\n",
    "        passages = {\n",
    "            \"manual\": manual_text(row),\n",
    "            \"inventory\": f\"Inventory for {row['asset']}. Last inspection: {row['inspection']}.\",\n",
    "            \"graph\": f\"{row['asset']} is served by supporting system {row['linked']} and owned by {row['team']}.\",\n",
    "        }\n",
    "        docs.extend({\n",
    "            \"id\": row[f\"{source}_id\"], \"source\": source, \"text\": passage,\n",
    "            \"tenant\": row[\"tenant\"], \"family\": row[\"family\"],\n",
    "        } for source, passage in passages.items())\n",
    "    return docs\n",
    "\n",
    "\n",
    "def _case(row, variant):\n",
    "    asset = row[\"asset\"]\n",
    "    wrappers = (\n",
    "        \"{}\", \"Please help. {}\", \"Ticket intake: {}\", \"Shift note. {}\", \"Quick question: {}\",\n",
    "        \"Could you check this? {}\", \"{} Thanks.\", \"Facilities desk: {}\", \"I need a record check. {}\", \"Operator message: {}\",\n",
    "    )\n",
    "    category = row[\"slice\"]\n",
    "    wording = {\n",
    "        \"manual\": (f\"What is the maximum temperature for {asset}?\", f\"What's the thermal limit, in C, of {asset}?\"),\n",
    "        \"numeric\": (f\"When was {asset} last inspected?\", f\"Give the last inspection date for {asset}.\"),\n",
    "        \"multi_source\": (f\"Give the last inspection date and supporting system for {asset}.\",\n",
    "                         f\"For {asset}, which system supports it and when was its most recent inspection?\"),\n",
    "        \"ambiguity\": (\"What is the maximum temperature for that unit?\", \"When was that pump last inspected?\"),\n",
    "        \"boundary\": (f\"As a guest, show the inventory record for {asset}.\", f\"Guest request: give inspection date for {asset}.\"),\n",
    "        \"follow_up\": (\"What is its maximum temperature?\", \"And how hot can this one run?\"),\n",
    "    }\n",
    "    question = wrappers[variant].format(wording[category][variant % 2])\n",
    "    role = \"guest\" if category == \"boundary\" else \"operator\"\n",
    "    value, evidence, source = {\n",
    "        \"manual\": (str(row[\"limit\"]), [row[\"manual_id\"]], \"manual\"),\n",
    "        \"numeric\": (row[\"inspection\"], [row[\"inventory_id\"]], \"inventory\"),\n",
    "        \"multi_source\": (f\"{row['inspection']} | {row['linked']}\", [row[\"inventory_id\"], row[\"graph_id\"]], \"graph\"),\n",
    "        \"follow_up\": (str(row[\"limit\"]), [row[\"manual_id\"]], \"manual\"),\n",
    "        \"ambiguity\": (\"\", [], \"none\"),\n",
    "        \"boundary\": (\"\", [], \"none\"),\n",
    "    }[category]\n",
    "    decision = {\"ambiguity\": \"clarify\", \"boundary\": \"deny\"}.get(category, \"answer\")\n",
    "    return {\n",
    "        **row, \"id\": f\"{row['family']}-{variant:02d}\", \"question\": question, \"role\": role,\n",
    "        \"decision\": decision, \"value\": value, \"evidence\": evidence, \"source\": source,\n",
    "        \"variant\": variant, \"previous_asset\": asset if category == \"follow_up\" else \"\",\n",
    "        \"previous_version\": row[\"version\"] if category == \"follow_up\" else \"\",\n",
    "    }\n",
    "\n",
    "\n",
    "def cases(split=\"dev\"):\n",
    "    return [_case(row, variant) for row in assets(split) for variant in range(10)]\n",
    "\n",
    "\n",
    "def digest(rows):\n",
    "    serial = json.dumps(rows, ensure_ascii=False, sort_keys=True, separators=(\",\", \":\")).encode()\n",
    "    return hashlib.sha256(serial).hexdigest()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-05",
   "metadata": {},
   "source": [
    "### Preserve source authority\n",
    "\n",
    "Generate original documents and an inventory view. Parameterize the database query, set it read-only, and select only evidence that belongs to the trusted tenant."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "lab-06-06",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-27T06:27:33.110242Z",
     "iopub.status.busy": "2026-11-27T06:27:33.109947Z",
     "iopub.status.idle": "2026-11-27T06:27:33.131412Z",
     "shell.execute_reply": "2026-11-27T06:27:33.129209Z"
    }
   },
   "outputs": [],
   "source": [
    "@lru_cache\n",
    "def _inventory(split):\n",
    "    db = sqlite3.connect(\":memory:\")\n",
    "    db.row_factory = sqlite3.Row\n",
    "    db.execute(\"CREATE TABLE inventory(asset TEXT PRIMARY KEY, tenant TEXT, inspection TEXT, version TEXT)\")\n",
    "    db.executemany(\n",
    "        \"INSERT INTO inventory VALUES(:asset, :tenant, :inspection, :version)\", assets(split)\n",
    "    )\n",
    "    db.execute(\"CREATE VIEW operator_inventory AS SELECT asset, tenant, inspection, version FROM inventory\")\n",
    "    db.execute(\"PRAGMA query_only = ON\")\n",
    "    return db\n",
    "\n",
    "\n",
    "def read_inventory(asset, tenant, role=\"operator\", split=\"dev\"):\n",
    "    if role != \"operator\":\n",
    "        return None\n",
    "    row = _inventory(split).execute(\n",
    "        \"SELECT * FROM operator_inventory WHERE asset = ? AND tenant = ?\", (asset, tenant)\n",
    "    ).fetchone()\n",
    "    return dict(row) if row is not None else None\n",
    "\n",
    "\n",
    "def safe_context(case, split=\"dev\"):\n",
    "    if case[\"role\"] != \"operator\" or case.get(\"tenant\") not in TENANTS:\n",
    "        return \"\"\n",
    "    if case[\"slice\"] == \"ambiguity\":\n",
    "        return \"\"\n",
    "    asset_id = case.get(\"previous_asset\") if case[\"slice\"] == \"follow_up\" else case[\"asset\"]\n",
    "    source_ids = {\n",
    "        d[f\"{source}_id\"]\n",
    "        for d in assets(split) if d[\"asset\"] == asset_id and d[\"tenant\"] == case[\"tenant\"]\n",
    "        for source in (\"manual\", \"inventory\", \"graph\")\n",
    "    }\n",
    "    return \"\\n\".join(f\"[{doc['id']}] {doc['text']}\" for doc in corpus(split) if doc[\"id\"] in source_ids)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-07",
   "metadata": {},
   "source": [
    "### Score the outcome\n",
    "\n",
    "A correct decision still needs the right value and complete evidence. Use a paired bootstrap over equipment families when comparing two systems."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "lab-06-08",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-27T06:27:33.136967Z",
     "iopub.status.busy": "2026-11-27T06:27:33.136709Z",
     "iopub.status.idle": "2026-11-27T06:27:33.151866Z",
     "shell.execute_reply": "2026-11-27T06:27:33.151251Z"
    }
   },
   "outputs": [],
   "source": [
    "def score_answer(case, answer):\n",
    "    if not isinstance(answer, dict) or not isinstance(answer.get(\"evidence\"), list):\n",
    "        return 0\n",
    "    evidence = answer[\"evidence\"]\n",
    "    return int(\n",
    "        answer.get(\"decision\") == case[\"decision\"]\n",
    "        and isinstance(answer.get(\"value\"), str)\n",
    "        and answer[\"value\"].strip() == case[\"value\"]\n",
    "        and all(isinstance(item, str) for item in evidence)\n",
    "        and sorted(evidence) == sorted(case[\"evidence\"])\n",
    "    )\n",
    "\n",
    "\n",
    "def paired_interval(cases, candidate, incumbent, draws=1500):\n",
    "    if len(cases) != len(candidate) or len(cases) != len(incumbent) or not cases:\n",
    "        raise ValueError(\"Expected equal-length nonempty case and score arrays.\")\n",
    "    groups = {}\n",
    "    for case, new, old in zip(cases, candidate, incumbent):\n",
    "        groups.setdefault(case[\"family\"], []).append(int(new) - int(old))\n",
    "    summaries = [(sum(values), len(values)) for values in groups.values()]\n",
    "    rng = random.Random(401)\n",
    "    estimates = []\n",
    "    for _ in range(draws):\n",
    "        sampled = rng.choices(summaries, k=len(summaries))\n",
    "        estimates.append(sum(total for total, _ in sampled) / sum(n for _, n in sampled))\n",
    "    estimates.sort()\n",
    "    return {\n",
    "        \"delta\": sum(total for total, _ in summaries) / len(cases),\n",
    "        \"low\": estimates[int(draws * .025)],\n",
    "        \"high\": estimates[int(draws * .975) - 1],\n",
    "        \"n\": len(cases), \"families\": len(summaries),\n",
    "    }\n",
    "\n",
    "\n",
    "def decode_answer(text):\n",
    "    try:\n",
    "        answer = json.loads(text.strip())\n",
    "    except (AttributeError, ValueError):\n",
    "        return {}\n",
    "    return answer if isinstance(answer, dict) else {}\n",
    "\n",
    "\n",
    "def answer_prompt(case, context):\n",
    "    previous = case.get(\"previous_asset\") or \"none\"\n",
    "    return (\n",
    "        \"You are a facilities helpdesk. Use only the supplied records. Decide answer, clarify, or deny. \"\n",
    "        \"Deny requests from a guest. Clarify when the equipment is unspecified and no previous equipment is listed. \"\n",
    "        \"Output exactly one JSON object with keys decision, value and evidence. For deny or clarify use an empty \"\n",
    "        \"value and evidence array. Use the exact record text for dates or identifiers and an integer-as-string \"\n",
    "        \"for temperatures. When asked for both inspection and supporting system, return DATE | SYSTEM. \"\n",
    "        \"For an answer include only supporting record IDs in evidence.\\n\"\n",
    "        f\"Role: {case['role']}\\nPrevious equipment: {previous}\\nRequest: {case['question']}\\n\"\n",
    "        f\"Records:\\n{context or '(none)'}\"\n",
    "    )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-09",
   "metadata": {},
   "source": [
    "### Record the runtime and evidence\n",
    "\n",
    "The model checkpoints are fixed. Local smoke mode uses offline fixtures to exercise the notebook code path. It cannot produce GPU measurements."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "lab-06-10",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-27T06:27:33.155297Z",
     "iopub.status.busy": "2026-11-27T06:27:33.154997Z",
     "iopub.status.idle": "2026-11-27T06:27:43.289030Z",
     "shell.execute_reply": "2026-11-27T06:27:43.288233Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Evidence saved to evidence/runtime.json\n",
      "{\n",
      "  \"device\": \"Tesla T4\",\n",
      "  \"python\": \"3.13.16\",\n",
      "  \"platform\": \"Linux\",\n",
      "  \"packages\": {\n",
      "    \"torch\": \"2.14.1+cu130\",\n",
      "    \"transformers\": \"4.51.3\",\n",
      "    \"accelerate\": \"1.6.0\",\n",
      "    \"numpy\": \"2.4.6\",\n",
      "    \"scikit-learn\": \"1.6.1\",\n",
      "    \"matplotlib\": \"3.10.0\",\n",
      "    \"bitsandbytes\": \"0.49.0\",\n",
      "    \"sentence-transformers\": \"4.1.0\"\n",
      "  },\n",
      "  \"smoke\": false,\n",
      "  \"cuda\": \"13.0\",\n",
      "  \"memory_bytes\": 15637086208,\n",
      "  \"capability\": [\n",
      "    7,\n",
      "    5\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "def _convert(value):\n",
    "    if hasattr(value, \"tolist\"):\n",
    "        return value.tolist()\n",
    "    if hasattr(value, \"item\"):\n",
    "        return value.item()\n",
    "    if isinstance(value, Path):\n",
    "        return str(value)\n",
    "    raise TypeError(type(value).__name__)\n",
    "\n",
    "\n",
    "def save(name, value):\n",
    "    output = Path(\"evidence\")\n",
    "    output.mkdir(exist_ok=True)\n",
    "    path = output / f\"{name}.json\"\n",
    "    path.write_text(json.dumps(value, indent=2, ensure_ascii=False, default=_convert, allow_nan=False) + \"\\n\")\n",
    "    print(f\"Evidence saved to {path}\")\n",
    "    return path\n",
    "\n",
    "\n",
    "def chart(title, labels, values, unit):\n",
    "    import matplotlib.pyplot as plt\n",
    "    import numpy as np\n",
    "    from matplotlib.ticker import PercentFormatter\n",
    "\n",
    "    values = np.asarray(values, dtype=float)\n",
    "    positions = np.arange(len(labels))\n",
    "    palette = (\"#3d6b5b\", \"#298876\", \"#7b97a2\", \"#9c6951\")\n",
    "    paper, ink, line = \"#f5f7f2\", \"#20382f\", \"#d3ded6\"\n",
    "    readable = [label.replace(\"_\", \" \") for label in labels]\n",
    "    fig, axes = plt.subplots(figsize=(8.1, max(2.55, .48 * len(labels) + 1.7)), layout=\"constrained\")\n",
    "    fig.patch.set_facecolor(paper)\n",
    "    axes.set_facecolor(paper)\n",
    "    bars = axes.barh(positions, values, height=.55, color=[palette[i % len(palette)] for i in positions])\n",
    "    axes.set_yticks(positions, labels=readable)\n",
    "    axes.invert_yaxis()\n",
    "    fraction = unit.casefold() == \"fraction\"\n",
    "    if fraction:\n",
    "        axes.xaxis.set_major_formatter(PercentFormatter(xmax=1, decimals=0))\n",
    "    axes.set_xlabel(\"Share of cases\" if fraction else unit, color=ink, loc=\"left\", labelpad=8)\n",
    "    axes.set_title(title, loc=\"left\", color=ink, weight=\"semibold\", pad=15, fontsize=16)\n",
    "    axes.set_axisbelow(True)\n",
    "    axes.grid(axis=\"x\", color=line, linewidth=.75)\n",
    "    axes.spines[[\"top\", \"right\", \"left\", \"bottom\"]].set_visible(False)\n",
    "    axes.tick_params(axis=\"both\", length=0, colors=ink, pad=5)\n",
    "    finite = values[np.isfinite(values)]\n",
    "    if len(finite):\n",
    "        left, right = min(0.0, finite.min()), max(0.0, finite.max())\n",
    "        span = right - left or 1.0\n",
    "        axes.set_xlim(left - (.15 * span if left < 0 else 0), right + .18 * span)\n",
    "        for bar, value in zip(bars, values):\n",
    "            if not np.isfinite(value):\n",
    "                continue\n",
    "            center = bar.get_y() + bar.get_height() / 2\n",
    "            if value == 0:\n",
    "                axes.scatter([0], [center], s=14, color=ink, clip_on=False, zorder=3)\n",
    "            formatted = f\"{value:.1%}\" if fraction else f\"{value:,.3g}\"\n",
    "            axes.annotate(formatted, (value, center), xytext=(6 if value >= 0 else -6, 0), textcoords=\"offset points\",\n",
    "                          ha=\"left\" if value >= 0 else \"right\", va=\"center\", color=ink, fontsize=10)\n",
    "    target = Path(\"evidence\") / (re.sub(r\"[^a-z0-9]+\", \"-\", title.lower()).strip(\"-\") + \".svg\")\n",
    "    target.parent.mkdir(exist_ok=True)\n",
    "    fig.savefig(target)\n",
    "    plt.show()\n",
    "    plt.close(fig)\n",
    "\n",
    "import importlib.metadata\n",
    "import platform\n",
    "import sys\n",
    "import time\n",
    "\n",
    "COURSE_SMOKE = os.environ.get(\"COURSE_SMOKE\") == \"1\"\n",
    "HAS_MODEL_RUNTIME = not COURSE_SMOKE and LAB_NUMBER != 10\n",
    "if HAS_MODEL_RUNTIME:\n",
    "    import torch\n",
    "    from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig\n",
    "\n",
    "\n",
    "def device_name():\n",
    "    if COURSE_SMOKE:\n",
    "        return \"CPU smoke\"\n",
    "    if not HAS_MODEL_RUNTIME:\n",
    "        return \"CPU\"\n",
    "    return torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"CPU\"\n",
    "\n",
    "\n",
    "def sync():\n",
    "    if HAS_MODEL_RUNTIME and torch.cuda.is_available():\n",
    "        torch.cuda.synchronize()\n",
    "\n",
    "\n",
    "def load_text(quant=False):\n",
    "    if not HAS_MODEL_RUNTIME:\n",
    "        raise RuntimeError(\"Use a fixture explicitly inside the CPU smoke lane.\")\n",
    "    repo, revision = MODEL_IDS[\"text\"]\n",
    "    tokenizer = AutoTokenizer.from_pretrained(repo, revision=revision, padding_side=\"left\")\n",
    "    options = {\"revision\": revision, \"attn_implementation\": \"sdpa\"}\n",
    "    if torch.cuda.is_available():\n",
    "        options.update(torch_dtype=torch.float16, device_map={\"\": 0})\n",
    "    else:\n",
    "        options.update(torch_dtype=torch.float32)\n",
    "    if quant:\n",
    "        if not torch.cuda.is_available():\n",
    "            raise RuntimeError(\"NF4 comparison requires CUDA.\")\n",
    "        options[\"quantization_config\"] = BitsAndBytesConfig(\n",
    "            load_in_4bit=True, bnb_4bit_quant_type=\"nf4\", bnb_4bit_compute_dtype=torch.float16,\n",
    "        )\n",
    "    return tokenizer, AutoModelForCausalLM.from_pretrained(repo, **options).eval()\n",
    "\n",
    "\n",
    "def generate(tokenizer, model, prompts, max_new_tokens=48, temperature=0.0, **kwargs):\n",
    "    rendered = [\n",
    "        tokenizer.apply_chat_template([{\"role\": \"user\", \"content\": p}], tokenize=False, add_generation_prompt=True)\n",
    "        for p in prompts\n",
    "    ]\n",
    "    tokens = tokenizer(rendered, return_tensors=\"pt\", padding=True, add_special_tokens=False).to(model.device)\n",
    "    sampling = {\"do_sample\": True, \"temperature\": temperature} if temperature > 0 else {\"do_sample\": False}\n",
    "    with torch.inference_mode():\n",
    "        output = model.generate(\n",
    "            **tokens, max_new_tokens=max_new_tokens, pad_token_id=tokenizer.pad_token_id,\n",
    "            **sampling, **kwargs,\n",
    "        )\n",
    "    return tokenizer.batch_decode(output[:, tokens.input_ids.shape[1]:], skip_special_tokens=True)\n",
    "\n",
    "\n",
    "def write_receipt():\n",
    "    versions = {}\n",
    "    for package in (\"torch\", \"transformers\", \"accelerate\", \"numpy\", \"scikit-learn\", \"matplotlib\", \"bitsandbytes\", \"sentence-transformers\"):\n",
    "        try:\n",
    "            versions[package] = importlib.metadata.version(package)\n",
    "        except importlib.metadata.PackageNotFoundError:\n",
    "            pass\n",
    "    receipt = {\n",
    "        \"device\": device_name(), \"python\": sys.version.split()[0], \"platform\": platform.system(),\n",
    "        \"packages\": versions, \"smoke\": COURSE_SMOKE,\n",
    "    }\n",
    "    if HAS_MODEL_RUNTIME and torch.cuda.is_available():\n",
    "        props = torch.cuda.get_device_properties(0)\n",
    "        receipt.update(cuda=torch.version.cuda, memory_bytes=props.total_memory, capability=list(torch.cuda.get_device_capability(0)))\n",
    "    save(\"runtime\", receipt)\n",
    "    print(json.dumps(receipt, indent=2))\n",
    "    return receipt\n",
    "\n",
    "if 'get_ipython' in globals() and get_ipython() is not None:\n",
    "    from matplotlib_inline.backend_inline import set_matplotlib_formats\n",
    "    set_matplotlib_formats('svg')\n",
    "hardware = write_receipt()\n",
    "if True and os.environ.get('COURSE_T4') == '1':\n",
    "    assert 'T4' in hardware['device'], f\"Expected T4, got {hardware['device']}\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-11",
   "metadata": {},
   "source": [
    "# Choose an evidence source\n",
    "\n",
    "The operator asks “What is its maximum temperature?” after viewing fan F-250.\n",
    "You have the manual, an inventory view and an equipment graph. Which source\n",
    "can support the temperature? What changes if the saved manual revision is old?\n",
    "[Read Lesson 6](https://docs.recohut.com/courses/advanced-ai-systems-engineering/2-build-the-evidence-layer/06-choose-an-evidence-source).\n",
    "\n",
    "The notebook tests document ordering on the same requests with the same model.\n",
    "It also reads exact inspection dates from a fixed SQLite view and combines a\n",
    "row and a graph edge when the operator asks which system supports the asset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "lab-06-12",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-27T06:27:43.294720Z",
     "iopub.status.busy": "2026-11-27T06:27:43.294169Z",
     "iopub.status.idle": "2026-11-27T06:27:43.315468Z",
     "shell.execute_reply": "2026-11-27T06:27:43.314642Z"
    }
   },
   "outputs": [],
   "source": [
    "import re\n",
    "from collections import defaultdict\n",
    "from statistics import median\n",
    "from time import perf_counter\n",
    "\n",
    "EVIDENCE_TOKEN_BUDGET = 112\n",
    "OUTPUT_TOKEN_BUDGET = 100\n",
    "MANUAL_BATCH_SIZE = 4\n",
    "MANUAL_METHODS = (\"Corpus prefix\", \"Exact ID first\", \"All tenant manuals\")\n",
    "ROUTED_METHODS = (\"Routed · corpus prefix\", \"Routed · exact ID first\", \"Routed · all manuals\")\n",
    "ROUTE_BY_SLICE = {\n",
    "    \"manual\": \"manual\",\n",
    "    \"numeric\": \"SQL\",\n",
    "    \"multi_source\": \"graph + SQL\",\n",
    "    \"ambiguity\": \"clarify\",\n",
    "    \"boundary\": \"deny\",\n",
    "    \"follow_up\": \"manual\",\n",
    "}\n",
    "ASSET_ID = re.compile(r\"\\b[PFV]-\\d+\\b\", re.IGNORECASE)\n",
    "\n",
    "manuals_by_tenant = defaultdict(list)\n",
    "edges_by_tenant = defaultdict(dict)\n",
    "asset_index = {}\n",
    "for equipment in assets(\"dev\"):\n",
    "    tenant = equipment[\"tenant\"]\n",
    "    asset_index[tenant, equipment[\"asset\"]] = equipment\n",
    "    edges_by_tenant[tenant][equipment[\"asset\"]] = {\n",
    "        \"target\": equipment[\"linked\"], \"type\": \"supported_by\", \"evidence\": equipment[\"graph_id\"]\n",
    "    }\n",
    "for document in corpus(\"dev\"):\n",
    "    if document[\"source\"] == \"manual\":\n",
    "        manuals_by_tenant[document[\"tenant\"]].append(document)\n",
    "\n",
    "\n",
    "def no_answer(decision):\n",
    "    return {\"decision\": decision, \"value\": \"\", \"evidence\": []}\n",
    "\n",
    "\n",
    "def select_route(question, role, tenant, previous_asset=\"\", previous_version=\"\"):\n",
    "    \"\"\"Resolve the trusted scope and one current equipment ID before lookup.\"\"\"\n",
    "    if role != \"operator\" or tenant not in manuals_by_tenant:\n",
    "        return \"deny\", None\n",
    "    matches = {match.upper() for match in ASSET_ID.findall(question)}\n",
    "    if len(matches) > 1:\n",
    "        return \"clarify\", None\n",
    "    asset_id = next(iter(matches), previous_asset)\n",
    "    equipment = asset_index.get((tenant, asset_id))\n",
    "    if equipment is None or (not matches and previous_version != equipment[\"version\"]):\n",
    "        return \"clarify\", None\n",
    "    request = question.casefold()\n",
    "    if \"support\" in request:\n",
    "        return (\"graph + SQL\" if \"inspect\" in request else \"graph\"), equipment\n",
    "    if \"inspect\" in request:\n",
    "        return \"SQL\", equipment\n",
    "    if any(term in request for term in (\"temperature\", \"thermal limit\", \"how hot\")):\n",
    "        return \"manual\", equipment\n",
    "    return \"clarify\", None\n",
    "\n",
    "\n",
    "def structured_answer(route, equipment, role, tenant):\n",
    "    if route in {\"deny\", \"clarify\"}:\n",
    "        return no_answer(route), {}\n",
    "    if role != \"operator\" or equipment[\"tenant\"] != tenant:\n",
    "        return no_answer(\"deny\"), {}\n",
    "    asset_id = equipment[\"asset\"]\n",
    "    inventory = read_inventory(asset_id, tenant, role) if route in {\"SQL\", \"graph + SQL\"} else None\n",
    "    relation = edges_by_tenant[tenant].get(asset_id) if route in {\"graph\", \"graph + SQL\"} else None\n",
    "    if ((route in {\"SQL\", \"graph + SQL\"} and not inventory)\n",
    "            or (route in {\"graph\", \"graph + SQL\"} and not relation)):\n",
    "        return no_answer(\"clarify\"), {}\n",
    "\n",
    "    reads = {}\n",
    "    values, evidence = [], []\n",
    "    if inventory:\n",
    "        reads[\"inventory\"] = {\"row\": inventory, \"evidence\": equipment[\"inventory_id\"]}\n",
    "        values.append(inventory[\"inspection\"])\n",
    "        evidence.append(equipment[\"inventory_id\"])\n",
    "    if relation:\n",
    "        reads[\"graph\"] = relation\n",
    "        values.append(relation[\"target\"])\n",
    "        evidence.append(relation[\"evidence\"])\n",
    "    return {\"decision\": \"answer\", \"value\": \" | \".join(values), \"evidence\": evidence}, reads"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-13",
   "metadata": {},
   "source": [
    "## Does the desk have a current reference?\n",
    "\n",
    "Keep the request and signed-in role fixed. Before reading the source,\n",
    "predict which route the desk should choose if the saved F-250 revision\n",
    "differs from the current one. The inventory view supplies exact dates.\n",
    "The graph supplies one typed edge. Both reads use the trusted tenant."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "lab-06-14",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-27T06:27:43.321487Z",
     "iopub.status.busy": "2026-11-27T06:27:43.319960Z",
     "iopub.status.idle": "2026-11-27T06:27:43.344907Z",
     "shell.execute_reply": "2026-11-27T06:27:43.344088Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "One changed field {'case_id': 'F250-00', 'question': 'What is its maximum temperature?', 'role': 'operator', 'tenant': 'north-yard', 'asset': 'F-250', 'manual': {'id': 'manual-F-250-r3', 'source': 'manual', 'text': 'Equipment manual for F-250 (revision r3). Maximum operating temperature: 101 C. Known fault: filter blockage. The supporting system is S-650. Maintenance owner: controls.', 'tenant': 'north-yard', 'family': 'F250'}, 'current': {'revision': 'r3', 'route': 'manual', 'expected': {'decision': 'answer', 'value': '101', 'evidence': ['manual-F-250-r3']}}, 'stale': {'revision': 'r2', 'route': 'clarify', 'expected': {'decision': 'clarify', 'value': '', 'evidence': []}}}\n",
      "One request needs two sources {'question': 'Give the last inspection date and supporting system for F-220.', 'sources': {'inventory': {'row': {'asset': 'F-220', 'tenant': 'north-yard', 'inspection': '2025-05-05', 'version': 'r3'}, 'evidence': 'inventory-F-220-r3'}, 'graph': {'target': 'S-620', 'type': 'supported_by', 'evidence': 'graph-F-220-r3'}}, 'expected': {'decision': 'answer', 'value': '2025-05-05 | S-620', 'evidence': ['inventory-F-220-r3', 'graph-F-220-r3']}, 'returned': {'decision': 'answer', 'value': '2025-05-05 | S-620', 'evidence': ['inventory-F-220-r3', 'graph-F-220-r3']}}\n"
     ]
    }
   ],
   "source": [
    "def route_case(case):\n",
    "    return select_route(case[\"question\"], case[\"role\"], case[\"tenant\"],\n",
    "                        case[\"previous_asset\"], case[\"previous_version\"])\n",
    "\n",
    "\n",
    "def expected_answer(case):\n",
    "    return {field: case[field] for field in (\"decision\", \"value\", \"evidence\")}\n",
    "\n",
    "\n",
    "dev_cases = [case for case in cases(\"dev\") if case[\"variant\"] in {0, 3}]\n",
    "assert len(dev_cases) == 2 * len(asset_index)\n",
    "assert {case[\"slice\"] for case in dev_cases} == set(SLICES)\n",
    "assert SPLIT_MANIFEST[\"dev\"][\"sha256\"] == digest(cases(\"dev\"))\n",
    "opening_case = next(case for case in dev_cases if case[\"id\"] == \"F250-00\")\n",
    "opening_route, opening_equipment = route_case(opening_case)\n",
    "stale_revision = \"r2\"\n",
    "assert opening_equipment[\"version\"] != stale_revision\n",
    "stale_case = {**opening_case, \"previous_version\": stale_revision}\n",
    "stale_route, stale_equipment = route_case(stale_case)\n",
    "opening_manual = next(doc for doc in manuals_by_tenant[opening_case[\"tenant\"]]\n",
    "                      if doc[\"id\"] == opening_equipment[\"manual_id\"])\n",
    "assert opening_route == \"manual\"\n",
    "assert (stale_route, stale_equipment) == (\"clarify\", None)\n",
    "opening = {\n",
    "    \"case_id\": opening_case[\"id\"], \"question\": opening_case[\"question\"],\n",
    "    \"role\": opening_case[\"role\"], \"tenant\": opening_case[\"tenant\"],\n",
    "    \"asset\": opening_case[\"previous_asset\"], \"manual\": opening_manual,\n",
    "    \"current\": {\"revision\": opening_case[\"previous_version\"], \"route\": opening_route,\n",
    "                \"expected\": expected_answer(opening_case)},\n",
    "    \"stale\": {\"revision\": stale_revision, \"route\": stale_route, \"expected\": no_answer(\"clarify\")},\n",
    "}\n",
    "\n",
    "multi_case = next(case for case in dev_cases if case[\"slice\"] == \"multi_source\")\n",
    "multi_route, multi_equipment = route_case(multi_case)\n",
    "multi_answer, multi_sources = structured_answer(multi_route, multi_equipment,\n",
    "                                               multi_case[\"role\"], multi_case[\"tenant\"])\n",
    "assert score_answer(multi_case, multi_answer) == 1\n",
    "graph_route, graph_equipment = select_route(\"Which system supports F-250?\", \"operator\", opening_case[\"tenant\"])\n",
    "assert graph_route == \"graph\"\n",
    "graph_answer, graph_sources = structured_answer(graph_route, graph_equipment, \"operator\", opening_case[\"tenant\"])\n",
    "assert graph_answer == {\"decision\": \"answer\", \"value\": opening_equipment[\"linked\"],\n",
    "                        \"evidence\": [opening_equipment[\"graph_id\"]]}\n",
    "assert set(graph_sources) == {\"graph\"}\n",
    "assert route_case(next(case for case in dev_cases if case[\"slice\"] == \"boundary\")) == (\"deny\", None)\n",
    "other_tenant = next(tenant for tenant in manuals_by_tenant if tenant != opening_case[\"tenant\"])\n",
    "assert select_route(\"What is the maximum temperature for F-250?\", \"operator\", other_tenant) == (\"clarify\", None)\n",
    "assert structured_answer(multi_route, multi_equipment, \"guest\", multi_case[\"tenant\"])[0] == no_answer(\"deny\")\n",
    "print(\"One changed field\", opening)\n",
    "print(\"One request needs two sources\", {\"question\": multi_case[\"question\"], \"sources\": multi_sources,\n",
    "                                      \"expected\": expected_answer(multi_case), \"returned\": multi_answer})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-15",
   "metadata": {},
   "source": [
    "## Which manual survives the token budget?\n",
    "\n",
    "“Corpus prefix” keeps the first evidence tokens in corpus order. “Exact ID\n",
    "first” puts the verified asset’s current manual first and applies the same\n",
    "ceiling. This tests the effect of ordering. “All tenant manuals” keeps the\n",
    "whole scoped corpus and exposes the cost of removing that ceiling.\n",
    "\n",
    "Look for both the manual ID and its temperature line together. A source ID on\n",
    "its own can survive clipping after the relevant value has been lost."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "lab-06-16",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-27T06:27:43.349078Z",
     "iopub.status.busy": "2026-11-27T06:27:43.348751Z",
     "iopub.status.idle": "2026-11-27T06:27:43.368779Z",
     "shell.execute_reply": "2026-11-27T06:27:43.367952Z"
    }
   },
   "outputs": [],
   "source": [
    "def build_manual_context(equipment, method, tokenizer):\n",
    "    primary = equipment[\"manual_id\"]\n",
    "    entries = manuals_by_tenant[equipment[\"tenant\"]]\n",
    "    if method == \"Exact ID first\":\n",
    "        entries = sorted(entries, key=lambda doc: doc[\"id\"] != primary)\n",
    "    context = \"\\n\".join(f'[{doc[\"id\"]}] {doc[\"text\"]}' for doc in entries)\n",
    "    all_ids = tokenizer.encode(context, add_special_tokens=False)\n",
    "    visible_ids = all_ids if method == \"All tenant manuals\" else all_ids[:EVIDENCE_TOKEN_BUDGET]\n",
    "    visible = tokenizer.decode(visible_ids)\n",
    "    support = f'[{primary}] {manual_text(equipment).partition(\" Known fault:\")[0]}'\n",
    "    return {\n",
    "        \"context\": visible,\n",
    "        \"evidence_tokens\": len(visible_ids),\n",
    "        \"discarded_tokens\": len(all_ids) - len(visible_ids),\n",
    "        \"support_visible\": support in visible,\n",
    "    }\n",
    "\n",
    "\n",
    "def input_token_count(tokenizer, prompt):\n",
    "    rendered = tokenizer.apply_chat_template(\n",
    "        [{\"role\": \"user\", \"content\": prompt}], tokenize=False, add_generation_prompt=True\n",
    "    )\n",
    "    return len(tokenizer.encode(rendered, add_special_tokens=False))\n",
    "\n",
    "\n",
    "def scored_record(case, method, route, response, context=None, raw=None, **details):\n",
    "    expected = expected_answer(case)\n",
    "    answer_evidence = response.get(\"evidence\")\n",
    "    covered = response.get(\"decision\") == \"answer\"\n",
    "    cites_expected = (covered and isinstance(answer_evidence, list)\n",
    "                     and all(isinstance(item, str) for item in answer_evidence)\n",
    "                     and sorted(answer_evidence) == sorted(expected[\"evidence\"]))\n",
    "    answer_value = response.get(\"value\")\n",
    "    exact_value = isinstance(answer_value, str) and answer_value.strip() == expected[\"value\"]\n",
    "    strict = score_answer(case, response)\n",
    "    if strict:\n",
    "        outcome = \"Pass\"\n",
    "    elif raw is not None and not response:\n",
    "        outcome = \"No usable JSON object\"\n",
    "    elif response.get(\"decision\") != expected[\"decision\"]:\n",
    "        outcome = \"Wrong decision\"\n",
    "    elif not exact_value:\n",
    "        outcome = \"Wrong value\"\n",
    "    else:\n",
    "        outcome = \"Wrong evidence\"\n",
    "    return {\n",
    "        \"case_id\": case[\"id\"], \"family\": case[\"family\"], \"slice\": case[\"slice\"],\n",
    "        \"question\": case[\"question\"], \"role\": case[\"role\"], \"tenant\": case[\"tenant\"],\n",
    "        \"previous_asset\": case[\"previous_asset\"], \"previous_version\": case[\"previous_version\"],\n",
    "        \"method\": method, \"expected_route\": ROUTE_BY_SLICE[case[\"slice\"]], \"route\": route,\n",
    "        \"expected\": expected, \"response\": response, \"raw\": raw,\n",
    "        \"route_error\": route != ROUTE_BY_SLICE[case[\"slice\"]], \"covered\": covered,\n",
    "        \"citation_support\": cites_expected if expected[\"decision\"] == \"answer\" else None,\n",
    "        \"exact_value\": exact_value if expected[\"decision\"] == \"answer\" else None,\n",
    "        \"strict_pass\": strict, \"outcome\": outcome,\n",
    "        **(context or {}), **details,\n",
    "    }\n",
    "\n",
    "\n",
    "manual_cases, cpu_records, structured_ablation = [], [], []\n",
    "for case in dev_cases:\n",
    "    route, equipment = route_case(case)\n",
    "    if route == \"manual\":\n",
    "        manual_cases.append((case, equipment))\n",
    "        continue\n",
    "    answer, sources = structured_answer(route, equipment, case[\"role\"], case[\"tenant\"])\n",
    "    cpu_records.append(scored_record(case, \"Shared structured routes\", route, answer, sources=sources))\n",
    "    if route == \"graph + SQL\":\n",
    "        for method in (\"SQL\", \"graph\", \"graph + SQL\"):\n",
    "            output, reads = structured_answer(method, equipment, case[\"role\"], case[\"tenant\"])\n",
    "            structured_ablation.append(scored_record(case, method, method, output, sources=reads))\n",
    "\n",
    "assert len(manual_cases) + len(cpu_records) == len(dev_cases)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-17",
   "metadata": {},
   "source": [
    "## Compare answer quality, generation time and GPU memory\n",
    "\n",
    "The manual arms use the same frozen model, prompts apart from the supplied\n",
    "evidence, batch membership and generation cap. An excluded warm-up runs\n",
    "before timing. Each timed batch includes tokenisation, generation and\n",
    "decoding. Peak allocated GPU memory includes the loaded model. Prompt\n",
    "tokens count the unpadded rendered input, and output-text token counts\n",
    "re-tokenise the decoded reply without special tokens."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "lab-06-18",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-27T06:27:43.373579Z",
     "iopub.status.busy": "2026-11-27T06:27:43.373223Z",
     "iopub.status.idle": "2026-11-27T06:28:48.691087Z",
     "shell.execute_reply": "2026-11-27T06:28:48.688029Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.13/dist-packages/huggingface_hub/utils/_auth.py:104: UserWarning: \n",
      "Error while fetching `HF_TOKEN` secret value from your vault: 'Requesting secret HF_TOKEN timed out. Secrets can only be fetched when running from the Colab UI.'.\n",
      "You are not authenticated with the Hugging Face Hub in this notebook.\n",
      "If the error persists, please let us know by opening an issue on GitHub (https://github.com/huggingface/huggingface_hub/issues/new).\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Sliding Window Attention is enabled but not implemented for `sdpa`; unexpected results may be encountered.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.13/dist-packages/transformers/generation/configuration_utils.py:631: UserWarning: `do_sample` is set to `False`. However, `temperature` is set to `0.7` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `temperature`.\n",
      "  warnings.warn(\n",
      "/usr/local/lib/python3.13/dist-packages/transformers/generation/configuration_utils.py:636: UserWarning: `do_sample` is set to `False`. However, `top_p` is set to `0.8` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `top_p`.\n",
      "  warnings.warn(\n",
      "/usr/local/lib/python3.13/dist-packages/transformers/generation/configuration_utils.py:653: UserWarning: `do_sample` is set to `False`. However, `top_k` is set to `20` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `top_k`.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.13/dist-packages/transformers/generation/configuration_utils.py:631: UserWarning: `do_sample` is set to `False`. However, `temperature` is set to `0.7` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `temperature`.\n",
      "  warnings.warn(\n",
      "/usr/local/lib/python3.13/dist-packages/transformers/generation/configuration_utils.py:636: UserWarning: `do_sample` is set to `False`. However, `top_p` is set to `0.8` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `top_p`.\n",
      "  warnings.warn(\n",
      "/usr/local/lib/python3.13/dist-packages/transformers/generation/configuration_utils.py:653: UserWarning: `do_sample` is set to `False`. However, `top_k` is set to `20` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `top_k`.\n",
      "  warnings.warn(\n"
     ]
    }
   ],
   "source": [
    "manual_records, batch_timings, model_load_s = [], [], None\n",
    "if not COURSE_SMOKE:\n",
    "    started = perf_counter()\n",
    "    tokenizer, model = load_text()\n",
    "    sync()\n",
    "    model_load_s = perf_counter() - started\n",
    "\n",
    "    prepared = {}\n",
    "    for method in MANUAL_METHODS:\n",
    "        rows = []\n",
    "        for case, equipment in manual_cases:\n",
    "            context = build_manual_context(equipment, method, tokenizer)\n",
    "            prompt = answer_prompt(case, context[\"context\"])\n",
    "            rows.append((case, context, prompt, input_token_count(tokenizer, prompt)))\n",
    "        prepared[method] = rows\n",
    "\n",
    "    assert all(row[1][\"support_visible\"] for row in prepared[\"Exact ID first\"])\n",
    "    assert all(row[1][\"support_visible\"] for row in prepared[\"All tenant manuals\"])\n",
    "    assert all(\n",
    "        a[1][\"evidence_tokens\"] == b[1][\"evidence_tokens\"]\n",
    "        for a, b in zip(prepared[\"Corpus prefix\"], prepared[\"Exact ID first\"])\n",
    "    )\n",
    "\n",
    "    warmup = [row[2] for row in prepared[\"All tenant manuals\"][:MANUAL_BATCH_SIZE]]\n",
    "    generate(tokenizer, model, warmup, max_new_tokens=8)\n",
    "    sync()\n",
    "    for start in range(0, len(manual_cases), MANUAL_BATCH_SIZE):\n",
    "        # Alternate ordering so a fixed arm does not always start each group.\n",
    "        methods = MANUAL_METHODS if (start // MANUAL_BATCH_SIZE) % 2 == 0 else MANUAL_METHODS[::-1]\n",
    "        for method in methods:\n",
    "            batch = prepared[method][start:start + MANUAL_BATCH_SIZE]\n",
    "            if torch.cuda.is_available():\n",
    "                torch.cuda.reset_peak_memory_stats()\n",
    "            sync()\n",
    "            started = perf_counter()\n",
    "            outputs = generate(tokenizer, model, [row[2] for row in batch], max_new_tokens=OUTPUT_TOKEN_BUDGET)\n",
    "            sync()\n",
    "            wall_ms = (perf_counter() - started) * 1000\n",
    "            assert len(outputs) == len(batch)\n",
    "            output_counts = [len(tokenizer.encode(raw, add_special_tokens=False)) for raw in outputs]\n",
    "            batch_timings.append({\n",
    "                \"method\": method, \"case_ids\": [row[0][\"id\"] for row in batch], \"wall_ms\": wall_ms,\n",
    "                \"peak_allocated_bytes\": torch.cuda.max_memory_allocated() if torch.cuda.is_available() else None,\n",
    "                \"input_tokens\": sum(row[3] for row in batch), \"output_text_tokens\": sum(output_counts),\n",
    "            })\n",
    "            for (case, context, _, prompt_tokens), raw, output_tokens in zip(batch, outputs, output_counts):\n",
    "                manual_records.append(scored_record(case, method, \"manual\", decode_answer(raw),\n",
    "                    context=context, raw=raw, prompt_tokens=prompt_tokens, output_text_tokens=output_tokens))\n",
    "\n",
    "    assert len(manual_records) == len(MANUAL_METHODS) * len(manual_cases)\n",
    "else:\n",
    "    # A reversible character tokenizer makes clipping observable offline.\n",
    "    # Its fixture counts do not enter model evidence or time tables.\n",
    "    class FixtureTokenizer:\n",
    "        def encode(self, text, add_special_tokens=False):\n",
    "            return list(text)\n",
    "\n",
    "        def decode(self, tokens):\n",
    "            return \"\".join(tokens)\n",
    "\n",
    "    fixture_tokenizer = FixtureTokenizer()\n",
    "    source = build_manual_context(opening_equipment, \"Exact ID first\", fixture_tokenizer)\n",
    "    baseline = build_manual_context(opening_equipment, \"Corpus prefix\", fixture_tokenizer)\n",
    "    assert source[\"support_visible\"] and not baseline[\"support_visible\"]\n",
    "    assert source[\"evidence_tokens\"] == baseline[\"evidence_tokens\"]\n",
    "    assert build_manual_context(opening_equipment, \"All tenant manuals\", fixture_tokenizer)[\"discarded_tokens\"] == 0"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-19",
   "metadata": {},
   "source": [
    "## Did each source answer the question it was asked?\n",
    "\n",
    "The routed arms share the deterministic SQL, graph, clarification and denial\n",
    "outcomes. Only the manual context policy changes. Compare manual arms on\n",
    "their common requests and routed arms on the complete development sample.\n",
    "The paired intervals use equipment families, so rewordings of a ticket stay\n",
    "together in each draw. Report the ablation separately because it has only\n",
    "the families whose questions require two sources."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "lab-06-20",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-27T06:28:48.701991Z",
     "iopub.status.busy": "2026-11-27T06:28:48.701171Z",
     "iopub.status.idle": "2026-11-27T06:28:49.517680Z",
     "shell.execute_reply": "2026-11-27T06:28:49.515875Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Evidence comparison {'mode': 'full', 'settings': {'evidence_token_ceiling': 112, 'output_token_cap': 100, 'batch_size': 4, 'variants': [0, 3], 'bootstrap_draws': 1500, 'development_sha256': '51dbc208b6b20a620237dd76ce0a2db4f10aa75f4f8fc404121e301b8d79a0cf'}, 'cohorts': {'development_cases': 24, 'development_families': 12, 'manual_cases': 8, 'structured_cases': 16}, 'outcomes': [{'method': 'Shared structured routes', 'slice': 'numeric', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 4, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 4, 'exact_values': 4, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Shared structured routes', 'slice': 'all', 'cases': 16, 'family_count': 8, 'answerable_cases': 8, 'covered': 8, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 8, 'exact_values': 8, 'strict_passes': 16, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 16}}, {'method': 'Shared structured routes', 'slice': 'multi_source', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 4, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 4, 'exact_values': 4, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Shared structured routes', 'slice': 'ambiguity', 'cases': 4, 'family_count': 2, 'answerable_cases': 0, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Shared structured routes', 'slice': 'boundary', 'cases': 4, 'family_count': 2, 'answerable_cases': 0, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Corpus prefix', 'slice': 'manual', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}, {'method': 'Corpus prefix', 'slice': 'all', 'cases': 8, 'family_count': 4, 'answerable_cases': 8, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 8}}, {'method': 'Exact ID first', 'slice': 'manual', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}, {'method': 'Exact ID first', 'slice': 'all', 'cases': 8, 'family_count': 4, 'answerable_cases': 8, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 8}}, {'method': 'All tenant manuals', 'slice': 'manual', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}, {'method': 'All tenant manuals', 'slice': 'all', 'cases': 8, 'family_count': 4, 'answerable_cases': 8, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 8}}, {'method': 'All tenant manuals', 'slice': 'follow_up', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}, {'method': 'Exact ID first', 'slice': 'follow_up', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}, {'method': 'Corpus prefix', 'slice': 'follow_up', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}, {'method': 'Routed · corpus prefix', 'slice': 'numeric', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 4, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 4, 'exact_values': 4, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · corpus prefix', 'slice': 'all', 'cases': 24, 'family_count': 12, 'answerable_cases': 16, 'covered': 8, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 8, 'exact_values': 8, 'strict_passes': 16, 'strict_pass_rate': 0.6666666666666666, 'outcomes': {'Pass': 16, 'No usable JSON object': 8}}, {'method': 'Routed · corpus prefix', 'slice': 'multi_source', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 4, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 4, 'exact_values': 4, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · corpus prefix', 'slice': 'ambiguity', 'cases': 4, 'family_count': 2, 'answerable_cases': 0, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · corpus prefix', 'slice': 'boundary', 'cases': 4, 'family_count': 2, 'answerable_cases': 0, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · corpus prefix', 'slice': 'manual', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}, {'method': 'Routed · corpus prefix', 'slice': 'follow_up', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}, {'method': 'Routed · exact ID first', 'slice': 'numeric', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 4, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 4, 'exact_values': 4, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · exact ID first', 'slice': 'all', 'cases': 24, 'family_count': 12, 'answerable_cases': 16, 'covered': 8, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 8, 'exact_values': 8, 'strict_passes': 16, 'strict_pass_rate': 0.6666666666666666, 'outcomes': {'Pass': 16, 'No usable JSON object': 8}}, {'method': 'Routed · exact ID first', 'slice': 'multi_source', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 4, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 4, 'exact_values': 4, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · exact ID first', 'slice': 'ambiguity', 'cases': 4, 'family_count': 2, 'answerable_cases': 0, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · exact ID first', 'slice': 'boundary', 'cases': 4, 'family_count': 2, 'answerable_cases': 0, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · exact ID first', 'slice': 'manual', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}, {'method': 'Routed · exact ID first', 'slice': 'follow_up', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}, {'method': 'Routed · all manuals', 'slice': 'numeric', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 4, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 4, 'exact_values': 4, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · all manuals', 'slice': 'all', 'cases': 24, 'family_count': 12, 'answerable_cases': 16, 'covered': 8, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 8, 'exact_values': 8, 'strict_passes': 16, 'strict_pass_rate': 0.6666666666666666, 'outcomes': {'Pass': 16, 'No usable JSON object': 8}}, {'method': 'Routed · all manuals', 'slice': 'multi_source', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 4, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 4, 'exact_values': 4, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · all manuals', 'slice': 'ambiguity', 'cases': 4, 'family_count': 2, 'answerable_cases': 0, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · all manuals', 'slice': 'boundary', 'cases': 4, 'family_count': 2, 'answerable_cases': 0, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}, {'method': 'Routed · all manuals', 'slice': 'manual', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}, {'method': 'Routed · all manuals', 'slice': 'follow_up', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 0, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'No usable JSON object': 4}}], 'structured_ablation': [{'method': 'SQL', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 4, 'route_errors': 4, 'route_accuracy': 0.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'Wrong value': 4}}, {'method': 'graph', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 4, 'route_errors': 4, 'route_accuracy': 0.0, 'citation_matches': 0, 'exact_values': 0, 'strict_passes': 0, 'strict_pass_rate': 0.0, 'outcomes': {'Wrong value': 4}}, {'method': 'graph + SQL', 'cases': 4, 'family_count': 2, 'answerable_cases': 4, 'covered': 4, 'route_errors': 0, 'route_accuracy': 1.0, 'citation_matches': 4, 'exact_values': 4, 'strict_passes': 4, 'strict_pass_rate': 1.0, 'outcomes': {'Pass': 4}}], 'paired_strict': [{'cohort': 'Two-source requests', 'candidate': 'graph + SQL', 'incumbent': 'SQL', 'wins': 4, 'losses': 0, 'delta': 1.0, 'low': 1.0, 'high': 1.0, 'n': 4, 'families': 2}, {'cohort': 'Two-source requests', 'candidate': 'graph + SQL', 'incumbent': 'graph', 'wins': 4, 'losses': 0, 'delta': 1.0, 'low': 1.0, 'high': 1.0, 'n': 4, 'families': 2}, {'cohort': 'Manual requests', 'candidate': 'Exact ID first', 'incumbent': 'Corpus prefix', 'wins': 0, 'losses': 0, 'delta': 0.0, 'low': 0.0, 'high': 0.0, 'n': 8, 'families': 4}, {'cohort': 'All development requests', 'candidate': 'Routed · exact ID first', 'incumbent': 'Routed · corpus prefix', 'wins': 0, 'losses': 0, 'delta': 0.0, 'low': 0.0, 'high': 0.0, 'n': 24, 'families': 12}, {'cohort': 'Manual requests', 'candidate': 'All tenant manuals', 'incumbent': 'Corpus prefix', 'wins': 0, 'losses': 0, 'delta': 0.0, 'low': 0.0, 'high': 0.0, 'n': 8, 'families': 4}, {'cohort': 'All development requests', 'candidate': 'Routed · all manuals', 'incumbent': 'Routed · corpus prefix', 'wins': 0, 'losses': 0, 'delta': 0.0, 'low': 0.0, 'high': 0.0, 'n': 24, 'families': 12}], 'manual_costs': [{'method': 'Corpus prefix', 'cases': 8, 'batches': 2, 'support_visible': 4, 'evidence_tokens_median': 112.0, 'discarded_tokens_median': 208.5, 'prompt_tokens_median': 276.5, 'output_text_tokens_median': 60.0, 'batch_wall_ms_median': 5087.280997499931, 'peak_allocated_bytes': 3205916160}, {'method': 'Exact ID first', 'cases': 8, 'batches': 2, 'support_visible': 8, 'evidence_tokens_median': 112.0, 'discarded_tokens_median': 208.5, 'prompt_tokens_median': 276.5, 'output_text_tokens_median': 61.0, 'batch_wall_ms_median': 4622.231657999862, 'peak_allocated_bytes': 3205916160}, {'method': 'All tenant manuals', 'cases': 8, 'batches': 2, 'support_visible': 8, 'evidence_tokens_median': 320.5, 'discarded_tokens_median': 0.0, 'prompt_tokens_median': 485.0, 'output_text_tokens_median': 64.0, 'batch_wall_ms_median': 6037.1492760000365, 'peak_allocated_bytes': 3285371904}], 'model_load_s': 29.644956739999998}\n",
      "Opening ticket, observed manual outputs [{'case_id': 'F250-00', 'family': 'F250', 'slice': 'follow_up', 'question': 'What is its maximum temperature?', 'role': 'operator', 'tenant': 'north-yard', 'previous_asset': 'F-250', 'previous_version': 'r3', 'method': 'All tenant manuals', 'expected_route': 'manual', 'route': 'manual', 'expected': {'decision': 'answer', 'value': '101', 'evidence': ['manual-F-250-r3']}, 'response': {}, 'raw': '```json\\n{\\n  \"decision\": \"The maximum temperature of F-250 is 101 C.\",\\n  \"value\": null,\\n  \"evidence\": [\\n    \"manual-F-250-r3\"\\n  ]\\n}\\n```', 'route_error': False, 'covered': False, 'citation_support': False, 'exact_value': False, 'strict_pass': 0, 'outcome': 'No usable JSON object', 'context': '[manual-V-200-r3] Equipment manual for V-200 (revision r3). Maximum operating temperature: 87 C. Known fault: seal wear. The supporting system is S-600. Maintenance owner: electrical.\\n[manual-P-210-r3] Equipment manual for P-210 (revision r3). Maximum operating temperature: 97 C. Known fault: filter blockage. The supporting system is S-610. Maintenance owner: mechanical.\\n[manual-F-220-r3] Equipment manual for F-220 (revision r3). Maximum operating temperature: 71 C. Known fault: seal wear. The supporting system is S-620. Maintenance owner: controls.\\n[manual-V-230-r3] Equipment manual for V-230 (revision r3). Maximum operating temperature: 81 C. Known fault: filter blockage. The supporting system is S-630. Maintenance owner: electrical.\\n[manual-P-240-r3] Equipment manual for P-240 (revision r3). Maximum operating temperature: 91 C. Known fault: seal wear. The supporting system is S-640. Maintenance owner: mechanical.\\n[manual-F-250-r3] Equipment manual for F-250 (revision r3). Maximum operating temperature: 101 C. Known fault: filter blockage. The supporting system is S-650. Maintenance owner: controls.', 'evidence_tokens': 322, 'discarded_tokens': 0, 'support_visible': True, 'prompt_tokens': 483, 'output_text_tokens': 52}, {'case_id': 'F250-00', 'family': 'F250', 'slice': 'follow_up', 'question': 'What is its maximum temperature?', 'role': 'operator', 'tenant': 'north-yard', 'previous_asset': 'F-250', 'previous_version': 'r3', 'method': 'Exact ID first', 'expected_route': 'manual', 'route': 'manual', 'expected': {'decision': 'answer', 'value': '101', 'evidence': ['manual-F-250-r3']}, 'response': {}, 'raw': '```json\\n{\\n  \"decision\": \"The maximum temperature of F-250 is 101°C.\",\\n  \"value\": null,\\n  \"evidence\": [\\n    \"manual-F-250-r3\",\\n    \"DATE | SYSTEM\"\\n  ]\\n}\\n```', 'route_error': False, 'covered': False, 'citation_support': False, 'exact_value': False, 'strict_pass': 0, 'outcome': 'No usable JSON object', 'context': '[manual-F-250-r3] Equipment manual for F-250 (revision r3). Maximum operating temperature: 101 C. Known fault: filter blockage. The supporting system is S-650. Maintenance owner: controls.\\n[manual-V-200-r3] Equipment manual for V-200 (revision r3). Maximum operating temperature: 87 C. Known fault: seal wear. The supporting system is S-600. Maintenance owner: electrical.\\n[manual-P-', 'evidence_tokens': 112, 'discarded_tokens': 210, 'support_visible': True, 'prompt_tokens': 273, 'output_text_tokens': 58}, {'case_id': 'F250-00', 'family': 'F250', 'slice': 'follow_up', 'question': 'What is its maximum temperature?', 'role': 'operator', 'tenant': 'north-yard', 'previous_asset': 'F-250', 'previous_version': 'r3', 'method': 'Corpus prefix', 'expected_route': 'manual', 'route': 'manual', 'expected': {'decision': 'answer', 'value': '101', 'evidence': ['manual-F-250-r3']}, 'response': {}, 'raw': '```json\\n{\\n  \"decision\": \"The maximum temperature of F-250 cannot be determined directly from the provided information.\",\\n  \"value\": \"\",\\n  \"evidence\": []\\n}\\n```', 'route_error': False, 'covered': False, 'citation_support': False, 'exact_value': False, 'strict_pass': 0, 'outcome': 'No usable JSON object', 'context': '[manual-V-200-r3] Equipment manual for V-200 (revision r3). Maximum operating temperature: 87 C. Known fault: seal wear. The supporting system is S-600. Maintenance owner: electrical.\\n[manual-P-210-r3] Equipment manual for P-210 (revision r3). Maximum operating temperature: 97 C. Known fault: filter blockage. The supporting system is S-610. Maintenance owner: mechanical.\\n[manual-F-2', 'evidence_tokens': 112, 'discarded_tokens': 210, 'support_visible': False, 'prompt_tokens': 273, 'output_text_tokens': 40}]\n",
      "First recorded manual miss {'case_id': 'F200-00', 'family': 'F200', 'slice': 'manual', 'question': 'What is the maximum temperature for V-200?', 'role': 'operator', 'tenant': 'north-yard', 'previous_asset': '', 'previous_version': '', 'method': 'Corpus prefix', 'expected_route': 'manual', 'route': 'manual', 'expected': {'decision': 'answer', 'value': '87', 'evidence': ['manual-V-200-r3']}, 'response': {}, 'raw': '```json\\n{\\n  \"decision\": \"The maximum temperature for V-200 is 87°C.\",\\n  \"value\": null,\\n  \"evidence\": [\\n    \"manual-V-200-r3\",\\n    \"manual-P-210-r3\"\\n  ]\\n}\\n```', 'route_error': False, 'covered': False, 'citation_support': False, 'exact_value': False, 'strict_pass': 0, 'outcome': 'No usable JSON object', 'context': '[manual-V-200-r3] Equipment manual for V-200 (revision r3). Maximum operating temperature: 87 C. Known fault: seal wear. The supporting system is S-600. Maintenance owner: electrical.\\n[manual-P-210-r3] Equipment manual for P-210 (revision r3). Maximum operating temperature: 97 C. Known fault: filter blockage. The supporting system is S-610. Maintenance owner: mechanical.\\n[manual-F-2', 'evidence_tokens': 112, 'discarded_tokens': 210, 'support_visible': True, 'prompt_tokens': 275, 'output_text_tokens': 62}\n",
      "Evidence saved to evidence/summary.json\n",
      "Evidence saved to evidence/records.json\n",
      "Evidence saved to evidence/structured-ablation.json\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"591.59952pt\" height=\"234.47952pt\" viewBox=\"0 0 591.59952 234.47952\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2026-11-27T06:28:49.411727</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.10.0, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 234.47952 \n",
       "L 591.59952 234.47952 \n",
       "L 591.59952 -0 \n",
       "L 0 -0 \n",
       "z\n",
       "\" style=\"fill: #f5f7f2\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 76.001563 194.92327 \n",
       "L 584.39952 194.92327 \n",
       "L 584.39952 34.3575 \n",
       "L 76.001563 34.3575 \n",
       "z\n",
       "\" style=\"fill: #f5f7f2\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <path d=\"M 76.001563 194.92327 \n",
       "L 76.001563 34.3575 \n",
       "\" clip-path=\"url(#pe5926949bc)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_2\"/>\n",
       "     <g id=\"text_1\">\n",
       "      <!-- 0.0 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(68.05 207.521707) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n",
       "Q 1547 4250 1301 3770 \n",
       "Q 1056 3291 1056 2328 \n",
       "Q 1056 1369 1301 889 \n",
       "Q 1547 409 2034 409 \n",
       "Q 2525 409 2770 889 \n",
       "Q 3016 1369 3016 2328 \n",
       "Q 3016 3291 2770 3770 \n",
       "Q 2525 4250 2034 4250 \n",
       "z\n",
       "M 2034 4750 \n",
       "Q 2819 4750 3233 4129 \n",
       "Q 3647 3509 3647 2328 \n",
       "Q 3647 1150 3233 529 \n",
       "Q 2819 -91 2034 -91 \n",
       "Q 1250 -91 836 529 \n",
       "Q 422 1150 422 2328 \n",
       "Q 422 3509 836 4129 \n",
       "Q 1250 4750 2034 4750 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n",
       "L 1344 794 \n",
       "L 1344 0 \n",
       "L 684 0 \n",
       "L 684 794 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(95.410156 0)\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <path d=\"M 162.170708 194.92327 \n",
       "L 162.170708 34.3575 \n",
       "\" clip-path=\"url(#pe5926949bc)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_4\"/>\n",
       "     <g id=\"text_2\">\n",
       "      <!-- 0.2 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(154.219145 207.521707) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n",
       "L 3431 531 \n",
       "L 3431 0 \n",
       "L 469 0 \n",
       "L 469 531 \n",
       "Q 828 903 1448 1529 \n",
       "Q 2069 2156 2228 2338 \n",
       "Q 2531 2678 2651 2914 \n",
       "Q 2772 3150 2772 3378 \n",
       "Q 2772 3750 2511 3984 \n",
       "Q 2250 4219 1831 4219 \n",
       "Q 1534 4219 1204 4116 \n",
       "Q 875 4013 500 3803 \n",
       "L 500 4441 \n",
       "Q 881 4594 1212 4672 \n",
       "Q 1544 4750 1819 4750 \n",
       "Q 2544 4750 2975 4387 \n",
       "Q 3406 4025 3406 3419 \n",
       "Q 3406 3131 3298 2873 \n",
       "Q 3191 2616 2906 2266 \n",
       "Q 2828 2175 2409 1742 \n",
       "Q 1991 1309 1228 531 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(95.410156 0)\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <path d=\"M 248.339853 194.92327 \n",
       "L 248.339853 34.3575 \n",
       "\" clip-path=\"url(#pe5926949bc)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_6\"/>\n",
       "     <g id=\"text_3\">\n",
       "      <!-- 0.4 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(240.388291 207.521707) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n",
       "L 825 1625 \n",
       "L 2419 1625 \n",
       "L 2419 4116 \n",
       "z\n",
       "M 2253 4666 \n",
       "L 3047 4666 \n",
       "L 3047 1625 \n",
       "L 3713 1625 \n",
       "L 3713 1100 \n",
       "L 3047 1100 \n",
       "L 3047 0 \n",
       "L 2419 0 \n",
       "L 2419 1100 \n",
       "L 313 1100 \n",
       "L 313 1709 \n",
       "L 2253 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-34\" transform=\"translate(95.410156 0)\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <path d=\"M 334.508999 194.92327 \n",
       "L 334.508999 34.3575 \n",
       "\" clip-path=\"url(#pe5926949bc)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_8\"/>\n",
       "     <g id=\"text_4\">\n",
       "      <!-- 0.6 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(326.557436 207.521707) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \n",
       "Q 1688 2584 1439 2293 \n",
       "Q 1191 2003 1191 1497 \n",
       "Q 1191 994 1439 701 \n",
       "Q 1688 409 2113 409 \n",
       "Q 2538 409 2786 701 \n",
       "Q 3034 994 3034 1497 \n",
       "Q 3034 2003 2786 2293 \n",
       "Q 2538 2584 2113 2584 \n",
       "z\n",
       "M 3366 4563 \n",
       "L 3366 3988 \n",
       "Q 3128 4100 2886 4159 \n",
       "Q 2644 4219 2406 4219 \n",
       "Q 1781 4219 1451 3797 \n",
       "Q 1122 3375 1075 2522 \n",
       "Q 1259 2794 1537 2939 \n",
       "Q 1816 3084 2150 3084 \n",
       "Q 2853 3084 3261 2657 \n",
       "Q 3669 2231 3669 1497 \n",
       "Q 3669 778 3244 343 \n",
       "Q 2819 -91 2113 -91 \n",
       "Q 1303 -91 875 529 \n",
       "Q 447 1150 447 2328 \n",
       "Q 447 3434 972 4092 \n",
       "Q 1497 4750 2381 4750 \n",
       "Q 2619 4750 2861 4703 \n",
       "Q 3103 4656 3366 4563 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-36\" transform=\"translate(95.410156 0)\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <path d=\"M 420.678144 194.92327 \n",
       "L 420.678144 34.3575 \n",
       "\" clip-path=\"url(#pe5926949bc)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_10\"/>\n",
       "     <g id=\"text_5\">\n",
       "      <!-- 0.8 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(412.726581 207.521707) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \n",
       "Q 1584 2216 1326 1975 \n",
       "Q 1069 1734 1069 1313 \n",
       "Q 1069 891 1326 650 \n",
       "Q 1584 409 2034 409 \n",
       "Q 2484 409 2743 651 \n",
       "Q 3003 894 3003 1313 \n",
       "Q 3003 1734 2745 1975 \n",
       "Q 2488 2216 2034 2216 \n",
       "z\n",
       "M 1403 2484 \n",
       "Q 997 2584 770 2862 \n",
       "Q 544 3141 544 3541 \n",
       "Q 544 4100 942 4425 \n",
       "Q 1341 4750 2034 4750 \n",
       "Q 2731 4750 3128 4425 \n",
       "Q 3525 4100 3525 3541 \n",
       "Q 3525 3141 3298 2862 \n",
       "Q 3072 2584 2669 2484 \n",
       "Q 3125 2378 3379 2068 \n",
       "Q 3634 1759 3634 1313 \n",
       "Q 3634 634 3220 271 \n",
       "Q 2806 -91 2034 -91 \n",
       "Q 1263 -91 848 271 \n",
       "Q 434 634 434 1313 \n",
       "Q 434 1759 690 2068 \n",
       "Q 947 2378 1403 2484 \n",
       "z\n",
       "M 1172 3481 \n",
       "Q 1172 3119 1398 2916 \n",
       "Q 1625 2713 2034 2713 \n",
       "Q 2441 2713 2670 2916 \n",
       "Q 2900 3119 2900 3481 \n",
       "Q 2900 3844 2670 4047 \n",
       "Q 2441 4250 2034 4250 \n",
       "Q 1625 4250 1398 4047 \n",
       "Q 1172 3844 1172 3481 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-38\" transform=\"translate(95.410156 0)\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_6\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <path d=\"M 506.847289 194.92327 \n",
       "L 506.847289 34.3575 \n",
       "\" clip-path=\"url(#pe5926949bc)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_12\"/>\n",
       "     <g id=\"text_6\">\n",
       "      <!-- 1.0 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(498.895727 207.521707) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n",
       "L 1825 531 \n",
       "L 1825 4091 \n",
       "L 703 3866 \n",
       "L 703 4441 \n",
       "L 1819 4666 \n",
       "L 2450 4666 \n",
       "L 2450 531 \n",
       "L 3481 531 \n",
       "L 3481 0 \n",
       "L 794 0 \n",
       "L 794 531 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-31\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(95.410156 0)\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_7\">\n",
       "     <!-- Strict pass fraction -->\n",
       "     <g style=\"fill: #20382f\" transform=\"translate(76.001563 225.199833) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"DejaVuSans-53\" d=\"M 3425 4513 \n",
       "L 3425 3897 \n",
       "Q 3066 4069 2747 4153 \n",
       "Q 2428 4238 2131 4238 \n",
       "Q 1616 4238 1336 4038 \n",
       "Q 1056 3838 1056 3469 \n",
       "Q 1056 3159 1242 3001 \n",
       "Q 1428 2844 1947 2747 \n",
       "L 2328 2669 \n",
       "Q 3034 2534 3370 2195 \n",
       "Q 3706 1856 3706 1288 \n",
       "Q 3706 609 3251 259 \n",
       "Q 2797 -91 1919 -91 \n",
       "Q 1588 -91 1214 -16 \n",
       "Q 841 59 441 206 \n",
       "L 441 856 \n",
       "Q 825 641 1194 531 \n",
       "Q 1563 422 1919 422 \n",
       "Q 2459 422 2753 634 \n",
       "Q 3047 847 3047 1241 \n",
       "Q 3047 1584 2836 1778 \n",
       "Q 2625 1972 2144 2069 \n",
       "L 1759 2144 \n",
       "Q 1053 2284 737 2584 \n",
       "Q 422 2884 422 3419 \n",
       "Q 422 4038 858 4394 \n",
       "Q 1294 4750 2059 4750 \n",
       "Q 2388 4750 2728 4690 \n",
       "Q 3069 4631 3425 4513 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n",
       "L 1172 3500 \n",
       "L 2356 3500 \n",
       "L 2356 3053 \n",
       "L 1172 3053 \n",
       "L 1172 1153 \n",
       "Q 1172 725 1289 603 \n",
       "Q 1406 481 1766 481 \n",
       "L 2356 481 \n",
       "L 2356 0 \n",
       "L 1766 0 \n",
       "Q 1100 0 847 248 \n",
       "Q 594 497 594 1153 \n",
       "L 594 3053 \n",
       "L 172 3053 \n",
       "L 172 3500 \n",
       "L 594 3500 \n",
       "L 594 4494 \n",
       "L 1172 4494 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n",
       "Q 2534 3019 2420 3045 \n",
       "Q 2306 3072 2169 3072 \n",
       "Q 1681 3072 1420 2755 \n",
       "Q 1159 2438 1159 1844 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2956 \n",
       "Q 1341 3275 1631 3429 \n",
       "Q 1922 3584 2338 3584 \n",
       "Q 2397 3584 2469 3576 \n",
       "Q 2541 3569 2628 3553 \n",
       "L 2631 2963 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n",
       "L 1178 3500 \n",
       "L 1178 0 \n",
       "L 603 0 \n",
       "L 603 3500 \n",
       "z\n",
       "M 603 4863 \n",
       "L 1178 4863 \n",
       "L 1178 4134 \n",
       "L 603 4134 \n",
       "L 603 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \n",
       "L 3122 2828 \n",
       "Q 2878 2963 2633 3030 \n",
       "Q 2388 3097 2138 3097 \n",
       "Q 1578 3097 1268 2742 \n",
       "Q 959 2388 959 1747 \n",
       "Q 959 1106 1268 751 \n",
       "Q 1578 397 2138 397 \n",
       "Q 2388 397 2633 464 \n",
       "Q 2878 531 3122 666 \n",
       "L 3122 134 \n",
       "Q 2881 22 2623 -34 \n",
       "Q 2366 -91 2075 -91 \n",
       "Q 1284 -91 818 406 \n",
       "Q 353 903 353 1747 \n",
       "Q 353 2603 823 3093 \n",
       "Q 1294 3584 2113 3584 \n",
       "Q 2378 3584 2631 3529 \n",
       "Q 2884 3475 3122 3366 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n",
       "L 1159 -1331 \n",
       "L 581 -1331 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2969 \n",
       "Q 1341 3281 1617 3432 \n",
       "Q 1894 3584 2278 3584 \n",
       "Q 2916 3584 3314 3078 \n",
       "Q 3713 2572 3713 1747 \n",
       "Q 3713 922 3314 415 \n",
       "Q 2916 -91 2278 -91 \n",
       "Q 1894 -91 1617 61 \n",
       "Q 1341 213 1159 525 \n",
       "z\n",
       "M 3116 1747 \n",
       "Q 3116 2381 2855 2742 \n",
       "Q 2594 3103 2138 3103 \n",
       "Q 1681 3103 1420 2742 \n",
       "Q 1159 2381 1159 1747 \n",
       "Q 1159 1113 1420 752 \n",
       "Q 1681 391 2138 391 \n",
       "Q 2594 391 2855 752 \n",
       "Q 3116 1113 3116 1747 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \n",
       "Q 1497 1759 1228 1600 \n",
       "Q 959 1441 959 1056 \n",
       "Q 959 750 1161 570 \n",
       "Q 1363 391 1709 391 \n",
       "Q 2188 391 2477 730 \n",
       "Q 2766 1069 2766 1631 \n",
       "L 2766 1759 \n",
       "L 2194 1759 \n",
       "z\n",
       "M 3341 1997 \n",
       "L 3341 0 \n",
       "L 2766 0 \n",
       "L 2766 531 \n",
       "Q 2569 213 2275 61 \n",
       "Q 1981 -91 1556 -91 \n",
       "Q 1019 -91 701 211 \n",
       "Q 384 513 384 1019 \n",
       "Q 384 1609 779 1909 \n",
       "Q 1175 2209 1959 2209 \n",
       "L 2766 2209 \n",
       "L 2766 2266 \n",
       "Q 2766 2663 2505 2880 \n",
       "Q 2244 3097 1772 3097 \n",
       "Q 1472 3097 1187 3025 \n",
       "Q 903 2953 641 2809 \n",
       "L 641 3341 \n",
       "Q 956 3463 1253 3523 \n",
       "Q 1550 3584 1831 3584 \n",
       "Q 2591 3584 2966 3190 \n",
       "Q 3341 2797 3341 1997 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n",
       "L 2834 2853 \n",
       "Q 2591 2978 2328 3040 \n",
       "Q 2066 3103 1784 3103 \n",
       "Q 1356 3103 1142 2972 \n",
       "Q 928 2841 928 2578 \n",
       "Q 928 2378 1081 2264 \n",
       "Q 1234 2150 1697 2047 \n",
       "L 1894 2003 \n",
       "Q 2506 1872 2764 1633 \n",
       "Q 3022 1394 3022 966 \n",
       "Q 3022 478 2636 193 \n",
       "Q 2250 -91 1575 -91 \n",
       "Q 1294 -91 989 -36 \n",
       "Q 684 19 347 128 \n",
       "L 347 722 \n",
       "Q 666 556 975 473 \n",
       "Q 1284 391 1588 391 \n",
       "Q 1994 391 2212 530 \n",
       "Q 2431 669 2431 922 \n",
       "Q 2431 1156 2273 1281 \n",
       "Q 2116 1406 1581 1522 \n",
       "L 1381 1569 \n",
       "Q 847 1681 609 1914 \n",
       "Q 372 2147 372 2553 \n",
       "Q 372 3047 722 3315 \n",
       "Q 1072 3584 1716 3584 \n",
       "Q 2034 3584 2315 3537 \n",
       "Q 2597 3491 2834 3397 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-66\" d=\"M 2375 4863 \n",
       "L 2375 4384 \n",
       "L 1825 4384 \n",
       "Q 1516 4384 1395 4259 \n",
       "Q 1275 4134 1275 3809 \n",
       "L 1275 3500 \n",
       "L 2222 3500 \n",
       "L 2222 3053 \n",
       "L 1275 3053 \n",
       "L 1275 0 \n",
       "L 697 0 \n",
       "L 697 3053 \n",
       "L 147 3053 \n",
       "L 147 3500 \n",
       "L 697 3500 \n",
       "L 697 3744 \n",
       "Q 697 4328 969 4595 \n",
       "Q 1241 4863 1831 4863 \n",
       "L 2375 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n",
       "Q 1497 3097 1228 2736 \n",
       "Q 959 2375 959 1747 \n",
       "Q 959 1119 1226 758 \n",
       "Q 1494 397 1959 397 \n",
       "Q 2419 397 2687 759 \n",
       "Q 2956 1122 2956 1747 \n",
       "Q 2956 2369 2687 2733 \n",
       "Q 2419 3097 1959 3097 \n",
       "z\n",
       "M 1959 3584 \n",
       "Q 2709 3584 3137 3096 \n",
       "Q 3566 2609 3566 1747 \n",
       "Q 3566 888 3137 398 \n",
       "Q 2709 -91 1959 -91 \n",
       "Q 1206 -91 779 398 \n",
       "Q 353 888 353 1747 \n",
       "Q 353 2609 779 3096 \n",
       "Q 1206 3584 1959 3584 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n",
       "L 3513 0 \n",
       "L 2938 0 \n",
       "L 2938 2094 \n",
       "Q 2938 2591 2744 2837 \n",
       "Q 2550 3084 2163 3084 \n",
       "Q 1697 3084 1428 2787 \n",
       "Q 1159 2491 1159 1978 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2956 \n",
       "Q 1366 3272 1645 3428 \n",
       "Q 1925 3584 2291 3584 \n",
       "Q 2894 3584 3203 3211 \n",
       "Q 3513 2838 3513 2113 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSans-53\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(63.476562 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(102.685547 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(143.798828 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(171.582031 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(226.5625 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(265.771484 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-70\" transform=\"translate(297.558594 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(361.035156 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(422.314453 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(474.414062 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(526.513672 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-66\" transform=\"translate(558.300781 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(593.505859 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(634.619141 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(695.898438 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(750.878906 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(790.087891 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(817.871094 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(879.052734 0)\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_13\"/>\n",
       "     <g id=\"text_8\">\n",
       "      <!-- SQL -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(51.209375 61.196905) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-51\" d=\"M 2522 4238 \n",
       "Q 1834 4238 1429 3725 \n",
       "Q 1025 3213 1025 2328 \n",
       "Q 1025 1447 1429 934 \n",
       "Q 1834 422 2522 422 \n",
       "Q 3209 422 3611 934 \n",
       "Q 4013 1447 4013 2328 \n",
       "Q 4013 3213 3611 3725 \n",
       "Q 3209 4238 2522 4238 \n",
       "z\n",
       "M 3406 84 \n",
       "L 4238 -825 \n",
       "L 3475 -825 \n",
       "L 2784 -78 \n",
       "Q 2681 -84 2626 -87 \n",
       "Q 2572 -91 2522 -91 \n",
       "Q 1538 -91 948 567 \n",
       "Q 359 1225 359 2328 \n",
       "Q 359 3434 948 4092 \n",
       "Q 1538 4750 2522 4750 \n",
       "Q 3503 4750 4090 4092 \n",
       "Q 4678 3434 4678 2328 \n",
       "Q 4678 1516 4351 937 \n",
       "Q 4025 359 3406 84 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-4c\" d=\"M 628 4666 \n",
       "L 1259 4666 \n",
       "L 1259 531 \n",
       "L 3531 531 \n",
       "L 3531 0 \n",
       "L 628 0 \n",
       "L 628 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-53\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-51\" transform=\"translate(63.476562 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-4c\" transform=\"translate(142.1875 0)\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_14\"/>\n",
       "     <g id=\"text_9\">\n",
       "      <!-- graph -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(41.728125 118.439604) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-67\" d=\"M 2906 1791 \n",
       "Q 2906 2416 2648 2759 \n",
       "Q 2391 3103 1925 3103 \n",
       "Q 1463 3103 1205 2759 \n",
       "Q 947 2416 947 1791 \n",
       "Q 947 1169 1205 825 \n",
       "Q 1463 481 1925 481 \n",
       "Q 2391 481 2648 825 \n",
       "Q 2906 1169 2906 1791 \n",
       "z\n",
       "M 3481 434 \n",
       "Q 3481 -459 3084 -895 \n",
       "Q 2688 -1331 1869 -1331 \n",
       "Q 1566 -1331 1297 -1286 \n",
       "Q 1028 -1241 775 -1147 \n",
       "L 775 -588 \n",
       "Q 1028 -725 1275 -790 \n",
       "Q 1522 -856 1778 -856 \n",
       "Q 2344 -856 2625 -561 \n",
       "Q 2906 -266 2906 331 \n",
       "L 2906 616 \n",
       "Q 2728 306 2450 153 \n",
       "Q 2172 0 1784 0 \n",
       "Q 1141 0 747 490 \n",
       "Q 353 981 353 1791 \n",
       "Q 353 2603 747 3093 \n",
       "Q 1141 3584 1784 3584 \n",
       "Q 2172 3584 2450 3431 \n",
       "Q 2728 3278 2906 2969 \n",
       "L 2906 3500 \n",
       "L 3481 3500 \n",
       "L 3481 434 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \n",
       "L 3513 0 \n",
       "L 2938 0 \n",
       "L 2938 2094 \n",
       "Q 2938 2591 2744 2837 \n",
       "Q 2550 3084 2163 3084 \n",
       "Q 1697 3084 1428 2787 \n",
       "Q 1159 2491 1159 1978 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 4863 \n",
       "L 1159 4863 \n",
       "L 1159 2956 \n",
       "Q 1366 3272 1645 3428 \n",
       "Q 1925 3584 2291 3584 \n",
       "Q 2894 3584 3203 3211 \n",
       "Q 3513 2838 3513 2113 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-67\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(63.476562 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(104.589844 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-70\" transform=\"translate(165.869141 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-68\" transform=\"translate(229.345703 0)\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_15\"/>\n",
       "     <g id=\"text_10\">\n",
       "      <!-- graph + SQL -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(7.2 175.682303) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-2b\" d=\"M 2944 4013 \n",
       "L 2944 2272 \n",
       "L 4684 2272 \n",
       "L 4684 1741 \n",
       "L 2944 1741 \n",
       "L 2944 0 \n",
       "L 2419 0 \n",
       "L 2419 1741 \n",
       "L 678 1741 \n",
       "L 678 2272 \n",
       "L 2419 2272 \n",
       "L 2419 4013 \n",
       "L 2944 4013 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-67\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(63.476562 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(104.589844 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-70\" transform=\"translate(165.869141 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-68\" transform=\"translate(229.345703 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(292.724609 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-2b\" transform=\"translate(324.511719 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(408.300781 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-53\" transform=\"translate(440.087891 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-51\" transform=\"translate(503.564453 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-4c\" transform=\"translate(582.275391 0)\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 76.001563 41.655944 \n",
       "L 76.001563 41.655944 \n",
       "L 76.001563 73.139428 \n",
       "L 76.001563 73.139428 \n",
       "z\n",
       "\" clip-path=\"url(#pe5926949bc)\" style=\"fill: #3d6b5b\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 76.001563 98.898643 \n",
       "L 76.001563 98.898643 \n",
       "L 76.001563 130.382127 \n",
       "L 76.001563 130.382127 \n",
       "z\n",
       "\" clip-path=\"url(#pe5926949bc)\" style=\"fill: #298876\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 76.001563 156.141342 \n",
       "L 506.847289 156.141342 \n",
       "L 506.847289 187.624826 \n",
       "L 76.001563 187.624826 \n",
       "z\n",
       "\" clip-path=\"url(#pe5926949bc)\" style=\"fill: #7b97a2\"/>\n",
       "   </g>\n",
       "   <g id=\"PathCollection_1\">\n",
       "    <defs>\n",
       "     <path id=\"m5716493802\" d=\"M 0 1.870829 \n",
       "C 0.49615 1.870829 0.972045 1.673706 1.322876 1.322876 \n",
       "C 1.673706 0.972045 1.870829 0.49615 1.870829 0 \n",
       "C 1.870829 -0.49615 1.673706 -0.972045 1.322876 -1.322876 \n",
       "C 0.972045 -1.673706 0.49615 -1.870829 0 -1.870829 \n",
       "C -0.49615 -1.870829 -0.972045 -1.673706 -1.322876 -1.322876 \n",
       "C -1.673706 -0.972045 -1.870829 -0.49615 -1.870829 0 \n",
       "C -1.870829 0.49615 -1.673706 0.972045 -1.322876 1.322876 \n",
       "C -0.972045 1.673706 -0.49615 1.870829 0 1.870829 \n",
       "z\n",
       "\" style=\"stroke: #20382f\"/>\n",
       "    </defs>\n",
       "    <g>\n",
       "     <use xlink:href=\"#m5716493802\" x=\"76.001563\" y=\"57.397686\" style=\"fill: #20382f; stroke: #20382f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_11\">\n",
       "    <!-- 0 -->\n",
       "    <g style=\"fill: #20382f\" transform=\"translate(82.001563 60.157061) scale(0.1 -0.1)\">\n",
       "     <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"PathCollection_2\">\n",
       "    <g>\n",
       "     <use xlink:href=\"#m5716493802\" x=\"76.001563\" y=\"114.640385\" style=\"fill: #20382f; stroke: #20382f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_12\">\n",
       "    <!-- 0 -->\n",
       "    <g style=\"fill: #20382f\" transform=\"translate(82.001563 117.39976) scale(0.1 -0.1)\">\n",
       "     <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_13\">\n",
       "    <!-- 1 -->\n",
       "    <g style=\"fill: #20382f\" transform=\"translate(512.847289 174.642459) scale(0.1 -0.1)\">\n",
       "     <use xlink:href=\"#DejaVuSans-31\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_14\">\n",
       "    <!-- Strict outcomes on two-source requests -->\n",
       "    <g style=\"fill: #20382f\" transform=\"translate(76.001563 19.3575) scale(0.16 -0.16)\">\n",
       "     <defs>\n",
       "      <path id=\"DejaVuSans-Bold-53\" d=\"M 3834 4519 \n",
       "L 3834 3531 \n",
       "Q 3450 3703 3084 3790 \n",
       "Q 2719 3878 2394 3878 \n",
       "Q 1963 3878 1756 3759 \n",
       "Q 1550 3641 1550 3391 \n",
       "Q 1550 3203 1689 3098 \n",
       "Q 1828 2994 2194 2919 \n",
       "L 2706 2816 \n",
       "Q 3484 2659 3812 2340 \n",
       "Q 4141 2022 4141 1434 \n",
       "Q 4141 663 3683 286 \n",
       "Q 3225 -91 2284 -91 \n",
       "Q 1841 -91 1394 -6 \n",
       "Q 947 78 500 244 \n",
       "L 500 1259 \n",
       "Q 947 1022 1364 901 \n",
       "Q 1781 781 2169 781 \n",
       "Q 2563 781 2772 912 \n",
       "Q 2981 1044 2981 1288 \n",
       "Q 2981 1506 2839 1625 \n",
       "Q 2697 1744 2272 1838 \n",
       "L 1806 1941 \n",
       "Q 1106 2091 782 2419 \n",
       "Q 459 2747 459 3303 \n",
       "Q 459 4000 909 4375 \n",
       "Q 1359 4750 2203 4750 \n",
       "Q 2588 4750 2994 4692 \n",
       "Q 3400 4634 3834 4519 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-74\" d=\"M 1759 4494 \n",
       "L 1759 3500 \n",
       "L 2913 3500 \n",
       "L 2913 2700 \n",
       "L 1759 2700 \n",
       "L 1759 1216 \n",
       "Q 1759 972 1856 886 \n",
       "Q 1953 800 2241 800 \n",
       "L 2816 800 \n",
       "L 2816 0 \n",
       "L 1856 0 \n",
       "Q 1194 0 917 276 \n",
       "Q 641 553 641 1216 \n",
       "L 641 2700 \n",
       "L 84 2700 \n",
       "L 84 3500 \n",
       "L 641 3500 \n",
       "L 641 4494 \n",
       "L 1759 4494 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-72\" d=\"M 3138 2547 \n",
       "Q 2991 2616 2845 2648 \n",
       "Q 2700 2681 2553 2681 \n",
       "Q 2122 2681 1889 2404 \n",
       "Q 1656 2128 1656 1613 \n",
       "L 1656 0 \n",
       "L 538 0 \n",
       "L 538 3500 \n",
       "L 1656 3500 \n",
       "L 1656 2925 \n",
       "Q 1872 3269 2151 3426 \n",
       "Q 2431 3584 2822 3584 \n",
       "Q 2878 3584 2943 3579 \n",
       "Q 3009 3575 3134 3559 \n",
       "L 3138 2547 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-69\" d=\"M 538 3500 \n",
       "L 1656 3500 \n",
       "L 1656 0 \n",
       "L 538 0 \n",
       "L 538 3500 \n",
       "z\n",
       "M 538 4863 \n",
       "L 1656 4863 \n",
       "L 1656 3950 \n",
       "L 538 3950 \n",
       "L 538 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-63\" d=\"M 3366 3391 \n",
       "L 3366 2478 \n",
       "Q 3138 2634 2908 2709 \n",
       "Q 2678 2784 2431 2784 \n",
       "Q 1963 2784 1702 2511 \n",
       "Q 1441 2238 1441 1747 \n",
       "Q 1441 1256 1702 982 \n",
       "Q 1963 709 2431 709 \n",
       "Q 2694 709 2930 787 \n",
       "Q 3166 866 3366 1019 \n",
       "L 3366 103 \n",
       "Q 3103 6 2833 -42 \n",
       "Q 2563 -91 2291 -91 \n",
       "Q 1344 -91 809 395 \n",
       "Q 275 881 275 1747 \n",
       "Q 275 2613 809 3098 \n",
       "Q 1344 3584 2291 3584 \n",
       "Q 2566 3584 2833 3536 \n",
       "Q 3100 3488 3366 3391 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-20\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-6f\" d=\"M 2203 2784 \n",
       "Q 1831 2784 1636 2517 \n",
       "Q 1441 2250 1441 1747 \n",
       "Q 1441 1244 1636 976 \n",
       "Q 1831 709 2203 709 \n",
       "Q 2569 709 2762 976 \n",
       "Q 2956 1244 2956 1747 \n",
       "Q 2956 2250 2762 2517 \n",
       "Q 2569 2784 2203 2784 \n",
       "z\n",
       "M 2203 3584 \n",
       "Q 3106 3584 3614 3096 \n",
       "Q 4122 2609 4122 1747 \n",
       "Q 4122 884 3614 396 \n",
       "Q 3106 -91 2203 -91 \n",
       "Q 1297 -91 786 396 \n",
       "Q 275 884 275 1747 \n",
       "Q 275 2609 786 3096 \n",
       "Q 1297 3584 2203 3584 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-75\" d=\"M 500 1363 \n",
       "L 500 3500 \n",
       "L 1625 3500 \n",
       "L 1625 3150 \n",
       "Q 1625 2866 1622 2436 \n",
       "Q 1619 2006 1619 1863 \n",
       "Q 1619 1441 1641 1255 \n",
       "Q 1663 1069 1716 984 \n",
       "Q 1784 875 1895 815 \n",
       "Q 2006 756 2150 756 \n",
       "Q 2500 756 2700 1025 \n",
       "Q 2900 1294 2900 1772 \n",
       "L 2900 3500 \n",
       "L 4019 3500 \n",
       "L 4019 0 \n",
       "L 2900 0 \n",
       "L 2900 506 \n",
       "Q 2647 200 2364 54 \n",
       "Q 2081 -91 1741 -91 \n",
       "Q 1134 -91 817 281 \n",
       "Q 500 653 500 1363 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-6d\" d=\"M 3781 2919 \n",
       "Q 3994 3244 4286 3414 \n",
       "Q 4578 3584 4928 3584 \n",
       "Q 5531 3584 5847 3212 \n",
       "Q 6163 2841 6163 2131 \n",
       "L 6163 0 \n",
       "L 5038 0 \n",
       "L 5038 1825 \n",
       "Q 5041 1866 5042 1909 \n",
       "Q 5044 1953 5044 2034 \n",
       "Q 5044 2406 4934 2573 \n",
       "Q 4825 2741 4581 2741 \n",
       "Q 4263 2741 4089 2478 \n",
       "Q 3916 2216 3909 1719 \n",
       "L 3909 0 \n",
       "L 2784 0 \n",
       "L 2784 1825 \n",
       "Q 2784 2406 2684 2573 \n",
       "Q 2584 2741 2328 2741 \n",
       "Q 2006 2741 1831 2477 \n",
       "Q 1656 2213 1656 1722 \n",
       "L 1656 0 \n",
       "L 531 0 \n",
       "L 531 3500 \n",
       "L 1656 3500 \n",
       "L 1656 2988 \n",
       "Q 1863 3284 2130 3434 \n",
       "Q 2397 3584 2719 3584 \n",
       "Q 3081 3584 3359 3409 \n",
       "Q 3638 3234 3781 2919 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-65\" d=\"M 4031 1759 \n",
       "L 4031 1441 \n",
       "L 1416 1441 \n",
       "Q 1456 1047 1700 850 \n",
       "Q 1944 653 2381 653 \n",
       "Q 2734 653 3104 758 \n",
       "Q 3475 863 3866 1075 \n",
       "L 3866 213 \n",
       "Q 3469 63 3072 -14 \n",
       "Q 2675 -91 2278 -91 \n",
       "Q 1328 -91 801 392 \n",
       "Q 275 875 275 1747 \n",
       "Q 275 2603 792 3093 \n",
       "Q 1309 3584 2216 3584 \n",
       "Q 3041 3584 3536 3087 \n",
       "Q 4031 2591 4031 1759 \n",
       "z\n",
       "M 2881 2131 \n",
       "Q 2881 2450 2695 2645 \n",
       "Q 2509 2841 2209 2841 \n",
       "Q 1884 2841 1681 2658 \n",
       "Q 1478 2475 1428 2131 \n",
       "L 2881 2131 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-73\" d=\"M 3272 3391 \n",
       "L 3272 2541 \n",
       "Q 2913 2691 2578 2766 \n",
       "Q 2244 2841 1947 2841 \n",
       "Q 1628 2841 1473 2761 \n",
       "Q 1319 2681 1319 2516 \n",
       "Q 1319 2381 1436 2309 \n",
       "Q 1553 2238 1856 2203 \n",
       "L 2053 2175 \n",
       "Q 2913 2066 3209 1816 \n",
       "Q 3506 1566 3506 1031 \n",
       "Q 3506 472 3093 190 \n",
       "Q 2681 -91 1863 -91 \n",
       "Q 1516 -91 1145 -36 \n",
       "Q 775 19 384 128 \n",
       "L 384 978 \n",
       "Q 719 816 1070 734 \n",
       "Q 1422 653 1784 653 \n",
       "Q 2113 653 2278 743 \n",
       "Q 2444 834 2444 1013 \n",
       "Q 2444 1163 2330 1236 \n",
       "Q 2216 1309 1875 1350 \n",
       "L 1678 1375 \n",
       "Q 931 1469 631 1722 \n",
       "Q 331 1975 331 2491 \n",
       "Q 331 3047 712 3315 \n",
       "Q 1094 3584 1881 3584 \n",
       "Q 2191 3584 2531 3537 \n",
       "Q 2872 3491 3272 3391 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-6e\" d=\"M 4056 2131 \n",
       "L 4056 0 \n",
       "L 2931 0 \n",
       "L 2931 347 \n",
       "L 2931 1631 \n",
       "Q 2931 2084 2911 2256 \n",
       "Q 2891 2428 2841 2509 \n",
       "Q 2775 2619 2662 2680 \n",
       "Q 2550 2741 2406 2741 \n",
       "Q 2056 2741 1856 2470 \n",
       "Q 1656 2200 1656 1722 \n",
       "L 1656 0 \n",
       "L 538 0 \n",
       "L 538 3500 \n",
       "L 1656 3500 \n",
       "L 1656 2988 \n",
       "Q 1909 3294 2193 3439 \n",
       "Q 2478 3584 2822 3584 \n",
       "Q 3428 3584 3742 3212 \n",
       "Q 4056 2841 4056 2131 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-77\" d=\"M 225 3500 \n",
       "L 1313 3500 \n",
       "L 1900 1088 \n",
       "L 2491 3500 \n",
       "L 3425 3500 \n",
       "L 4013 1113 \n",
       "L 4603 3500 \n",
       "L 5691 3500 \n",
       "L 4769 0 \n",
       "L 3547 0 \n",
       "L 2956 2406 \n",
       "L 2369 0 \n",
       "L 1147 0 \n",
       "L 225 3500 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-2d\" d=\"M 347 2297 \n",
       "L 2309 2297 \n",
       "L 2309 1388 \n",
       "L 347 1388 \n",
       "L 347 2297 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-71\" d=\"M 2181 2772 \n",
       "Q 1825 2772 1636 2509 \n",
       "Q 1447 2247 1447 1747 \n",
       "Q 1447 1247 1636 984 \n",
       "Q 1825 722 2181 722 \n",
       "Q 2541 722 2730 984 \n",
       "Q 2919 1247 2919 1747 \n",
       "Q 2919 2247 2730 2509 \n",
       "Q 2541 2772 2181 2772 \n",
       "z\n",
       "M 2919 506 \n",
       "Q 2688 197 2409 53 \n",
       "Q 2131 -91 1766 -91 \n",
       "Q 1119 -91 703 423 \n",
       "Q 288 938 288 1747 \n",
       "Q 288 2556 703 3067 \n",
       "Q 1119 3578 1766 3578 \n",
       "Q 2131 3578 2409 3434 \n",
       "Q 2688 3291 2919 2981 \n",
       "L 2919 3500 \n",
       "L 4044 3500 \n",
       "L 4044 -1331 \n",
       "L 2919 -1331 \n",
       "L 2919 506 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "     </defs>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-53\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-74\" transform=\"translate(72.021484 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-72\" transform=\"translate(119.824219 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-69\" transform=\"translate(169.140625 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-63\" transform=\"translate(203.417969 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-74\" transform=\"translate(262.695312 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-20\" transform=\"translate(310.498047 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6f\" transform=\"translate(345.3125 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-75\" transform=\"translate(414.013672 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-74\" transform=\"translate(485.205078 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-63\" transform=\"translate(533.007812 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6f\" transform=\"translate(592.285156 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6d\" transform=\"translate(660.986328 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-65\" transform=\"translate(765.185547 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-73\" transform=\"translate(833.007812 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-20\" transform=\"translate(892.529297 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6f\" transform=\"translate(927.34375 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6e\" transform=\"translate(996.044922 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-20\" transform=\"translate(1067.236328 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-74\" transform=\"translate(1102.050781 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-77\" transform=\"translate(1149.853516 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6f\" transform=\"translate(1242.236328 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-2d\" transform=\"translate(1310.9375 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-73\" transform=\"translate(1352.441406 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6f\" transform=\"translate(1411.962891 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-75\" transform=\"translate(1480.664062 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-72\" transform=\"translate(1551.855469 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-63\" transform=\"translate(1601.171875 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-65\" transform=\"translate(1660.449219 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-20\" transform=\"translate(1728.271484 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-72\" transform=\"translate(1763.085938 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-65\" transform=\"translate(1812.402344 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-71\" transform=\"translate(1880.224609 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-75\" transform=\"translate(1951.806641 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-65\" transform=\"translate(2022.998047 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-73\" transform=\"translate(2090.820312 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-74\" transform=\"translate(2150.341797 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-73\" transform=\"translate(2198.144531 0)\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pe5926949bc\">\n",
       "   <rect x=\"76.001563\" y=\"34.3575\" width=\"508.397957\" height=\"160.56577\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<Figure size 810x314 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def summarise(group):\n",
    "    answerable = [row for row in group if row[\"expected\"][\"decision\"] == \"answer\"]\n",
    "    failures = defaultdict(int)\n",
    "    for row in group:\n",
    "        failures[row[\"outcome\"]] += 1\n",
    "    return {\n",
    "        \"cases\": len(group), \"family_count\": len({row[\"family\"] for row in group}),\n",
    "        \"answerable_cases\": len(answerable), \"covered\": sum(row[\"covered\"] for row in group),\n",
    "        \"route_errors\": sum(row[\"route_error\"] for row in group),\n",
    "        \"route_accuracy\": sum(not row[\"route_error\"] for row in group) / len(group),\n",
    "        \"citation_matches\": sum(row[\"citation_support\"] for row in answerable),\n",
    "        \"exact_values\": sum(row[\"exact_value\"] for row in answerable),\n",
    "        \"strict_passes\": sum(row[\"strict_pass\"] for row in group),\n",
    "        \"strict_pass_rate\": sum(row[\"strict_pass\"] for row in group) / len(group),\n",
    "        \"outcomes\": dict(failures),\n",
    "    }\n",
    "\n",
    "\n",
    "def grouped_outcomes(records):\n",
    "    groups = defaultdict(list)\n",
    "    for row in records:\n",
    "        groups[row[\"method\"], row[\"slice\"]].append(row)\n",
    "        groups[row[\"method\"], \"all\"].append(row)\n",
    "    return [\n",
    "        {\"method\": method, \"slice\": question_slice, **summarise(group)}\n",
    "        for (method, question_slice), group in groups.items()\n",
    "    ]\n",
    "\n",
    "\n",
    "def compare_paired(name, candidate, incumbent, rows):\n",
    "    def outcomes(method):\n",
    "        return {row[\"case_id\"]: row[\"strict_pass\"] for row in rows if row[\"method\"] == method}\n",
    "\n",
    "    new, old = outcomes(candidate), outcomes(incumbent)\n",
    "    assert new.keys() == old.keys() and new\n",
    "    matching = [case for case in dev_cases if case[\"id\"] in new]\n",
    "    return {\n",
    "        \"cohort\": name, \"candidate\": candidate, \"incumbent\": incumbent,\n",
    "        \"wins\": sum(new[key] > old[key] for key in new), \"losses\": sum(new[key] < old[key] for key in new),\n",
    "        **paired_interval(matching, [new[case[\"id\"]] for case in matching],\n",
    "                          [old[case[\"id\"]] for case in matching]),\n",
    "    }\n",
    "\n",
    "\n",
    "# The same observed non-manual outputs are re-used in each routed comparison.\n",
    "routed_records = []\n",
    "pairs = [compare_paired(\"Two-source requests\", \"graph + SQL\", ablation, structured_ablation)\n",
    "         for ablation in (\"SQL\", \"graph\")]\n",
    "if manual_records:\n",
    "    for manual_method, routed_method in zip(MANUAL_METHODS, ROUTED_METHODS):\n",
    "        routed_records.extend(\n",
    "            {**row, \"method\": routed_method}\n",
    "            for row in [*cpu_records, *manual_records]\n",
    "            if row[\"method\"] in {\"Shared structured routes\", manual_method}\n",
    "        )\n",
    "    assert len(routed_records) == len(dev_cases) * len(ROUTED_METHODS)\n",
    "    for method, routed_method in zip(MANUAL_METHODS[1:], ROUTED_METHODS[1:]):\n",
    "        pairs += [\n",
    "            compare_paired(\"Manual requests\", method, MANUAL_METHODS[0], manual_records),\n",
    "            compare_paired(\"All development requests\", routed_method, ROUTED_METHODS[0], routed_records),\n",
    "        ]\n",
    "\n",
    "manual_costs = []\n",
    "for method in MANUAL_METHODS:\n",
    "    rows = [row for row in manual_records if row[\"method\"] == method]\n",
    "    timings = [row for row in batch_timings if row[\"method\"] == method]\n",
    "    if rows:\n",
    "        peaks = [row[\"peak_allocated_bytes\"] for row in timings if row[\"peak_allocated_bytes\"] is not None]\n",
    "        manual_costs.append({\n",
    "            \"method\": method, \"cases\": len(rows), \"batches\": len(timings),\n",
    "            \"support_visible\": sum(row[\"support_visible\"] for row in rows),\n",
    "            \"evidence_tokens_median\": median(row[\"evidence_tokens\"] for row in rows),\n",
    "            \"discarded_tokens_median\": median(row[\"discarded_tokens\"] for row in rows),\n",
    "            \"prompt_tokens_median\": median(row[\"prompt_tokens\"] for row in rows),\n",
    "            \"output_text_tokens_median\": median(row[\"output_text_tokens\"] for row in rows),\n",
    "            \"batch_wall_ms_median\": median(row[\"wall_ms\"] for row in timings),\n",
    "            \"peak_allocated_bytes\": max(peaks) if peaks else None,\n",
    "        })\n",
    "\n",
    "outcomes = grouped_outcomes([*cpu_records, *manual_records, *routed_records])\n",
    "structured_summary = [{\"method\": method, **summarise([row for row in structured_ablation if row[\"method\"] == method])}\n",
    "                      for method in (\"SQL\", \"graph\", \"graph + SQL\")]\n",
    "summary = {\n",
    "    \"mode\": \"smoke\" if COURSE_SMOKE else \"full\", \"settings\": {\n",
    "        \"evidence_token_ceiling\": EVIDENCE_TOKEN_BUDGET, \"output_token_cap\": OUTPUT_TOKEN_BUDGET,\n",
    "        \"batch_size\": MANUAL_BATCH_SIZE, \"variants\": [0, 3], \"bootstrap_draws\": 1500,\n",
    "        \"development_sha256\": SPLIT_MANIFEST[\"dev\"][\"sha256\"],\n",
    "    },\n",
    "    \"cohorts\": {\"development_cases\": len(dev_cases), \"development_families\": len(asset_index),\n",
    "                \"manual_cases\": len(manual_cases), \"structured_cases\": len(cpu_records)},\n",
    "    \"outcomes\": outcomes, \"structured_ablation\": structured_summary, \"paired_strict\": pairs,\n",
    "    \"manual_costs\": manual_costs, \"model_load_s\": model_load_s,\n",
    "}\n",
    "print(\"Evidence comparison\", summary)\n",
    "print(\"Opening ticket, observed manual outputs\",\n",
    "      [row for row in manual_records if row[\"case_id\"] == opening_case[\"id\"]])\n",
    "first_miss = next((row for row in manual_records if not row[\"strict_pass\"]), None)\n",
    "if first_miss is not None:\n",
    "    print(\"First recorded manual miss\", first_miss)\n",
    "save(\"summary\", summary)\n",
    "save(\"records\", {\"opening\": opening, \"decisions\": [*cpu_records, *manual_records, *routed_records],\n",
    "                 \"batch_timings\": batch_timings})\n",
    "save(\"structured-ablation\", structured_ablation)\n",
    "chart(\"Strict outcomes on two-source requests\", [row[\"method\"] for row in structured_summary],\n",
    "      [row[\"strict_pass_rate\"] for row in structured_summary], \"Strict pass fraction\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-21",
   "metadata": {},
   "source": [
    "### Read the result\n",
    "\n",
    "Return to F-250 and find the manual ID and temperature line in each supplied\n",
    "context before grading the reply. Then inspect the two-source request and\n",
    "ask which half each single-source result omitted. Look at route accuracy\n",
    "alongside strict accuracy before deciding whether to change the router or\n",
    "the answer generator. [Read Lesson 6](https://docs.recohut.com/courses/advanced-ai-systems-engineering/2-build-the-evidence-layer/06-choose-an-evidence-source)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-06-22",
   "metadata": {},
   "source": [
    "## Read the result\n",
    "\n",
    "Inspect the per-case records in `evidence/` before drawing a conclusion from an aggregate. Use the printed sample size, split and hardware when comparing it with another run.\n",
    "\n",
    "- [From Local to Global: A Graph RAG Approach to Query-Focused Summarization](https://arxiv.org/abs/2404.16130)\n",
    "- [Lost in the Middle: How Language Models Use Long Contexts](https://arxiv.org/abs/2307.03172)"
   ]
  }
 ],
 "metadata": {
  "course": {
   "lab": 6,
   "slug": "06-choose-an-evidence-source"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
