How to Evaluate and Tune RAG Pipelines for Accuracy and Latency
Build a RAG evaluation dataset, diagnose retrieval and answer failures, and tune accuracy, latency and cost around your customers' needs.
On this page 14 sections
- 01Define success with the customer first
- 02Evaluate the pipeline in layers
- 03Build an evaluation dataset that resembles real usage
- 04Measure retrieval quality before judging the answer
- 05Measure answer quality and abstention separately
- 06Use LLM judges carefully
- 07Measure latency as the customer experiences it
- 08Diagnose failures before changing settings
- 09Tune the largest quality bottleneck first
- 10Choose configurations for different customer needs
- 11A worked accuracy-versus-latency experiment
- 12Run experiments reproducibly
- 13Set release gates and monitor production
- 14A practical tuning sequence
A RAG pipeline is useful when it finds the right evidence, writes an answer supported by that evidence, and responds within the time the customer can accept. A fluent answer is not proof that any of those things happened.
The practical goal is the highest useful answer quality within your customer's latency, cost and risk constraints. A customer-support assistant, an internal knowledge tool and a research assistant should not automatically share the same configuration.
This guide walks through a repeatable process: define success with the customer, build an evaluation set, measure each stage, diagnose failures, run controlled experiments, and release the configuration that meets the agreed requirements. The numerical targets and experiment results below are illustrative, not measurements from a client project or universal benchmarks.
If embeddings, indexes and hybrid retrieval are new to you, start with the vector database guide.
Define success with the customer first
Ask what users are trying to accomplish and what happens when the system is wrong. “Maximum accuracy” is too vague to guide engineering decisions.
For a support assistant, a useful answer might resolve a question without an unnecessary handoff. For an analyst, it might identify every relevant exception and provide verifiable citations. For a search box, the best result may be a document link with no generated answer at all.
Agree on these requirements before selecting models or increasing retrieval depth:
| Requirement | Question to settle |
|---|---|
| Successful outcome | What must the user be able to do after receiving the answer? |
| Allowed evidence | Which sources, versions and customer records can the system use? |
| Error severity | Which mistakes are inconvenient, and which must block a release? |
| Waiting time | How long can users wait for the first useful content and the complete response? |
| Unsupported questions | Should the system clarify, abstain, open a ticket or escalate? |
| Workload | What traffic, concurrency, languages and document types must it support? |
| Cost | What is the acceptable cost per resolved task, including retries and escalation? |
Write a short acceptance contract. For example, an illustrative support pilot might require at least 90% acceptable responses on its agreed test set, p95 complete-response latency of at most four seconds at the specified load, and no observed cross-tenant disclosures. It should separately cap the rate of unsupported answers on unanswerable questions.
Those numbers are negotiation examples. Small test sets cannot establish very low failure rates, and zero observed failures does not prove zero production risk. Critical failures should be individual release blockers rather than errors averaged into an overall score.
Evaluate the pipeline in layers
RAG usually has several opportunities to fail:
Source → parsing → chunking → indexing
↓
Question → retrieval → reranking → context assembly → generation
↓ ↓ ↓ ↓
evidence ordering coverage answer quality
Across the whole request: permissions, freshness, latency and costSeparate evaluation into three layers:
- Data and retrieval: Is the required information present, correctly parsed, accessible and retrieved?
- Answer generation: Does the answer use that information correctly, completely and with valid citations?
- Product behavior: Does the system meet response-time expectations, handle missing evidence and help users finish their task?
This distinction is practical. A larger generator cannot reliably repair missing evidence. A better retriever cannot fix a generator that ignores an exception already present in its context. LangSmith's RAG evaluation tutorial similarly separates retrieval relevance, answer relevance, correctness and groundedness.
Build an evaluation dataset that resembles real usage
Start with real customer questions from an approved sample of support tickets, search logs or subject-matter interviews. Remove unnecessary personal data and restrict evaluation traces to the people authorized to inspect them.
A few hundred carefully reviewed cases can provide a useful development baseline, but the required sample size depends on the number of important customer segments and the failure rate you need to detect. A small pilot set is not evidence of rare-error safety.
Include a deliberate mix:
| Query category | Example | What it tests |
|---|---|---|
| Direct lookup | What is the return window for this product? | Basic retrieval and factual accuracy |
| Paraphrase | Can I send this back after trying it? | Semantic matching |
| Exact identifier | What does error AUTH-204 mean? | Lexical precision |
| Multiple sources | How do the standard and enterprise policies differ? | Evidence coverage and synthesis |
| Tables and numbers | What is the limit for the annual plan? | Parsing, units and row selection |
| Follow-up | Does that apply to contractors too? | Conversation context |
| Ambiguous question | Can I cancel it? | Clarification behavior |
| No supporting answer | Do you offer a feature absent from the documentation? | Appropriate abstention |
| Outdated or conflicting sources | Which policy applies after the renewal date? | Version and effective-date handling |
| Tenant or permission boundary | Ask for another customer's agreement | Access enforcement |
| Language variation | Ask in a supported language using local terminology | Language-specific quality |
Synthetic questions can expand coverage, but have people validate them. Questions generated directly from a chunk often repeat its wording and make retrieval look easier than production. Include difficult examples created independently of the retriever's output.
Store evidence and expectations, not only an answer string
An evaluation record can look like this. The policy and identifiers are fictional:
{
"id": "returns-017",
"question": "Can I return an opened headset after 20 days?",
"tenant_id": "demo-shop",
"language": "en",
"as_of": "2026-10-31",
"answerable": true,
"reference_claims": [
"The return window is 30 days",
"Opened headsets are excluded unless defective"
],
"evidence": [
{"document_id": "returns-policy", "version": 3, "section": "window"},
{"document_id": "returns-policy", "version": 3, "section": "exceptions"}
],
"expected_behavior": "Explain the exclusion and ask whether the item is defective",
"slices": ["support", "exceptions", "multiple-evidence"]
}Reference claims allow different correct wording. Evidence locations allow you to diagnose retrieval independently of generation. Store source spans or stable sections as well as chunk IDs: changing the chunking strategy should not invalidate the underlying evidence labels.
Separate development from final evaluation
Use a development set to tune prompts, thresholds and retrieval settings. Keep a held-out test set for release decisions. Group near-duplicate questions and related conversation turns so they do not leak across the split; use document-family or time-based splits where they match the deployment challenge.
If you repeatedly inspect test failures and tune against them, that set has become development data. Refresh the held-out set. Record the corpus snapshot, model versions, prompt version, configuration and evaluation rubric so results remain interpretable.
Measure retrieval quality before judging the answer
Retrieval metrics tell you whether the generator received useful evidence.
| Metric | What it tells you | Limitation |
|---|---|---|
| Evidence Recall@k | Fraction of labeled relevant evidence retrieved in the first k results | Requires sufficiently complete relevance labels |
| Precision@k | Fraction of the first k results labeled relevant | Depends on the relevance definition and label coverage |
| Hit rate@k | Fraction of questions with at least one relevant result | One result may not cover all required facts |
| MRR | How early the first relevant result appears, averaged across questions | Does not reward retrieving every required source |
| nDCG@k | Ranking quality when results have graded relevance | Requires graded judgments |
| Evidence coverage | Whether the final context contains the facts needed to answer | Must account for multiple sources and context truncation |
For a question with four labeled relevant evidence units, retrieving three gives evidence Recall@k of 75%. If the first relevant result is at rank two, its reciprocal rank is 0.5. Define how unanswered and unlabeled cases are handled before computing averages. Pinecone's retrieval evaluation guide explains recall, MRR and nDCG in more detail.
Human-relevance recall and ANN recall are different. ANN recall measures agreement with exact nearest-neighbor search. A vector index can reproduce exact neighbors perfectly while the embedding model retrieves the wrong content for the human question.
Measure evidence coverage at three points: initial candidates, reranked results, and the actual context sent to the model. This catches an important failure: retrieval found the evidence, but deduplication, ordering or the token budget removed it.
When comparing different chunk sizes, evaluate stable evidence spans or document sections as well as chunk-level metrics. Otherwise, splitting one relevant paragraph into more chunks can change the score without improving the information delivered.
Measure answer quality and abstention separately
Do not collapse correctness, groundedness and usefulness into one vague “accuracy” score.
| Dimension | Evaluation question |
|---|---|
| Correctness | Are the material claims correct against the approved reference and applicable source version? |
| Groundedness | Are the answer's claims supported by the retrieved context? |
| Completeness | Does it include the required conditions, exceptions and steps? |
| Relevance | Does it answer the actual question without unnecessary material? |
| Citation support | Does each citation actually support the associated claim? |
| Citation coverage | Are the claims requiring evidence accompanied by usable citations? |
| Behavior | Did it answer, clarify, abstain or escalate as expected? |
An answer can faithfully repeat an outdated policy and still be incorrect for today's question. It can also state the right fact from model memory without support from the retrieved sources. Both deserve different diagnoses.
Ragas provides metrics for aspects such as context recall, response relevancy and faithfulness. Its faithfulness metric assesses whether response claims are supported by the context. Framework metric names and implementations differ; do not assume every “context precision” score is identical to simple binary Precision@k.
Use a concrete review rubric
For the fictional returns question, an answer that says only “Yes, within 30 days” fails even though it mentions a true policy detail. It misses the exception that controls the outcome.
A useful rubric is:
- Pass: Material claims are correct, the required exception is present, citations support the answer, and the requested action is appropriate.
- Partial: No material false claim, but a required detail or usable citation is missing.
- Fail: A material claim is wrong, the key exception is omitted, or the response takes the wrong action.
- Critical fail: The response exposes unauthorized information or violates another explicitly defined release-blocking rule.
Score dimensions separately, then derive the pass/fail decision using the customer's rubric. Have two reviewers score a sample and resolve disagreements before trusting the labels.
Prevent abstention from inflating accuracy
A pipeline that refuses every question can avoid many wrong answers while being useless. Report at least:
- Answer coverage: The fraction of answerable cases it attempts to answer substantively.
- Correctness among answered cases: How many attempted answers are correct.
- False-answer rate on unanswerable cases: How often it provides a substantive answer when authorized evidence is insufficient.
- Appropriate-action rate: How often its answer, clarification or escalation matches the expected behavior.
Tune evidence gates on development data and evaluate the quality-versus-coverage trade-off. Similarity scores are not calibrated probabilities, and a threshold that works for one embedding model or language may not transfer to another.
Use LLM judges carefully
An LLM judge can help review many answers, but its score is an estimate. It can prefer fluent prose, overlook missing exceptions, follow instructions embedded in retrieved text, or disagree with a subject-matter expert.
Give the judge a narrow rubric and require evidence for its decision. Separate the reference answer, retrieved context and candidate answer explicitly. Treat candidate text as data, not instructions. For groundedness, ask about support in the supplied context; for correctness, provide the approved reference as well.
Calibrate the judge against human-reviewed cases across languages, document types and failure severities. Inspect both false passes and false failures. Version the judge model and rubric, blind it to the pipeline's identity, and randomize ordering in pairwise comparisons.
Use deterministic checks for exact requirements such as tenant IDs, source versions, required numeric values and citation identifiers. Use human review for material disagreements and critical release cases. Keep evaluation calls outside the user-facing latency measurement unless the product itself runs those checks synchronously.
Measure latency as the customer experiences it
Record both time to first useful content and time to complete response. A spinner or “Let me check” is not useful answer content. Streaming can improve perceived responsiveness without reducing the time needed to finish the answer.
Instrument the stages:
queue → routing/rewrite → query embedding → retrieval
→ reranking → context assembly → generation → deliveryFor sequential work, elapsed times contribute to the request total. For parallel lexical and vector retrieval, the critical path is approximately the slower branch plus coordination overhead. Do not add stage p95 values to estimate end-to-end p95: percentiles are not additive. Measure complete-request latency directly.
| Measurement | Why it matters |
|---|---|
| p50 | Typical experience |
| p95 and p99 | Slow-tail experience; require enough observations to estimate reliably |
| First useful content | How quickly the user receives something actionable |
| Complete response | When the whole answer, including citations, is available |
| Timeout and error rate | Requests that a successful-only latency report would hide |
| Queue time | Capacity problems that look like slow inference |
| Input/output tokens | Context and answer length often explain inference cost and delay |
Run load tests at agreed request rates and concurrency. Test warm and cold caches, short and long questions, large tenants, long outputs, retries and dependency failures. Report timeouts separately rather than silently dropping them from the latency distribution.
Control output verbosity when comparing configurations. A model that produces a much shorter but incomplete answer can look faster for the wrong reason.
Diagnose failures before changing settings
Use traces and source inspection to identify the earliest failing stage.
| Observation | Likely problem | First experiment |
|---|---|---|
| Required fact is absent from parsed text | Extraction or source coverage | Repair parsing or obtain the missing source |
| Fact is indexed but absent from candidates | Retrieval, filtering or query mismatch | Check filters, then test hybrid search or larger candidate depth |
| Exact neighbor search works but ANN misses evidence | Approximate-index settings | Increase search effort and measure the latency cost |
| Candidates include evidence but reranking removes it | Reranker fit or candidate handling | Evaluate reranker on this language/domain; preserve source diversity |
| Reranked evidence disappears from final context | Packing, deduplication or token budget | Trace context assembly and retain required spans |
| Correct evidence is present but answer is wrong | Prompt, generator or task complexity | Test generation against fixed evidence |
| Answer ignores a second source | Incomplete synthesis | Require coverage of the comparison and test context ordering |
| Answers are correct but slow | Excess serial work, inference or queuing | Profile the critical path before changing the database |
| One customer performs much worse | Tenant-specific corpus or traffic | Evaluate that segment and its filters separately |
An especially useful diagnostic is an oracle-context experiment: give the generator human-selected evidence directly. If it still fails, focus on answer generation or the task definition. If it succeeds, inspect retrieval and context assembly. This is a diagnostic upper-bound experiment, not a production score.
Tune the largest quality bottleneck first
Change one major variable at a time initially, then test combinations where interactions are likely. Keep the corpus, evaluation cases and workload fixed for each comparison.
| Lever | Potential quality benefit | Latency or cost trade-off |
|---|---|---|
| Better parsing and structure-aware chunks | Recover missing facts and preserve exceptions | Mostly ingestion cost; may change index size |
| Different embedding model | Improve domain or language matching | Re-embedding expense and query-encoding cost |
| Hybrid lexical/vector search | Preserve identifiers alongside semantic matches | Extra retrieval and fusion work |
| Larger candidate pool | Recover evidence missed at shallow depth | More retrieval and reranking work |
| Cross-encoder reranking | Improve ordering of query-passage pairs | Additional inference per candidate batch |
| Smaller, better context | Remove distraction while preserving evidence | Often reduces generation time; can lose needed evidence |
| Query rewriting or decomposition | Resolve follow-ups or multi-part questions | Extra calls and risk of changing intent |
| More capable generator | Improve synthesis and instruction following | Potentially greater inference cost and delay |
| Answer-length limits | Make routine answers concise | Can omit required qualifications if too aggressive |
Separate candidate count from final context size
Retrieving 40 candidates does not mean sending 40 chunks to the generator. You might retrieve 40, rerank them, and retain six complementary passages within a token budget. Those values are experiment settings, not recommended defaults.
Try a small development sweep, such as candidate depths of 10, 20 and 40, then compare evidence coverage and latency. Test final context sizes independently. Multi-source questions may need more diverse evidence than direct lookups.
Cross-encoders jointly score the query and passage, which makes them useful for reranking a smaller candidate set after initial retrieval. They cannot recover evidence that never entered the candidate pool. Sentence Transformers documents this retrieve-and-rerank pattern.
Reduce latency without blindly removing useful work
First remove duplicate retrieval calls, unnecessary query rewrites and irrelevant context. Run independent retrieval branches concurrently, keep connections reusable, and investigate queueing before selecting a smaller model.
Cache only where correctness survives reuse. Retrieval and answer cache keys need the relevant tenant, authorization scope, corpus version and configuration; invalidate results when permissions or documents change. A semantic cache can confuse similar questions with different exceptions, so evaluate it as a separate retrieval system.
Use batching to improve throughput where it helps, but measure the waiting time it adds to individual requests. Benchmark model and infrastructure choices under the actual concurrency profile.
Choose configurations for different customer needs
The same customer may need a quick path for routine lookups and a deeper path for difficult research. These are starting architectures to evaluate, not promises of a particular latency.
| Customer or workflow | Main priority | Starting configuration | What to watch |
|---|---|---|---|
| Public FAQ or routine support | Quick, correct resolution | One retrieval pass, concise generation, selective reranking | Unsupported promises, wrong exceptions, unnecessary handoffs |
| Internal knowledge assistant | Reliable citations across varied documents | Hybrid retrieval, reranking, version filters, balanced context | Permissions, stale policies, language differences |
| Analyst or research workflow | Complete evidence and source comparison | Decomposition when needed, wider retrieval, stronger synthesis | Missing sources, conflicting claims, excessive serial loops |
| Policy or contract review | Traceability and cautious handling of ambiguity | Explicit evidence requirements, abstention and expert review | Material omissions and unsupported interpretations |
| Search/autocomplete | Fast discovery | Return ranked snippets or documents without generation | Ranking relevance and tail latency |
| Cost-constrained high-volume service | Sustainable cost at a quality floor | Efficient model, short answers, carefully scoped caches | Quality loss in rare or difficult cases |
Route based on observable task requirements and customer policy. For example, an explicit comparison question may use the deeper path, while a direct FAQ lookup uses the quick path. Test the router's mistakes: misrouting a difficult question can erase the savings from all other tuning.
Bound extra work with deadlines, retrieval-round limits and token budgets. When the deadline is reached, provide an appropriate partial result, clarification or escalation. Do not quietly trade away access rules or invent an answer to meet the latency target.
Evaluate each route separately and then evaluate their combined production mix. Routing overhead and the proportion of requests escalated to the deeper path both affect the final p95.
A worked accuracy-versus-latency experiment
Suppose a support customer sets a development target of at least 90% acceptable responses and p95 complete-response latency of at most four seconds. The following numbers are invented to demonstrate selection, not observed benchmarks. Assume the same 500 cases, corpus, output requirements and load for each configuration.
| Configuration | Acceptable responses | p95 complete latency | Relative cost per request |
|---|---|---|---|
| A: Dense retrieval, eight context chunks | 410/500 = 82% | 2.0 s | 1.0× |
| B: Hybrid retrieval, 30 candidates reranked to six | 455/500 = 91% | 3.2 s | 1.3× |
| C: B plus deeper retrieval and stronger generation | 465/500 = 93% | 6.8 s | 2.4× |
| D: Larger unranked context | 445/500 = 89% | 4.4 s | 1.8× |
B is the candidate to validate for this support workflow. A misses the quality floor. C improves the point estimate but exceeds the latency budget. D is slower and less accurate than B, while also costing more.
For a research customer willing to wait longer, C could deserve further investigation. The extra ten passing cases may or may not justify its cost; inspect which cases improved and whether the difference is stable across repeated runs.
This is a Pareto trade-off: a configuration is dominated when another is no worse on the chosen objectives and better on at least one. Do not assume more latency always buys quality. Better parsing or context selection can improve both.
These aggregate numbers alone are insufficient for release. Compare paired per-question outcomes, estimate uncertainty, and inspect customer segments. A 91% overall result can hide poor performance on one language or tenant. Use a paired bootstrap over independent question groups, or another appropriate statistical method, rather than treating repeated versions of the same question as independent evidence.
Run experiments reproducibly
Keep a small experiment manifest alongside every result:
{
"experiment_id": "hybrid-rerank-dev-03",
"dataset_version": "support-dev-v2",
"corpus_version": "docs-2026-10-31",
"pipeline_version": "rag-v3",
"candidate_k": 30,
"context_k": 6,
"context_token_budget": 4000,
"query_rewrite": false,
"cache_mode": "disabled",
"target_concurrency": 10,
"repeats_per_case": 3
}These settings are illustrative. Also record the actual embedding, reranker, generator and judge versions, prompts, hardware or provider deployment, timeout behavior and token usage. Record per-request traces, not only summary scores.
Run the same cases against the baseline and candidate. Randomize or interleave execution to reduce time-of-day provider effects. Use repeated runs to understand model variability, but do not pretend repeats increase the number of distinct customer questions.
Keep warm-cache, cold-cache and cache-disabled experiments separate. Use a dedicated load test for latency: a sequential evaluation loop and an LLM judge running afterward do not reproduce production traffic.
A spreadsheet or JSONL report is enough to start. Ragas can supply metric implementations, and LangSmith supports dataset-based experiments and production evaluation workflows. Tool choice does not replace a clear rubric or reliable evidence labels. See LangSmith evaluation types for the distinction between offline and online evaluation.
Set release gates and monitor production
Choose release criteria before inspecting the final held-out results. A useful release report includes:
- Overall quality and the denominator behind each rate.
- Results for important customer, language, document and question segments.
- Answer coverage and false-answer rate on unanswerable cases.
- Critical-case outcomes, including tenant boundaries and citation validity.
- First-useful-content and complete-response latency at the agreed workload.
- Timeout, retry and error rates, plus cost per request and resolved task.
- The changes from the previous version and a rollback configuration.
After offline approval, use shadow evaluation or a limited rollout where appropriate. Shadow traffic must preserve the same access restrictions and data-handling rules. Monitor paired failures and operational load before expanding exposure.
Online metrics should include task completion, repeated questions, corrections and escalations, with sampled human review. A missing thumbs-down is not proof of correctness, and lower escalation rates are not automatically good if the assistant is confidently giving wrong answers.
Promote reviewed production failures into regression cases. Re-evaluate when documents, embeddings, chunking, filters, prompts, models or customer usage change. Roll back on critical failures or sustained quality and latency regressions according to the agreed release policy.
A practical tuning sequence
- Agree on customer outcomes, quality floors, latency budgets and unacceptable failures.
- Build reviewed development and held-out datasets with source evidence and segment labels.
- Instrument retrieval, context assembly, generation and complete-request timing.
- Establish a simple baseline and inspect its failures.
- Fix missing or malformed source content before tuning models.
- Improve retrieval coverage, then ranking and context selection.
- Tune generation using fixed evidence so retrieval changes do not hide the cause.
- Remove unnecessary serial work and test under realistic load.
- Select a configuration that meets the customer's constraints, with per-segment checks.
- Validate on held-out cases, roll out gradually and keep collecting reviewed failures.
If you are choosing the implementation framework, read LangChain vs LlamaIndex for RAG. For budgeting, see RAG development costs.
I build custom RAG systems with retrieval evaluation, source citations and access rules, and tune them around the actual customer workload. Tell me about your documents, users and response-time requirements.
