News / Learn / Retrieval-augmented generation (RAG)
Why does RAG fail and how do you fix it?
You'll be able to find the main reasons a RAG system gives wrong answers and fix them in the right order.
In plain English
Retrieval-augmented generation (RAG) means you search your own documents, then give the best matches to a language model and ask it to answer from them. Most failures happen before the model writes anything. The search finds the wrong text, or the right text never made it into the prompt. The model then does its best with bad input.
Why it matters
Teams often blame the model when answers are wrong. In most RAG systems the weak point is retrieval. If you don't measure retrieval separately, you will spend time and money on the wrong fix. Knowing the failure points lets you change one thing at a time and see what helps.
How it works
A RAG system has a few stages: split documents into chunks, turn chunks and questions into embeddings, find the closest chunks, and pass them to the model. Each stage can fail. Chunks can cut an answer in half or hold too much unrelated text. Embeddings can match on topic but miss the exact fact. The top results can be ranked poorly, so the useful one falls below the cutoff.
The usual symptoms have distinct causes. If the right passage was never retrieved, the problem is retrieval: chunking, the embedding model, or the number of results. If the right passage was retrieved but the answer is still wrong, the problem is ranking or the prompt. If the answer contradicts the retrieved text, the model is not grounded, so the prompt needs to tell it to rely only on the sources and to say when they don't contain the answer.
Questions also differ from documents. A user might ask with different words, a typo, or a reference like 'the new policy'. Exact keyword search misses synonyms. Pure vector search can miss rare names and codes. Hybrid search, which combines keyword and vector matches, often handles both.
The fix starts with a test set. Write real questions, record which document holds each answer, and check whether that document appears in the retrieved results. That single measure, retrieval recall, tells you where to work next.
A concrete example
A simple check: for each test question, see whether the known source appears in the top results.
def recall_at_k(test_cases, search, k=5):
hits = 0
for case in test_cases:
results = search(case["question"], top_k=k)
if any(r["doc_id"] == case["expected_doc_id"] for r in results):
hits += 1
return hits / len(test_cases)
# Run before and after each change.
# If recall is low, fix retrieval first.
# If recall is high but answers are wrong, look at ranking and the prompt.A short sketch to show the idea. Check the official docs of the tool you use.
What goes wrong
- Blaming the language model first Measure retrieval on its own. If the right source isn't in the results, a better model won't recover it.
- Chunks that split or lose context Check chunks by reading them. Keep related text together, and add a title or section heading to each chunk so it makes sense alone.
- Too few results retrieved Retrieve more candidates than you need, then rank or filter them. Passing only one or two chunks risks missing the answer.
- No instruction to stay within the sources Tell the model to answer only from the provided text and to say so when the answer is missing. Include the source in each answer so people can check it.
- Changing many things at once Change one part, such as chunk size or the embedding model, then rerun your test set. Otherwise you can't tell what helped.
Going deeper
Learn hybrid search, reranking, and how to build an evaluation set with real user questions. Then study how to measure faithfulness, meaning whether the answer is supported by the retrieved text.
FAQ
Is a bad answer always a model problem?
No. Many bad answers come from retrieval, where the correct passage never reached the model. Check whether the source was retrieved before changing the model.
How do I know if retrieval is failing?
Build a small set of questions with known source documents. Count how often the right source appears in the top results. Low counts point to retrieval.
Will a bigger context window fix RAG failures?
Not by itself. More text can add noise and dilute the useful passage. Better retrieval and ranking usually help more than sending more chunks.
Why does the model ignore the retrieved text?
The prompt may not tell it to rely on the sources, or the sources may not contain the answer. Clarify the instruction and allow it to say the answer is not found.
Do I need a vector database to start?
No. A simple index can work for small collections. Start with a test set and measure before adding infrastructure.
Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.