I Built RAG by Hand So I’d Know Where It Breaks

Ask almost anyone how to make a language model answer questions about your own documents and you’ll get the same four words: chunk, embed, retrieve, generate. Split the documents into pieces, turn each piece into a vector, find the pieces closest to the question, and hand them to the model to write an answer. It sounds like a solved problem with a tidy recipe. I built it from scratch this semester, without any framework, for the same reason I hand-wrote regex before learning classifiers: I wanted to see every seam before something hid them from me. What I found is that nearly every wrong answer my system gave was a retrieval failure, and retrieval is the part almost nobody talks about. (A small milestone on the side: my voice assistant paper went live in AIJR on 17 March, eleven months after I presented it. I was not exaggerating about academic timelines.)

The chunks that meant nothing

I began by splitting documents into fixed blocks of five hundred characters, because every tutorial does. The results looked fine until I read what the model was actually receiving. One chunk was a row of numbers whose column headings had been left behind in the previous chunk. Another began “it was discontinued in 2021,” with the “it” sitting several hundred characters earlier on the wrong side of a boundary. Those chunks produced lovely embeddings and carried almost no meaning. A table flattened into a paragraph turns out to be a hallucination generator, because the model sees numbers without labels and confidently invents the relationship between them.

Switching to chunking that respects the document’s own structure, keeping headings with their sections, keeping tables whole with their header rows, and overlapping slightly where content runs across a boundary, improved my answers more than any change to the model all semester. It’s an unglamorous lesson, but I now think chunking is the single highest-leverage decision in the whole system.

Searching the wrong way

The second surprise was how often the right chunk simply never came back. The model would reason carefully and correctly over a paragraph that had nothing to do with the question. If you’re debugging a system like this and you haven’t recorded what was retrieved for each question, you’re debugging the wrong half of it. Once I started logging retrievals, the pattern was obvious. Vector search is wonderful at paraphrase: it knows “how do I get my money back” is about refunds. It’s surprisingly poor at exact identifiers, though, and a question about error code E-4021 or a specific form number would return something vaguely related instead. Old-fashioned keyword search has exactly the opposite strengths. Running both and merging the results beat either alone, which meant the TF-IDF I’d learned for my 2023 chatbot came back from the dead to be useful. Nothing in the fundamentals really dies. It just waits.

Conversation added a third failure. After a good answer about refunds on annual plans, a user asks “and what about the other one?”, which is a useless thing to search for. The fix was a small step before retrieval that rewrites the latest message, using the conversation so far, into a complete standalone question, such as “what is the refund policy for monthly plans?” It fixed an entire category of follow-up failures at once. It’s obvious once stated: even the best search engine can’t find documents for a query that doesn’t contain the question.

Teaching it to refuse

The last failure was the most dangerous. The polite approach is to tell the model in the prompt to answer only from the context you’ve provided, and that mostly works, which is exactly the problem. When retrieval returns nothing useful, a model with nothing to ground on still produces a fluent, confident, invented answer. That follows directly from what I worked out last summer: it’s sampling plausible continuations, and “I don’t know” is rarely the most plausible one. So I moved the rule out of the prompt and into code. If retrieval confidence falls below a threshold, the system declines and says where else to look; if it does answer, it has to cite the chunks it used. This is now the third project in a row where the same principle has appeared. My chatbot’s crude fallback, my voice assistant’s dead air, and now this all point the same way. A system that admits uncertainty earns trust, and a system that bluffs once loses it.

The thing I can’t measure

Here’s where I’ve been stuck for two months. I’ve built something that seems to work, and I can’t tell you how well. There’s no accuracy figure, no ground truth, and no test set for “answered faithfully from the documents.” When I change the chunking, I get a vague sense that things improved, which isn’t a measurement. It’s a mood.

I’ve read around for solutions, and each has a catch. Comparing answers against reference answers works for factual lookups and breaks the moment the wording differs. Asking humans to judge is the real ground truth and doesn’t scale. Using another model as a judge with a scoring rubric scales nicely and has biases nobody seems to measure carefully. Retrieval metrics tell you whether the right chunk came back and nothing about whether the final answer was any good. Nobody has a clean answer, which is strangely comforting. I’m not missing a technique. I’ve walked into an open problem from the practical side.

The pattern I keep noticing is that every case where I can check a model’s output reliably involves something outside the model doing the checking. Code has compilers and test suites. A schema has a validator. A factual claim has a source document. “Is this a good answer” has nothing yet. That feels important, and I don’t have a theory for it.

Leave a Reply