Spaces:
Sleeping
Download README.md from TBM99/CoverageCheck: direct link, hf CLI and curl.
- Browser
- Download file 10.5 kB
-
https://huggingface.co/spaces/TBM99/CoverageCheck/resolve/main/README.md
- Command line
-
hf download hf://spaces/TBM99/CoverageCheck/README.md
-
curl -L -o README.md https://huggingface.co/spaces/TBM99/CoverageCheck/resolve/main/README.md
title: CoverageCheck
emoji: 📑
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 7860
pinned: false
short_description: Ontario auto insurance Q&A, three RAG designs compared
CoverageCheck
Ask a question about Ontario auto insurance coverage and get an answer that quotes the policy wording, or an honest "I can't determine". Three retrieval designs answer the same questions, and a blind test measures which one is right more often, and at what cost.
Live demo: tbm99-coveragecheck.hf.space (Ask, Evals, Architecture and About pages; live questions are capped per day).
Answers come only from public FSRA forms and Ontario laws, and are not coverage advice: read the cited text before relying on it.
The problem
An underwriter or broker answering "is my client covered if...?" has to read across documents: the standard Ontario auto policy (OAP 1), the change forms (OPCFs) that amend it, and the laws behind it, such as the Statutory Accident Benefits Schedule (SABS). One answer often needs two or three of them, and the right version depends on the policy date (SABS changed on 2026-07-01).
A wrong answer can leave a client uncovered, so the system must quote its source and say "I can't determine" when the documents don't answer the question. This project measures how much the retrieval design changes that, keeping everything else equal: the same 36 public documents, the same answer model (Claude Haiku 5.5) and the same instructions for all three systems.
Results
| System | Accuracy (95% CI) | Cost / question | Median time | Not-exact quotes | 1 doc (n=100) | 2 docs (n=76) | 3+ docs (n=25) |
|---|---|---|---|---|---|---|---|
| A: naive RAG | 42% (36% to 48%) | 8.16 | 6.9 s | 0.7% | 41% | 14% | 16% |
| B: hybrid RAG | 61% (55% to 67%) | 6.62 | 9.7 s | 1.1% | 63% | 46% | 24% |
| C: agent (LangGraph) | 84% (79% to 88%) | 3.16 | 19.2 s | 0.0% | 89% | 72% | 64% |
249 held-out questions, the same for every system. Cost per question: 0 when right, 1 for an unnecessary "I can't determine", 5 or 20 for a wrong answer (lower is better; see the cost view). Not-exact quotes: cited text not found word for word in the cited section.
- C vs B on the same 249 questions: 61 fixed, 4 broken; accuracy +22.9 points (95% CI +17.3 to +28.5), McNemar p < 0.001.
- B vs A on the same 249 questions: 60 fixed, 13 broken; accuracy +18.9 points (95% CI +12.4 to +25.3), McNemar p < 0.001.
The structure-aware agent (C) wins mostly on questions that need two or more documents, where it searches again for each missing fact. Its price is time: it is the slowest. All three declined the unanswerable questions almost every time. Full tables, charts and the paired statistics are in evals/report_heldout/report.md.
How it works
flowchart LR
D["36 public documents<br/>OAP 1, 30 OPCFs, 5 laws"] --> P["Parse + split by section<br/>link cross-references"]
P --> I["Indexes<br/>BM25 + embeddings"]
I --> A["A: naive RAG<br/>800-char windows, meaning search"]
I --> B["B: hybrid RAG<br/>sections, BM25 + dense, rerank,<br/>in-force dates, cited sections"]
I --> C["C: agent (LangGraph)<br/>B's search + a judge that lists<br/>needed facts, searches again"]
A --> L["Same model + instructions<br/>Claude Haiku 5.5"]
B --> L
C --> L
L --> V["Citation check<br/>every quote word for word"]
V --> E["Evals<br/>blind held-out set,<br/>paired statistics"]
- A, naive RAG: the baseline from a basic tutorial. Fixed 800-character windows, meaning search only, top passages to the model.
- B, structure-aware hybrid RAG: chunks never cross a section, so each can be cited by number. Keyword search (BM25) and meaning search are fused (Reciprocal Rank Fusion), a cross-encoder reranks, only versions in force on the policy date are searched, and sections the passages cite ("subject to section 268") are fetched too.
- C, agent: B's search, then a judge (the same Haiku model) writes down each fact the answer needs and which passage states it. A missing fact triggers a second, targeted search. Before replying, C checks its own quotes and answers once more if one fails.
The Architecture page walks through each step with a diagram and a real example.
The cost-weighted view
Accuracy treats every mistake alike; an insurance brokerage doesn't. Each answer gets a cost, a rough proxy for errors-and-omissions exposure:
| Outcome | Cost |
|---|---|
| Right answer, or declining an unanswerable question | 0 |
| "I can't determine" on a question the documents do answer | 1 |
| Wrong answer, low stakes | 5 |
| Wrong answer that could leave a client uncovered | 20 |
| Answering a question the documents can't answer | 20 |
So declining is cheap and a confident wrong answer is expensive. The report also shows
what each system would cost if it declined below a confidence threshold. The weights
live in config.COST_WEIGHTS.
How it was evaluated
- Tuning never touched the final test. Settings were tuned on 23 probe questions and a 63-question development set.
- The final test was written blind. Separate Claude Opus agents, who saw only the documents (never the code or the systems' answers), wrote 260 questions; independent reviewers fixed or dropped them, leaving 249. The systems were frozen at a commit before the set was opened, and pass criteria were declared before each run.
- Graded by an LLM, said plainly. Claude Opus graded every answer against the reference answer, blind to which system wrote it. No insurance professional checked the questions or the grades.
- Paired statistics. Systems are compared question by question (answers fixed and broken, McNemar's test, bootstrap confidence intervals), not by averages alone.
Limitations
- The questions, the reference answers and the grades all come from LLMs, not from an insurance professional.
- Only one edition of each FSRA form is public, and most state no dates, so the date questions rest mainly on the two SABS versions.
- The Fault Determination Rules' collision diagrams are images; only their text is indexed.
- C is the most accurate and the slowest (see the results table).
- The chat lives in the browser tab only; a reload starts over.
What I'd do at a real brokerage
- Start from the brokerage's own documents. Add the insurers' wordings and endorsements actually sold, with their editions and dates, through the same pinned, checked ingest.
- Have underwriters write and grade the test set. Replace the LLM-written questions and LLM grades with a set from real client questions, graded by licensed staff, and re-run all three systems on it before trusting any number here.
- Set the confidence threshold from the brokerage's own costs. Agree the cost of a wrong answer versus a referral with the E&O team, then pick the threshold on a separate set.
- Keep a human in the loop. Show answers to staff as a draft with its quotes, never directly to clients, and log every answer and its sources for audit.
- Watch it in production. Re-run the evals whenever a form, a law or the model changes, and track abstentions and corrected answers.
How I used Claude Code
Claude Code was the engineer; I decided. The way of working mattered as much as the code:
- Small steps, plan first. Each step began with a survey of the real data and a short plan; I approved the decisions before any code. Every step is recorded in SPEC.md, with its measured numbers and the designs that were rejected.
- Tests that can fail. Every module has tests on synthetic and real data. A mutation check then broke each rule on purpose to prove some test catches it.
- Independent audits. From data preparation to the first web page, two separate review agents audited each step, one hunting for wrong results on real data and one for design flaws. Every claim was re-checked on the data before acting on it. The last steps skipped them for time.
- An honest final test. Blind writers and reviewers, frozen systems, and criteria declared before each run (see above).
- Cost discipline. The whole project ran on a few dollars of API credit: every live run was estimated first and its spend recorded, and answers were cached and replayed.
Run it
Python 3.12 with uv, and Node for the frontend.
uv sync # dependencies (incl. Docling for ingest)
uv run python -m coveragecheck.ingest.download # verify the corpus files (saved by hand)
uv run python -m coveragecheck.ingest.parse # parse the documents
uv run python -m coveragecheck.ingest.chunk # sections, chunks, cross-references
uv run python -m coveragecheck.index.build # BM25 + dense indexes
cd web && npm ci && npm run build && cd .. # the React frontend
uv run python -m coveragecheck.web.api # http://127.0.0.1:8000
The answer model needs ANTHROPIC_API_KEY and ANTHROPIC_MODEL in .env (see
.env.example). uv run pytest runs the tests. The corpus files are public but not
redistributed here: data/CORPUS.md explains what is in and out and
why, and data/manifest.csv pins each file's source page and SHA-256.
Deploy: a two-stage Dockerfile (Node builds the frontend; Python 3.12
slim serves it and the API, with both embedding models baked in) runs on a Hugging Face
Docker Space. uv run python -m coveragecheck.deploy.space <user>/<space> uploads the
code and the prebuilt index in one commit.
Stack: Docling, bm25s, fastembed (bge-small-en-v1.5, MiniLM cross-encoder), numpy + parquet (no vector database), Claude Haiku 5.5 via the Anthropic SDK, Pydantic, LangGraph (System C only), rapidfuzz, FastAPI + React (Vite, Tailwind, shadcn/ui, Recharts).