When an AI answers badly from your own documents, people blame the search. Every time I've debugged it, the search was fine. The documents were the problem.
Imagine asking a very smart person a question about a subject they have never studied. You hand them a few pages to read first. If the pages are wrong, being smart won't help. If the pages are right but torn in half, it's even worse.
That's RAG, short for retrieval-augmented generation. The name is fancy, but the idea is simple. You search your documents for the parts that matter, paste them in front of the question, and the AI answers using only those parts.
When the answers are bad, everybody blames the searching. I think the searching is usually innocent.
Every system I've worked on hit the same problem. Answers were poor, so we swapped the search model. We added a re-ranker (a second step that re-sorts the results). We added keyword search, rewrote the question three ways, and fetched more results. Each change sounded smart. Each one made things slower. The answers stayed bad.
The search was finding the right pages the whole time. The pages just weren't worth finding.
First, print exactly what got handed to the AI and read it like you have to answer the question yourself. On AssistFlow AI, a support tool that reads a customer's website and answers from it, the answers were vague. So I printed the pages for one failing question. The top result was a navigation menu. The second was a cookie banner. The third was the correct paragraph, chopped in half right at the sentence with the answer.
Documents are too big to hand over whole, so you cut them into small pieces called chunks. Most people start with "cut every thousand characters, with a little overlap." That quietly assumes meaning comes in thousand-character lumps, and for most real documents it doesn't.
Think of a recipe cut in the middle of step four. You're left with half a procedure. Or a "Refund policy" page that says this does not apply to annual plans. Cut it badly and one chunk now says the opposite of the truth. So for each kind of document, decide the smallest piece that still makes full sense: one FAQ answer, one API endpoint, one policy section with its heading attached. Sometimes the right setting is don't cut this at all.
Both happen when you store the documents.
Put the lost context back. Paste the document title and the heading trail on top of each chunk, so it reads Refund policy → Annual plans → the text. It's like writing the subject name at the top of every page. In my experience this one change has saved more systems than every re-ranker I've ever added.
Store labels, then filter on them. The AI can't tell that a page is out of date, so it'll happily hand over a pricing page from two years ago. Product, version, date, language and customer are cheap labels. With them, many "the AI made something up" complaints become a simple filter.
Without test questions, every change only feels like it helps. Write thirty questions where you already know which document has the answer. Then check two things. Did the right chunk show up? And given those chunks, was the answer right?
Two honest signs. Exact codes failing: to a meaning-based search, ERR_4021 and ERR_4012 look almost the same, so run old-style keyword search alongside it. Questions that are secretly two questions, like how do I move off the free plan, and what happens to my old exports? Split those into two searches.
Reach for these when your tests point at them, not by default.