Blog · AI engineering
High-fidelity RAG: reliable retrieval for cited answers
Why many RAG pilots stall, and the engineering that fixes them: query rewriting, hypothetical document embeddings, hybrid search with rank fusion, graph retrieval, passage-level citations and an evaluation loop.
Retrieval-augmented generation (RAG) is how most organisations put language models to work on their own documents. The simple version is: the user asks, the retriever pulls a few chunks, the model writes an answer. It demos well. It often fails in production.
It fails on vague questions, on questions that need facts from several documents, and on exact identifiers that vector search blurs. When retrieval misses, the model fills the gap, and the answer sounds just as confident. This post sets out the engineering that closes that gap, step by step.
Where naive RAG breaks
Three failure modes cover most problems:
- Vague queries. "Tell me about Log4j" matches many passages loosely and few precisely.
- Exact terms. Vector search treats
CVE-2021-44228as text that looks like other CVE numbers. Keyword search does not. - Connected facts. "Which contracts signed after 1 January 2023 have a liability clause referencing GDPR and were reviewed by the London legal team?" needs facts that live in different places. No single chunk holds the answer.
Each needs a different fix.
Step 1: improve the query before you search
Multi-query rewriting. Ask a model to rewrite the question several ways, then search with all of them. "Tell me about Log4j" becomes "Which vulnerabilities affect Apache Log4j?", "How is CVE-2021-44228 exploited?" and "How do we mitigate CVE-2021-44228?". Each rewrite reaches passages the original would miss.
Hypothetical document embeddings (HyDE). Ask a model to draft what an ideal answer would look like, embed that draft, and search with it. The draft carries the vocabulary of a real answer, so it lands closer to the right passages than a short question does. The method comes from Gao et al.. The draft is used only to search; it never reaches the user.
Step 2: search three ways and fuse the results
No single index is enough. Run them together:
| Retriever | Good at | Weak at |
|---|---|---|
| Keyword (BM25) | IDs, names, exact phrases, rare terms | Synonyms and paraphrase |
| Vector | Meaning, paraphrase, vague questions | Exact identifiers and numbers |
| Graph | Relationships across documents, filters by date, owner or type | Free-text nuance |
Merge the ranked lists with reciprocal rank fusion, which rewards passages that rank well in several lists without needing scores on the same scale. Then apply a reranker to the top results before they go to the model.
Step 3: connect the dots with a graph
For the contracts question, a graph can follow explicit paths: contract to clause, clause to regulation, contract to reviewing team, with the signing date as a filter. Vector similarity guesses at those links; a graph states them. Graph-based RAG also helps with summary questions across a large corpus, as Edge et al. show.
The graph is only as good as its entities. Resolve the same supplier, person or system appearing under different names into one node, and keep a link from every edge back to the passage it came from.
Step 4: cite every claim, and allow "not found"
Ask the model to answer only from the supplied passages and to attach a citation to every sentence: file, page and passage. Then check the citations in code: does the cited passage exist, and was it in the retrieved set? Drop or flag any sentence that fails.
Give the model an explicit way to say the sources do not answer the question. A correct refusal is a good result.
Step 5: evaluate continuously
Reliability drifts when documents, models or prompts change. Keep a test set of real questions with known answers, including some with no answer in the corpus. Measure:
- Retrieval recall: did the right passage reach the model?
- Faithfulness: is each sentence supported by its cited passage?
- Answer correctness: does the answer match the known one?
- Refusal accuracy: does the system decline when it should?
Open-source tools such as Ragas automate parts of this. Run the set on every change, and block releases that regress.
Keep the pipeline on your estate
Queries, retrieved passages, embeddings and indexes all contain your data. For sensitive work, run the whole pipeline, models included, where your law applies. We set out that test in the three pillars of sovereign AI.
Where to start
Take 50 real questions your users ask and log what the retriever returns for each. If the right passage is missing more often than you expected, fix retrieval before you change the model. RelataDB, our open-source knowledge engine, combines keyword, vector and graph search with identity resolution in one place. Autonous uses that approach to give answers cited to file, page and passage, on your own hardware.