A compliance analyst needs to know whether an activity is permitted in a specific case. The applicable regulation spans four documents, with a general rule, exceptions that appear hundreds of pages later, and articles that refer to other articles. The analyst asks a general-purpose AI assistant. The answer arrives in seconds, well written, with an article number that exists. What the analyst doesn't see is that the article was amended by a later reform, and that the exception that changes the conclusion was never consulted.
That is the failure that costs the most to detect in an AI system built on documentation. It produces a plausible answer resting on the wrong source, with no visible error, and it gets discovered when someone who knows the material reviews it, or after it has already been acted on. Retrieval-augmented generation (RAG) exists to reduce that risk, and its success is also measured by how it behaves when retrieval fails.
What the model knows and what it doesn't
A language model answers from the patterns it learned from public text up to its training cutoff. It doesn't have your documentation, and when it lacks the data it responds with the most likely continuation. That is called hallucination: the model doesn't warn you that it doesn't know, it fills in with whatever sounds most probable, and the answer comes out with the same confidence as a correct one. So a regulation, a contract, or an internal manual the model has never seen gets answered with plausible sentences built on something else.
Attaching the full document to the question solves part of the problem, and with a document of reasonable size it can be enough. The limit shows up from several sides. The context window, which is the amount of text the model can read at once, isn't large enough for an organization's entire documentation. Even when the text fits, models make worse use of information placed in the middle of a long context than of information at the beginning or the end. And when the answer has to be auditable, a text of thousands of pages makes it impossible to know which part the model used to respond.
What each piece of a retrieval system does
The first step is splitting the documentation into chunks. Cutting at a fixed size splits articles in half and leaves an exception separated from the rule it modifies. Splitting along the document's own structure, one chunk per article or per clause, lets each piece keep its full meaning when it is retrieved.
Then comes the search. A search by exact words finds the article whose number appears in the question and the terms that the regulation defines literally. A semantic search works with embeddings, numerical representations of the meaning of a text, and finds chunks that talk about the same thing in different words. Each covers the other's blind spot, and combined they return the chunks most likely to contain the answer.
Regulatory documents cite one another, so retrieval follows the cross-references and also brings in the article that the retrieved chunk points to. When a reform has renamed a concept, a glossary translates the new term into the old one before searching. These are two tasks that someone who knows the material does from memory and that a basic search doesn't handle.
With the retrieved chunks in hand, the model writes the answer using only them, and each claim carries the literal sentence it comes from. A final step, with no model involved, checks in code that this sentence exists in the cited chunk. If it doesn't, the citation is discarded. That step is what turns an answer with sources into a verifiable answer.
Where retrieval fails
When the result is wrong, the cause can sit in different places, and each one is fixed with a different intervention.
- The answer isn't in the documentation.** The question falls outside the loaded material. This is the case where a system with no defined behavior for finding nothing is more likely to invent, because it retrieves the least-bad chunks and the model tries to build something from them.
- The right chunk exists and isn't retrieved.** The question uses vocabulary different from the document's, or the chunk was cut badly. It is fixed in the chunking, in the glossary, or in the search.
- The right chunk is retrieved and the model misreads it.** The answer contradicts or extrapolates beyond what it cites. The instruction to the model and the citation check come into play here.
- The retrieved chunk belongs to an outdated version.** The documentation changed and the search keeps working on the earlier version. It is fixed by updating the modified files.
Telling which of these happened is what makes it possible to fix the right problem, and looking only at the final answer rarely tells you.
What the system does when it doesn't find anything
The fallback policy is the decision about what happens when retrieval returns nothing sufficiently relevant. The correct response in that case is that the system doesn't find the data in the documentation, accompanied by the closest chunks it did find so the person asking can judge them. Answering anyway with the least-bad material produces the failure described at the start.
What counts as sufficiently relevant depends on the cost of each error. The system decides with a similarity threshold, the minimum value a chunk must reach to count as a match, and that value is set according to that cost. A user who gets a "can't find it" when the answer existed loses a few minutes. One who gets a wrong answer on a query that feeds a regulatory or contractual decision bears a much higher cost. That is why the threshold is strict where an error is expensive and more permissive where a rough orientation is enough.
The policy also defines who receives the case when the system abstains. It can be routed to a person with the question and the chunks found attached, so they don't start from scratch, or the query can be reformulated automatically to retry the search. The second option adds a component that decides on its own when to retry.
How to measure that it works
A system of this kind is evaluated with a set of questions whose correct answer is already known to the team that will use it. The set should include questions whose correct answer is that the data isn't there, because they are the only ones that test the fallback policy. Without them, the system passes everything it answers and nothing it should stay silent on.
The evaluation measures two things separately. One is whether the right chunk appeared among those retrieved, and the other is whether the written answer holds up against what it cites. Measuring them together hides where the error is, and the fix is different in each case, as the earlier section shows. The test is repeated every time the documentation or the system changes.
Back to the analyst
With a system built this way, the compliance analyst's same question has two possible outcomes. The analyst can receive the exception that changes the conclusion, with the literal sentence from the amended article and confirmation that the sentence exists. Or they can receive a "can't find it in the documentation," with the closest chunks to judge for themselves. In both cases they know how much to trust what's in front of them. Building it takes more work, but it is work that pays off in precision where an error can be very costly.