Introduction · section 2 of 8
What you are going to build
The pipeline is the one behind the question box on a permit-test app for new drivers. A sixteen-year-old studying for the Maryland test types how far from a fire hydrant can I park? and reads, a few seconds later:
Stay at least 15 feet from a fire hydrant.
Sources: Md. Code, Transp. § 21-1003 · as of 5 Oct 2026
The sentence is the model’s. The line under it is not: it is written by code from the record the answer was checked against, and it names the part of the Transportation Article the number came from and the day that part was fetched from the General Assembly’s own site. If the model had written 20 feet, nothing would have been shown, because no law it named says 20.
The pattern has a name. Retrieval is the job of finding, in a body of text too large to send whole, the few passages most likely to answer a question. The body of text is the corpus, and in this book it is a state’s driver manual and vehicle code. A source is one passage of it that an answer may rest on, and a citation is the record of which one: the page or the numbered part of the code, with the source’s own words beside it. Retrieval-augmented generation, usually written RAG, is a model writing from retrieved sources rather than from memory. The pattern is older than the name and simpler than its reputation: find the right text, give it to the model, and check what comes back against what you gave it.
The deployed version of this pipeline answers for fifty states and the District of Columbia, from 172,000 passages of law, through a worker at the edge of a content network, with an index of meanings and a database behind it. You will build the same stages with a corpus of twenty-seven Maryland laws, in a directory on your laptop, in about 1,200 lines of TypeScript, and every stage you build is the stage the deployed one runs. Where the deployed one does something yours does not, the chapter shows its code and says why.
Everything you build lives in one directory, ask/. By the end:
- Chapter 1 makes one call to a model and reads the reply, then asks for the reply in a shape your code can check.
- Chapter 2 gives the model the corpus and the rules, and has it write only from what it was given, naming what it used.
- Chapter 3 builds the check. Every law the model named must be one it was given; every number it wrote must be stated by a law it named. This is the chapter the rest of the book depends on.
- Chapters 4 through 8 find the right laws: by the words they share with the question, by their meaning, by the law’s own vocabulary, by a second model’s judgement of which ones answer, and by lookups once the right part of the code is known.
- Chapter 9 builds the corpus so that it can be trusted: every passage word for word from a fetched copy, dated, hashed, and held to its sources by a test.
- Chapter 10 assembles the pipeline so that every model-backed stage is optional, and its absence is the pipeline as it was before that stage existed.
- Chapters 11 and 12 measure it against the live model, by hand and on purpose, and test everything around the model without ever calling one.
The deployed pipeline is published as a reading copy, with its design documents, at https://github.com/AiFirstDevelopment/howards-lantern-rag-pipeline. Every In production passage quotes it, and every number in those passages traces to a comment in its code or a document beside it.