Skip to content
Writing

Case study

The right page, for the right car

An agentic GraphRAG case study: 441,000 factory service documents, a knowledge graph that records which vehicles each one actually covers, and an agent that answers a mechanic in about ten seconds, citing the page it read.

A mechanic has a 2021 full-size SUV on the lift and one question: what's the torque on the rear caliper bracket? The answer is printed on one page of one factory PDF. There are 441,000 of those PDFs, and there's a good chance the right one is filed under a different car.

This is the system that finds that page and answers with it. It has three parts: a pipeline that reads the PDFs, a knowledge graph that records which vehicles each document covers, and an AI agent that has to open a page before it's allowed to quote it.

9×as many of the right documents reachable for a car267 → 2,347 for one SUV
0%of searches come back emptywas 100% in our first benchmark
68%of answers correct on documents we never tuned on56 / 60 on the set we tuned against
~10 sto a full answer that cites its pagefirst words at 6 s
Role
Lead engineer. I designed and built the ingestion pipeline, graph schema, retrieval, agent tools and the evaluation harness. The rest of the team built the product around them.
Timeline
Jun 2025 – Oct 2026; retrieval and evaluation rebuilt Aug – Oct 2026
Team
Five engineers
Scale
441k documents · 2.9M searchable passages · two carmaker groups
Stack
Python, Neo4j 5 (vector + full-text search), PyMuPDF, pydantic-ai, OpenAI embeddings, Kubernetes, object storage
Terms used in this post
  • Passage (chunk): a page-sized piece of a document. Search ranks passages, then the agent opens whole documents.
  • Embedding: a list of numbers that captures what a passage means, so passages with similar meaning sit close together. "Search by meaning" compares embeddings.
  • Keyword search: classic full-text search on exact words and codes.
  • Approximate index: a structure that finds the closest embeddings fast by not checking every one. k is how many results you ask it for.
  • APPLIES_TO: our link in the graph from a document to each vehicle it covers.
  • Reranker: a second model that re-reads the top results and reorders them.
  • Tokens: the units a language model reads and writes, roughly three quarters of a word each.

The problem: the right page, filed under the wrong car

The documents come from two carmaker groups, about 90% from one large US group. They arrived as PDFs in a cloud drive, in one folder per vehicle. Four properties of that pile shaped every decision that followed:

  1. The folder isn't the coverage. A service bulletin filed under one vehicle can apply to twenty. A shared engine manual sits under one model and covers five.
  2. Everything has a near-twin. The same procedure appears almost word for word across about 35 variants of one pickup truck.
  3. Codes matter more than prose. Mechanics type fault codes like P0301. To a language model, P0301 (a misfire in cylinder 1) and P0300 (a random misfire) look almost the same.
  4. A wrong answer is worse than none. A torque value from the wrong engine is a safety problem, so every number the agent gives has to trace back to a page it actually read.

So the question was never "how do we search 441,000 PDFs?" It was "how do we search only the documents that apply to this car, and prove where every answer came from?"

System overview in three stages: read the PDFs into embedded passages, tag which vehicles each document covers as APPLIES_TO links in a Neo4j graph, then answer by resolving the vehicle, searching only its documents and citing opened pages. Below, one question traced through: 2,347 documents cover the asked SUV, against 267 by folder.
Fig. 01The system in one picture. The rest of this post follows one question from left to right.

1 · Teach the graph which car each document covers

Search can only narrow to the right car if the data knows which car every document is for. The source only said where each file had been filed.

So every document got a tag pass. An LLM reads the first 12,000 characters and fills in a fixed form: which vehicles it covers, model years, engine and transmission codes, document type, and a one-line summary. The output is checked against a strict schema, so it can't invent a field. Each covered vehicle becomes an APPLIES_TO link in the graph, carrying its own years. Tagging the whole corpus cost about $150.

Graph schema: Brand MAKES Model, Model CONTAINS Document, Document APPLIES_TO Model, Chunk BELONGS_TO Document, Chunk FOLLOWS Chunk, Chunk HAS_SCHEMATIC Schematic. One SUV reaches 267 documents by folder and 2,347 by coverage.
Fig. 02The graph. Where a document was filed (top) comes from the folders. What it applies to (red) comes from the tagger, and it's what search narrows on.

For the SUV in our opening question, that changed what search could even see. By folder, 267 documents belonged to it. By coverage, 2,347 do. The extra 2,080 are bulletins and shared manuals filed under sister vehicles, which is exactly where answers had been hiding.

2 · Check the search index before trusting it

The first measurement we took changed how we built everything after it.

Searching 2.9 million passages by meaning uses an approximate index: it trades a little accuracy for a lot of speed. In Neo4j's version, the number of results you ask for also sets how hard it searches. Ask for a few and it doesn't just return fewer. It searches less carefully and returns wrong ones, with confident-looking scores and no error.

Bar chart of how many of the true top 10 passages come back by the k requested: 5.8 of 10 at k=10, 8.8 at k=50, 9.8 at k=200 and 10 at k=1000, taking 25, 37, 67 and 183 ms.
Fig. 03Ask the index for 10 results and only 6 of them are the true top 10. Ask for 200 and keep the best 10, and 98 in 100 are right, for about 40 ms more.

The same trap hit the small index of about 400 vehicle descriptions that turns "2021 full-size SUV" into a specific vehicle. Asked for 50 results, a query about one sedan dropped the correct car entirely and put the fifth-best match first. With so few entries, the fix is to ask for more results than exist. The search then checks everything, and it's still faster than the approximate version.

3 · Narrow to the car, then score

Even a well-tuned index can't solve the near-twin problem. For one pickup variant, its 2,924 passages each sat behind thousands of identical passages from other variants. Searching everything and keeping the top 2,000, or even the top 20,000, returned zero passages for the right truck.

When we first ran the benchmark on the live graph, the original search came back empty in every case, and the fallback filled answers with other cars' pages. So the agent's search tool now works in four steps:

Four steps: find the vehicle (~10 ms), narrow to the documents linked to it by APPLIES_TO (44–60 ms), route codes to keyword search and everything else to meaning search, then score every passage in that set exactly (0.5–3.8 s) and return up to 40 short references.
Fig. 04One call to the agent's search tool. Steps 1 and 2 use the graph. Step 4 only looks inside the car's own documents.

Narrowing through the APPLIES_TO links takes 44–60 ms. Once narrowed, the car's passages can be compared against the question one by one, with no approximation at all. That turned out to be both faster and more complete than searching everything:

Bars for three vehicles: approximate global search takes about 6.4 to 6.5 seconds each; exact comparison inside the car's documents takes 0.47, 0.71 and 3.8 seconds.
Fig. 05Three vehicles where searching everything did return results. To leave enough of the car's passages after filtering, it has to ask for 100,000 results, which is why it takes seconds here rather than the milliseconds in Fig. 03. In one comparison, the exact search also found 120 matching passages from 63 documents, against 30 from 18.

After the change, empty results went from 100% to 0%, and in a sample of 30 searches, all 30 results were for the right vehicle.

4 · Codes need keywords; descriptions need meaning

Search by meaning is nearly blind to codes. For the misfire code P0301, it found 2 of 29 relevant documents. Plain keyword search found 20.

The textbook fix is to run both searches and blend the two ranked lists. On synthetic test questions, that looked like a two-point gain. On real mechanic questions, the blend beat the better of the two searches in 0 of 16 comparisons, because the two lists hardly overlapped.

So the tool picks one search by the shape of the question. Anything that looks like a fault code, a part number, a torque value or a fuse number goes to keyword search first. Everything else goes to meaning search first. Each falls back to the other only if it comes back empty.

5 · Make the agent show its work

Once search worked, the remaining mistakes came from how the agent used its tools. Four changes did most of the work:

  • Tool descriptions decide which tool gets called. In 8 of 11 early failures, the agent never searched the graph at all, because another tool's description claimed the same kind of question. Now each description names what the tool covers, so they don't overlap.
  • List first, then open. Returning 40 full documents cost about 22,000 tokens per search and answered no better than 20. Now search returns 40 short references with a one-line preview, and the agent opens only what it needs. We shortened the preview from 600 characters to 150 after we caught the agent answering from previews alone.
  • No citing what you haven't opened. The agent can only cite a document it opened, and every torque value it gives is checked against that page. Before this, 3 of 81 test runs gave the right answer with no source.
  • Filters that hide answers become sort orders. Filtering by document type cut one sedan's documents from 1,149 to 200, which often removed the answer. Now type only changes the order.

Results: what the mechanic gets

A typical question gets a full, cited answer in about 10 seconds. The first words appear at about 6 seconds. Every number in the answer links to the page it came from.

We measured accuracy on two levels.

Is the right document in what the agent sees? We used 250 blind test questions: 150 from the US group's documents and 100 from the European group's. An LLM wrote each one from a passage it was shown, never from the document's title. A small boost for the asked vehicle's own documents took first place from 58% to 62%, and that boost is shipped.

Grouped bars: the right document ranked first 58% at baseline and 62% with the own-vehicle boost, top 3 74% and 78%, top 10 85% and 86%, top 40 90%; an LLM reranker lifts first place to 69%. About 4% are never retrieved.
Fig. 06The right document is ranked first 62% of the time and is in the list the agent sees 90% of the time. Most misses are ranked too low, not missing. A reranker fixes exactly that: +7 points, but it adds 2.7 seconds.

Does the agent answer correctly? Each question runs several times, because agents don't give the same answer twice:

test setwhat it checksresult
First test set (20 questions × 3 runs)correct, cited answer32/60 → 56/60
Same kind of questions, new documents (24 questions, 71 runs)does it generalise?48/71 (68%)
Coverage set (27 questions × 3, 9 question types)grounded, cited answer80/81
cites the exact expected document67/81
Stress test (20 questions × 5 runs)answers about the wrong brand · runs that gave up0 · 0
Hard set (13 questions × 2 runs), built from known failurescorrect, cited answer10/26

The biggest speed win had nothing to do with search. Turning the model's reasoning effort down to its minimum took one agent step from 16.3 s to 5.2 s, with more visible output. 44% of every answer's tokens had been hidden reasoning.

Latency in detail
hosted, streamedmedian90th percentile
first streamed update1.0 s1.3 s
first words of the answer6.1 s7.4 s
full quick answer9.8 s11.1 s
full diagnostic report, a separate slower mode (three likely causes, each investigated)223 s—

What's still broken

  • New documents score lower. The first test set reached 56/60 partly because we tuned against it. On documents it had never seen, the same kind of question scored 68%. That gap is overfitting, and it's the number to watch.
  • The hard set is at 10/26. Most of its failures are the diagram tool offering a diagram from the wrong model year. That's the top of the backlog.
  • The reranker is parked. It adds 7 points of first-place accuracy, but it would make a 10-second answer take nearly 13. That trade-off is the product team's call.
Under the hood: the ingestion pipeline

The pipeline has two stages that never wait on each other. Producers download each PDF, extract its text, have an LLM name it from at most four pages, and write it to the graph. Chunkers claim documents by marking them in the graph itself, so there's no queue to run. They split each document page by page, keep the pages in reading order, drop logos, upload page images, and embed every passage.

The first runs were slow for a reason that wasn't obvious. Database writes were blocking the program's event loop, so 16 parallel tasks were really running one at a time. Moving those writes off the loop made it 4.4× faster. Splitting the work across processes instead of threads gave another 2.5×. It settled at about 12,000 documents an hour on one 4-core machine. When we rebuilt the graph from scratch in October, it was rebuilt and verified in under two days.

Diagrams drawn as vector art. One carmaker draws wiring diagrams as vector art, so 11,233 of 11,809 diagram documents had no image to extract. We render each page and ask a vision model whether it's a diagram. On 146 hand-checked pages, gpt-4.1-mini got all 146 right. With a cheap pre-check that skips half the pages, the whole backfill cost about $8.

Bugs that only showed up at scale:

  • The shared embedding client returned nothing on errors. During a credit outage, ingestion ran for 9 hours writing passages that couldn't be searched.
  • Very large PDFs got processed twice, because a worker's claim expired after 45 minutes and some jobs ran longer.
  • Archives unzipped into a folder of their own name, which created 7,959 duplicate documents.
  • A full rebuild shipped with zero PDFs uploaded, because the upload failure was only logged as a warning.

Every rebuild now ends with pass/fail checks written as graph queries: no document without passages, no passage without an embedding, no broken reading order.

Under the hood: what we tried and reverted
  • Stripping repeated boilerplate before embedding. First-place accuracy went from 49% to 48%, and found-at-all from 87% to 82.5%. Cleaner text pushed near-topic competitors above the right documents.
  • Assuming a document covers every year of its folder. Of 90 cases we checked by hand, 62 were year-specific bulletins that happened to sit in a wide folder.
  • Ranking on the one-line summary. "Air compressor" matched "air-conditioning compressor".
  • Blending three searches instead of two. The same accuracy, at 5.5 s instead of 0.4 s.

Lessons

  • Narrow before you score. When most of a collection is near-duplicates, searching everything and filtering afterwards fails at any size you can afford.
  • Measure the tools you trust. A default nobody chose was quietly returning 6 of the right 10.
  • Where a file is stored is a hint. What it covers is data you have to build.
  • Test sets are code, and they have bugs. Three times the agent's score "dropped", and each time the test was checking the wrong field while the agent hadn't changed.

The model was never the bottleneck. The work was everything around it: teaching the graph what each document covers, and teaching the agent what it's allowed to cite. The same assistant also searches two billion documents from older factory manuals. That's the other case study.

Aryan Gurav — MumbaiMore writingTop