Pathika

INSIGHTS / DATA & AI

RAG is a search problem: making AI answers you can trust

When an AI assistant answers from your documents and gets it wrong, the cause is usually the search step. How to measure retrieval, fix it and keep it current.

8 min read

Retrieval-augmented generation, usually shortened to RAG, is the standard way to make an AI assistant answer questions from an organisation's own documents. When a user asks something, the system searches the document collection, passes the most relevant passages to the model, and the model writes an answer from them. It sits behind most internal knowledge assistants, policy bots and support tools.

When these systems give wrong answers, the usual reaction is to blame the model for making things up. In our experience the more common cause sits one step earlier. The search returned the wrong passages, an out-of-date version, or nothing useful at all, and the model did its best with what it was given. Treat RAG as a search problem first and most quality problems become easier to find and fix.

Measure retrieval on its own

Most teams only evaluate the final answer. That makes problems hard to diagnose, because a bad answer could come from bad search, a confusing prompt or the model itself. Score retrieval separately. For each question in your test set, record which passages contain the answer, then check whether the search returned them and how high they ranked.

This one measurement changes the conversation. If the right passage came back and the answer was still wrong, work on the prompt or the model. If the right passage never came back, no model will fix it, and the work belongs in search. Our article on evals covers how to build the test set.

The content is the product

A RAG system can only be as good as the documents behind it. The usual problems are dull and common: three versions of the same policy with no sign of which is current, scanned PDFs with no readable text, tables that lose their meaning when converted, and the same navigation text repeated on every page. Search will happily return any of these.

How documents are split matters too. Passages that are too small lose context, so a sentence describing an exception gets separated from the rule it modifies. Passages that are too large bury the relevant part. Split along the document's own structure, such as sections and headings, and attach useful metadata to each passage: the source, its date, which product or region it applies to, and who is allowed to see it. Good metadata turns a vague search into a precise one.

Better search, and the right permissions

Semantic search, which matches on meaning, handles paraphrased questions well but struggles with exact terms like product codes, clause numbers and names. Keyword search has the opposite strengths. Running both and combining the results, known as hybrid search, is a sensible default. Adding a reranking step, where a second model reorders the top results by how well they answer the question, usually improves results further for a small cost.

Permissions belong in the search step. If a user is not allowed to read a document, it should never be returned for their question, so the access rules have to travel with each passage into the search index. Filtering after the model has already read the text is too late.

Cite sources, and know when to decline

Every answer should show where it came from. Citations let users check the answer against the source, build trust when it is right, and spot problems quickly when it isn't. They also make support easier, because a complaint about a wrong answer arrives with the passage that caused it.

The system also needs to know when to decline. If search returns nothing relevant, the right response is ‘I couldn't find this in the documents I have access to’, with a pointer to where to look or who to ask. An assistant that admits a gap is far more useful than one that fills it with a confident guess. Give refusals their own cases in the test set so this behaviour is checked on every change.

Keep it current

Document collections change every day. Policies are revised, products are retired, new procedures are written. A RAG system needs an ingestion pipeline that picks up changes, reprocesses the affected documents and removes outdated ones from the index, with monitoring that shows when the pipeline fails.

Run retrieval evals on a schedule as well as on every code change, because the content can drift even when the code doesn't. When the score drops, the cause is usually a batch of documents in an unexpected format or a source system that has stopped syncing. These are ordinary data engineering problems, which is why we build RAG as part of a data platform and treat the chatbot as the last step.

RELATED SERVICE

Data & AI Solutions

Building the data platforms, pipelines, retrieval systems and machine learning that let organisations put AI to work on their own data.

EXPLORE DATA & AI →

Next waypoint

Want to talk it through instead?

If this topic touches a challenge you're facing, we're happy to share what we've learned directly.

Get in touch