DEV Community

Deployed Lab
Deployed Lab

Posted on

Your AI said 14 days. The policy says 30. The fix is an open-book exam

Your AI said 14 days. The policy says 30. The fix is an open-book exam

A support assistant tells a customer, "You have 14 days to request a refund." The real policy says 30 days. It also quotes a contract line that only Legal may read. The English is fluent. It was simply handed the wrong pages.

This is the most common failure in company AI, and it is not a fluency problem. The model knows the world, but not your private files. Ask it cold and it guesses, confidently. Let it look through the right pages first and it is usually correct. That second way has a name: RAG, retrieval-augmented generation. Fetch the right pages, then write the answer from them. It is an open-book exam.

Three helpers and a desk

Picture the exam: a student who has never worked at your company must answer a question about your refund policy. Three helpers stand between the student and the shelves.

The Librarian (search) takes the question to the shelves and brings back pages that look like a match. The Guard (permission check) removes pages the asker may not read. The Reader (re-ranking) is a slower, more careful second sort that puts the best page first. Only a few pages fit on the desk, the context limit, so the order decides what the student sees.

In technical terms: once, in advance, you shelve the pages (split documents into chunks, embed them, stamp each with who may read it). On every question, the system searches, checks permission, re-ranks, builds one prompt from the top pages, and writes the answer from them, naming sources and saying "I don't know" when the pages lack the answer.

Here is the whole prompt: rules (answer only from these pages, name the page after each fact, trust the newest version, say "I don't know" when the pages lack the answer), then the top three pages, then the question. There is no more magic than this. The Legal-only contract page is not in it. The permission check dropped it before the message was built, so the AI cannot quote it, even by accident.

Why search needs two kinds of matching

Meaning search alone has a blind spot. In a small lab, the question "How long do Enterprise customers have to request a refund?" scored on meaning alone: marketing FAQ 0.88, old policy 0.82, current policy 0.74. The FAQ wins, and it names no days.

Hybrid search mixes half meaning and half exact keywords. The current policy scores 0.95 on keywords, because it holds "Enterprise" and "refund". The sums: current policy 0.5 x 0.74 + 0.5 x 0.95 = 0.845; old policy 0.5 x 0.82 + 0.5 x 0.55 = 0.685; FAQ 0.5 x 0.88 + 0.5 x 0.35 = 0.615. The current policy wins, and the answer becomes 30 days.

Keyword search earns its place on exact strings. A repair shop searches for "valve V-7731": meaning search returns general valve guides, because a part number has no meaning to match, while keyword search finds the page that holds it. Each kind of search has a blind spot the other covers.

Re-ranking is the third lever. A careful second reader gives its own scores (current policy 0.97, old policy 0.30, FAQ 0.20) and puts the current policy first. But it can only re-sort pages search already found. If search never found the right page, the re-ranker cannot save it.

Re-ranking is a decision, not a default. Search costs tens of milliseconds; re-ranking costs hundreds plus about $2 per 1,000 questions on a hosted re-ranker (Cohere Rerank, as of November 2026). Writing the answer takes seconds, the wait the user actually feels. Turn re-ranking on when the order is costing you correct answers, not just because it exists.

When the answer is bad, which stage do you blame?

Each stage has its own typical failure. Check them in order, because each stage feeds the next and an early fault hides later ones.

Chunks too small lose context ("30 days" alone does not say which plan); chunks too big bury the answer in noise. Fix it by testing a few chunk sizes on real questions. Meaning search is weak on codes like "V-7731": fix it with hybrid search. Nothing earlier knows who is asking: fix it by storing an access list with every chunk and filtering before the prompt is built. Only the top few pages fit in the prompt: fix it with a re-ranker. Retrieval was fine but the AI went beyond its pages: fix it by telling it to answer only from the pages, name sources, and say "I don't know".

The field numbers make the case for measuring, not eyeballing demos. On a fixed test set of 50 real questions, hybrid search put the right page in the top 3 for 44 of them; meaning-only search managed 31. The exact numbers vary, but the gap is the point. Nobody found it by watching demos. They found it by scoring the same 50 questions every time they changed a stage.

Two mix-ups to drop. RAG does not teach the AI your documents: pages are looked up for each question, then forgotten. And a rule in the prompt does not keep secrets safe: "never reveal secrets" is a request, not a lock. A page the AI never receives cannot be repeated, so the permission check must happen before the prompt is built.

The costliest RAG bug is a correct answer built from a document the asker was never meant to see. A consultant demos a company assistant to a new intern, who asks about pay bands. It answers from an executive memo: correct, and never meant for the intern. Store the access list with every chunk from day one, and test while logged in as a low-privilege user.

The full interactive chapter, with a lab where you switch each stage on and off and watch the answer change, is free at https://deployedlab.dev/lessons/09-rag-end-to-end. 11 chapters are free with no signup, and the full course is $5/month or $39/year at deployedlab.dev.

Top comments (0)