RAG (Retrieval-Augmented Generation) combines retrieving relevant documents and generating answers. The key metrics are retrieval accuracy (how well the system finds useful documents) and generation quality (how correct and fluent the answer is). Retrieval accuracy is often measured by recall or precision on retrieved documents. Generation quality is measured by metrics like BLEU, ROUGE, or human evaluation. Both matter because good retrieval helps the generator produce better answers.
RAG architecture overview in Prompt Engineering / GenAI - Model Metrics & Evaluation
Start learning this pattern below
Jump into concepts and practice - no test required
Retrieval Results Confusion Matrix (example):
Retrieved Relevant Retrieved Not Relevant
Relevant Docs TP = 80 FN = 20
Not Relevant Docs FP = 15 TN = 85
Total Docs = 200
Precision = TP / (TP + FP) = 80 / (80 + 15) = 0.842
Recall = TP / (TP + FN) = 80 / (80 + 20) = 0.8
Generation quality is often evaluated separately using scores like BLEU or ROUGE, not confusion matrices.In RAG, precision means the retrieved documents are mostly relevant, so the generator gets good info. Recall means the system finds most of the relevant documents, even if some irrelevant ones sneak in.
Example: If you want very accurate answers, high precision is important so the generator is not confused by bad info. But if you want to make sure no important info is missed, high recall is key.
For example, a medical question answering system should have high recall to avoid missing critical info, even if some irrelevant documents are retrieved. A customer support bot might prefer high precision to avoid giving wrong answers.
- Good retrieval precision: Above 0.8 means most retrieved docs are relevant.
- Good retrieval recall: Above 0.75 means most relevant docs are found.
- Good generation quality: BLEU or ROUGE scores above 0.5 (50%) are decent; human evaluation should confirm fluency and correctness.
- Bad values: Precision or recall below 0.5 means poor retrieval, leading to bad answers. BLEU/ROUGE below 0.3 usually means poor generation quality.
- Ignoring retrieval quality: Good generation scores alone can hide poor retrieval, causing unreliable answers.
- Overfitting to training data: High scores on training but poor real-world retrieval or generation.
- Data leakage: If test documents appear in training, metrics look falsely high.
- Accuracy paradox: High overall accuracy but poor recall on rare but important documents.
Your RAG model has 98% accuracy on generated answers but only 12% recall on retrieving relevant documents. Is it good for production? Why or why not?
Answer: No, it is not good. The low recall means the system misses most relevant documents, so the generator may not have enough info to answer well in many cases. High accuracy alone is misleading if retrieval is poor.
Practice
Solution
Step 1: Understand the role of retriever in RAG
The retriever searches a large collection of documents to find relevant information related to the question.Step 2: Differentiate retriever from generator
The generator uses the retrieved information to create a natural language answer, not to find documents.Final Answer:
To find relevant documents or information from a large dataset -> Option AQuick Check:
Retriever = Find info [OK]
- Confusing retriever with generator
- Thinking retriever generates answers
- Assuming retriever evaluates answers
Solution
Step 1: Recall RAG workflow
RAG first retrieves relevant documents to provide context for the answer.Step 2: Understand generation step
After retrieval, the generator uses the documents to produce a final answer.Final Answer:
Retrieve documents first, then generate answer -> Option BQuick Check:
Retrieve before generate [OK]
- Thinking generation happens before retrieval
- Mixing training with retrieval steps
- Confusing evaluation with generation
retrieved_docs = retriever.search(query) answer = generator.generate(retrieved_docs, query) print(answer)What will be printed if the retriever returns an empty list?
Solution
Step 1: Analyze retriever output
The retriever returns an empty list, meaning no documents found.Step 2: Understand generator behavior
The generator tries to create an answer without context, so it may produce a generic or less accurate answer, but no error occurs.Final Answer:
An answer generated without context, possibly generic or incorrect -> Option AQuick Check:
Empty retrieval leads to generic answer [OK]
- Assuming empty retrieval causes error
- Thinking query is printed directly
- Expecting empty string output
Solution
Step 1: Identify cause of irrelevant answers
If answers are irrelevant, the source documents are likely unrelated to the question.Step 2: Check retriever role
The retriever finds documents; if it returns unrelated ones, the generator has poor context to answer.Final Answer:
Retriever is returning unrelated documents -> Option CQuick Check:
Bad retrieval causes irrelevant answers [OK]
- Blaming generator without checking retrieval
- Confusing overfitting with retrieval errors
- Ignoring data quality issues
Solution
Step 1: Understand RAG with dynamic data
RAG retrieves documents from an external source, so it can use new data without retraining the generator.Step 2: Compare with standard language models
Standard models need retraining to learn new info, but RAG updates answers by searching fresh documents.Final Answer:
It can access fresh news by retrieving documents without retraining -> Option DQuick Check:
RAG updates answers via retrieval [OK]
- Thinking RAG skips retrieval
- Assuming no training data needed
- Believing RAG limits answer length
