How to Improve RAG Retrieval
A practical guide to improving retrieval quality in RAG systems using better chunking, embeddings, hybrid search, metadata, reranking, query processing, evaluation, and performance optimization.
Retrieval quality is one of the most important factors in a retrieval-augmented generation (RAG) system. A language model can only use the information that reaches its context, so even a powerful model can produce an incomplete or incorrect answer when the retrieval layer returns the wrong documents.
Improving RAG retrieval is not usually about changing one setting. Retrieval quality depends on the entire pipeline, including source documents, document cleaning, chunking, embeddings, indexing, query processing, keyword search, vector search, metadata filtering, candidate selection, reranking, and context construction.
The goal is to retrieve the smallest set of documents that contains the information necessary to answer the user's question. This guide explains practical ways to improve that process and how to determine which part of the pipeline is actually causing poor results.
What Does Good RAG Retrieval Mean?
Good RAG retrieval means that the system consistently places useful, relevant, and sufficiently complete information among the highest-ranked results. The retrieved context should directly support the user's question rather than simply being related to the same general topic.
There are two important dimensions to retrieval quality: recall and precision. Recall describes how often relevant information is successfully retrieved, while precision describes how much of the retrieved information is actually relevant.
| Problem | What It Means | Typical Fix |
|---|---|---|
| Low recall | Relevant information is missing from candidates | Improve chunking, embeddings, query processing, or retrieval depth |
| Low precision | Too many irrelevant results are retrieved | Improve ranking, filtering, or reranking |
| Wrong version | Results come from an incorrect product or version | Use metadata filters |
| Incomplete context | A relevant chunk lacks necessary surrounding information | Improve chunking or context expansion |
| Exact terms missed | Identifiers or exact phrases are not retrieved | Add lexical or hybrid search |
Understand the RAG Retrieval Pipeline
Before optimizing retrieval, understand the complete path from source documents to the final LLM context. A typical pipeline looks like this:
- Collect source documents.
- Clean and normalize the content.
- Split documents into chunks.
- Attach useful metadata.
- Generate embeddings.
- Store chunks and vectors in an index.
- Process the user's query.
- Retrieve candidate documents.
- Apply metadata and access filters.
- Optionally combine keyword and semantic results.
- Rerank candidates.
- Select the final context.
- Send the context to the LLM.
A useful optimization process starts by determining where relevant information disappears or becomes poorly ranked. Changing the embedding model will not fix a query filter that excludes the correct documents, and reranking will not help if the correct document was never retrieved.
1. Improve the Source Documents
Retrieval quality starts with the information being indexed. Poorly structured, duplicated, outdated, or noisy documents make retrieval harder regardless of which search technology you use.
Remove unnecessary navigation elements, duplicated headers, cookie notices, irrelevant boilerplate, tracking information, and other content that does not contribute to the meaning of the document.
Preserve important structural information such as titles, headings, lists, tables, code blocks, product names, version numbers, and section relationships. This information can improve both retrieval and the quality of the final context.
2. Remove Duplicate Content
Duplicate or near-duplicate documents can distort retrieval results. If the same information appears in many indexed chunks, a query may return several copies instead of providing diverse evidence.
Deduplication can be performed at the document level, chunk level, or both. Exact duplicates can often be detected with hashes, while near-duplicate content may require similarity-based techniques.
3. Improve Chunking
Chunking determines how documents are divided before they are indexed. It has a direct effect on what the retrieval system can find and how much context each result contains.
Chunks that are too small may lose important context. A sentence containing an API name might be retrieved without the explanation that describes how the API should be used. Chunks that are too large can contain many unrelated concepts and become less precise during retrieval.
Structure-aware chunking is often useful for technical documentation. Instead of splitting text at arbitrary character boundaries, chunks can follow headings, paragraphs, sections, lists, and code examples.
There is no universally optimal chunk size. The correct size depends on document structure, query patterns, embedding model, and the amount of context needed to answer typical questions.
4. Preserve Context During Chunking
A chunk should ideally contain enough information to remain understandable when retrieved independently. If a chunk begins with a sentence such as "This option is enabled by default" without explaining which option is being discussed, its embedding may not represent the actual meaning clearly.
One solution is to preserve document titles and heading paths as metadata or prepend relevant structural context to the chunk before generating its embedding.
Another technique is overlapping chunks, where adjacent chunks share some content. Overlap can reduce the chance that important information is split across chunk boundaries, although excessive overlap increases index size and duplication.
5. Choose a Suitable Embedding Model
Embeddings determine how semantic relationships are represented in the vector index. A weak or poorly matched embedding model can make relevant documents appear farther apart in vector space.
When selecting an embedding model, consider the languages in your data, the type of content, query style, supported input length, vector dimensions, latency, cost, and retrieval benchmark performance.
Do not choose an embedding model only because it is popular. Test candidate models against queries that represent the actual application.
6. Match the Embedding Model to Your Data
Different datasets have different retrieval requirements. General-purpose embeddings may work well for ordinary prose, while technical documentation can benefit from models that perform well on technical terminology and question-answer retrieval.
Multilingual applications also need to consider whether queries and documents can be represented consistently across languages. If users ask questions in one language while documents are written in another, cross-lingual retrieval capability becomes important.
7. Add Keyword Search
Vector search is not always sufficient. Exact strings such as API names, error codes, model identifiers, version numbers, file names, and configuration properties can be difficult to retrieve reliably using semantic similarity alone.
Adding keyword retrieval gives the system another relevance signal. A lexical engine can recognize that a document contains an exact term even if the embedding representation does not give that term enough importance.
8. Use Hybrid Search
Hybrid search combines keyword retrieval with semantic vector retrieval. This allows the system to capture both exact lexical matches and conceptual similarity.
For example, a query such as "PostgreSQL pgvector HNSW index" contains highly specific technical terms. Keyword search can strongly favor documents containing those terms, while semantic search can find related explanations even when the wording differs.
The two result sets can be combined using score normalization, weighted scoring, Reciprocal Rank Fusion, or another result-fusion strategy.
9. Improve Query Processing
The original user query is not always the best query for retrieval. Users may use vague language, omit important terms, include conversational context, or ask several questions at once.
Query processing can include normalization, spelling correction, query rewriting, expansion, language detection, intent classification, and extraction of structured filters.
For example, a user might ask "Why does my React app complain about hydration after I added localStorage?" A retrieval system may benefit from identifying concepts such as React hydration, server rendering, browser-only APIs, and localStorage.
10. Use Query Rewriting Carefully
An LLM can sometimes rewrite a user's question into a more retrieval-friendly query. This can improve recall when the original query is conversational or ambiguous.
However, query rewriting can also remove important details or introduce assumptions. The original query should therefore not be discarded blindly. In some systems, the original and rewritten queries are both used for retrieval.
11. Use Metadata Filters
Metadata filters restrict retrieval to documents that satisfy known conditions. Useful metadata includes product, version, language, category, document type, publication date, tenant, permissions, and source.
For example, if a user asks about a specific version of a library, filtering results to that version can prevent semantically similar documentation from older versions from competing for the top ranking.
Metadata filtering can improve both relevance and performance because the search engine has fewer eligible documents to consider.
12. Improve Retrieval Depth
Retrieving too few candidates can cause low recall. If the relevant chunk ranks slightly below the initial top-K cutoff, a later reranker will never see it.
Increasing the candidate count can improve recall, but it also increases downstream processing. The goal is to retrieve enough candidates to capture relevant information without creating unnecessary latency and reranking cost.
The appropriate candidate count should be measured using an evaluation dataset rather than selected as a universal number.
13. Add Reranking
Reranking is one of the most effective ways to improve precision after initial retrieval. A reranker receives the query and retrieved candidates and produces a new relevance ranking.
This works well because initial retrieval can focus on recall while the reranker focuses on precision. A vector or hybrid search engine can quickly retrieve a broad candidate set, after which a more computationally expensive model evaluates only those candidates.
Reranking is especially useful when the correct documents are present in the candidate set but are consistently ranked below less relevant results.
14. Understand the Limits of Reranking
Reranking cannot recover a document that initial retrieval failed to retrieve. If the correct chunk is not among the candidates, even a highly accurate reranker cannot select it.
This means that retrieval optimization should first ensure adequate recall and only then focus heavily on ranking precision.
15. Use Multiple Retrieval Strategies
Some questions are difficult to answer with one retrieval strategy. A complex RAG system can use several retrieval approaches and merge their candidate sets.
- Keyword retrieval for exact terminology.
- Semantic retrieval for conceptual similarity.
- Metadata filtering for structured constraints.
- Document-level retrieval for broad context.
- Chunk-level retrieval for precise passages.
- Specialized retrieval for structured data when necessary.
Combining these methods can improve recall, but the additional complexity should be justified by measured improvements.
16. Use Parent-Child Retrieval
Parent-child retrieval separates the unit used for searching from the unit used for final context. Small child chunks can provide precise retrieval, while a larger parent section can provide the surrounding context required for the answer.
For example, a long documentation section can be divided into small searchable chunks. When one chunk matches a query, the application can return the associated section or parent document instead of only the small chunk.
This approach can be useful when precise retrieval and contextual completeness are both important.
17. Use Contextual Metadata
Adding contextual information to chunks can make them easier to retrieve and interpret. Useful fields include document title, heading path, product name, version, URL, category, and source.
For example, instead of indexing a chunk containing only "This option requires an API key", the indexed representation can preserve its relationship to the surrounding documentation section and product.
18. Improve Document Titles and Headings
Titles and headings often contain highly valuable retrieval signals. A chunk titled "Configuring API Authentication" is easier to identify than an isolated paragraph that happens to discuss authentication.
When processing documents, preserve heading hierarchies and associate them with chunks. This information can be included in metadata, embeddings, or the final context.
19. Handle Tables and Structured Content Carefully
Tables can contain important information that is difficult to retrieve if they are converted into poorly structured text. Preserve column names and relationships between values whenever possible.
For structured data, a specialized retrieval method may sometimes be more appropriate than embedding the entire table as ordinary prose. The correct approach depends on the questions users need to ask.
20. Preserve Code Examples
Developer documentation often contains code that should remain intact during ingestion. Breaking a code example into unrelated chunks can make retrieval less useful and can remove important context from the final answer.
Store programming language and other useful metadata with code blocks. When appropriate, keep code examples associated with the explanatory text that describes them.
21. Use Deduplication During Retrieval
Even after source-level deduplication, multiple retrieved chunks may contain overlapping information. Returning several nearly identical chunks wastes context space and can crowd out more useful evidence.
Candidate deduplication can be performed before or after reranking. The exact strategy depends on whether duplicate chunks originate from the same document, different documents, or overlapping versions of the same information.
22. Diversify the Final Context
The highest-scoring documents are not always the best complete context when they all cover the same small aspect of a question. A context-selection stage can balance relevance with diversity.
For multi-part questions, it may be better to include several complementary chunks rather than many variations of the same passage.
23. Separate Retrieval from Context Selection
Retrieval and final context selection do not need to use the same K value. The retrieval stage should often prioritize recall, while context selection should prioritize the information density and usefulness of the final context.
For example, an application might retrieve a relatively broad candidate set, rerank it, remove duplicates, and then select a smaller set of chunks for the LLM.
24. Use a Relevance Threshold
A relevance threshold can prevent clearly unrelated results from being passed to the model. Instead of always returning exactly K chunks, the system can discard candidates whose relevance score falls below an empirically selected threshold.
Thresholds should be evaluated carefully. A threshold that is too strict can reduce recall, while one that is too low can fill the context with irrelevant information.
25. Build a Retrieval Evaluation Dataset
One of the most important improvements is creating a dataset of realistic queries and expected relevant documents. Without an evaluation dataset, retrieval optimization often becomes guesswork.
Each test case can contain a user query and one or more documents or chunks considered relevant. You can then compare different chunking strategies, embedding models, retrieval methods, and ranking configurations against the same queries.
26. Measure Recall@K
Recall@K measures whether relevant information appears within the top K retrieved results. It is particularly useful for evaluating the candidate-generation stage of a RAG system.
If Recall@50 is high but Recall@5 is low, the system may be finding the correct information but ranking it too low. This is a strong indication that reranking or ranking improvements may be useful.
27. Measure Precision@K
Precision@K measures how much of the top K results are relevant. It is useful for determining whether the final ranking contains too much irrelevant content.
A system can have good recall but poor precision. In that case, improving candidate retrieval alone may not solve the problem; ranking, filtering, reranking, or context selection may be more important.
28. Evaluate the Final Answer Too
Retrieval metrics are necessary but not sufficient. A document can be marked as relevant while still failing to provide enough information for the LLM to answer the question.
Evaluate whether the retrieved context actually supports the generated answer. Useful dimensions include factual correctness, completeness, citation quality, groundedness, and whether the answer uses information from the retrieved documents appropriately.
29. Diagnose Retrieval Failures
When a RAG answer is wrong, inspect the retrieval results before immediately changing the prompt or language model. Determine whether the correct information was retrieved and where it appeared in the ranking.
| Observation | Likely Problem |
|---|---|
| Correct document absent | Low recall or indexing problem |
| Correct document ranked low | Ranking or reranking problem |
| Correct document present but incomplete | Chunking or context problem |
| Wrong version retrieved | Metadata filtering problem |
| Exact term missed | Lexical retrieval problem |
| Many duplicate results | Deduplication or source-quality problem |
30. Optimize for the Actual Query Distribution
The best retrieval configuration depends on what users actually search for. A documentation assistant may receive highly technical questions, while a customer support application may receive short descriptions of problems.
Analyze real queries and group them by type. Look for exact-match queries, conceptual questions, multi-part questions, navigational searches, version-specific questions, and ambiguous queries.
Optimization should then target the failure modes that occur most frequently instead of optimizing for an abstract benchmark that does not represent real usage.
31. Optimize Vector Search Parameters
Approximate nearest-neighbor indexes use configuration parameters that trade retrieval quality against speed and memory usage. Increasing search effort can improve recall but may increase latency.
The exact parameters depend on the vector index implementation. Benchmark them using your own dataset and evaluation queries rather than assuming that maximum search depth is always optimal.
32. Keep Embeddings and Documents in Sync
When source documents change, their indexed representations need to be updated. Stale chunks can cause the retrieval system to return information that no longer matches the source.
A robust ingestion pipeline should track document versions, update timestamps, embedding versions, and indexing status. When the embedding model changes, you may also need to regenerate embeddings consistently across the collection.
33. Handle Document Versions Explicitly
Versioned documentation is a common source of retrieval errors. Semantically similar chunks from different versions can compete for the same query.
Store version information as metadata and apply filters when the user's question clearly refers to a specific version. When no version is specified, the application should have an explicit policy for deciding which version is preferred.
34. Improve Multilingual Retrieval
If users and documents use multiple languages, retrieval quality depends on how well the search system handles cross-language queries. Test queries in each supported language and include translated or multilingual examples in the evaluation dataset.
Keyword retrieval can require language-specific analysis, while semantic retrieval depends on the capabilities of the embedding model. A hybrid approach can be useful when exact technical terms remain unchanged across languages.
35. Optimize RAG Retrieval Latency
Retrieval quality should not be optimized independently of performance. Users generally expect an AI application to respond quickly, so every additional retrieval stage should have a measurable purpose.
- Run independent retrieval methods in parallel when possible.
- Use efficient vector indexes.
- Apply metadata filters early.
- Limit the number of candidates passed to expensive rerankers.
- Avoid unnecessarily large chunks.
- Cache repeated query embeddings where appropriate.
- Cache suitable repeated retrieval operations.
- Measure the complete end-to-end retrieval latency.
36. Optimize Context Size
More retrieved text does not automatically mean better answers. Excessive context can increase token usage, latency, and cost while adding irrelevant information.
After retrieval and reranking, select only the information that is necessary to answer the query. Context selection should consider relevance, diversity, completeness, and the available context budget.
37. Use Citations and Source Metadata
Preserving source information during retrieval makes the final RAG application easier to debug and more trustworthy. Store fields such as document title, URL, section, and source identifier alongside retrieved chunks.
The application can then provide citations or source references with generated answers. These references also make it easier to inspect whether the model actually used the correct documents.
38. Add Monitoring
Production retrieval systems can degrade over time as documents change, user behavior evolves, or indexes become stale. Monitoring helps detect these changes.
- Retrieval latency.
- Number of candidates retrieved.
- Reranking latency.
- Relevance-score distributions.
- Empty-result rates.
- User query patterns.
- Citation usage and source clicks.
- Human feedback on answer quality.
- Retrieval evaluation scores.
- Changes in document and embedding versions.
39. Avoid Optimizing Only the LLM Prompt
When a RAG system produces poor answers, it is tempting to modify the generation prompt immediately. Prompt improvements can help, but they cannot compensate for missing or irrelevant retrieval results.
Inspect the retrieved context first. If the context does not contain the answer, the retrieval pipeline needs improvement. If the correct information is present but the model ignores it, then prompt design or generation behavior may be the next area to investigate.
40. Use an Iterative Optimization Process
RAG retrieval should be optimized iteratively. Start with a simple baseline, measure it, identify the dominant failure mode, make one targeted change, and measure again.
- Create representative evaluation queries.
- Build a simple retrieval baseline.
- Measure recall and precision.
- Inspect failed queries manually.
- Identify the most common failure pattern.
- Change one retrieval component.
- Run the same evaluation again.
- Compare quality, latency, and cost.
- Keep the change only if it provides a meaningful improvement.
A Practical High-Quality RAG Retrieval Pipeline
A robust RAG retrieval pipeline can combine many of the techniques described above without making every query unnecessarily expensive.
Source Documents
β
Clean + Normalize
β
Structure-Aware Chunking
β
Metadata + Embeddings
β
Search Index
β
User Query
β
Query Processing
βββ Keyword Search
βββ Vector Search
β
Result Fusion
β
Metadata Filtering
β
Reranking
β
Deduplication + Selection
β
LLM Context
β
AnswerNot every application needs every stage. A small knowledge base may only require good chunking, embeddings, and vector search. A large enterprise system may benefit from hybrid retrieval, metadata filters, reranking, query rewriting, and detailed evaluation.
The Most Important RAG Retrieval Improvements
If you need to prioritize improvements, focus first on the parts that most directly affect whether the correct information reaches the candidate set.
- Clean and structure source documents.
- Use appropriate chunking.
- Preserve document and heading context.
- Choose an embedding model suited to the data.
- Add keyword retrieval when exact terms matter.
- Use hybrid search when lexical and semantic signals are both important.
- Apply metadata and authorization filters.
- Retrieve enough candidates to maintain good recall.
- Add reranking when candidates are relevant but poorly ordered.
- Deduplicate and select a focused final context.
- Build a representative retrieval evaluation dataset.
- Monitor quality, latency, and cost in production.
What Not to Do
- Do not assume a larger context always improves RAG.
- Do not change the embedding model without evaluating it.
- Do not use reranking to compensate for missing documents.
- Do not combine raw keyword and vector scores without considering their different scales.
- Do not ignore document versions.
- Do not index noisy or duplicated source content without a reason.
- Do not rely only on manual testing.
- Do not optimize retrieval while ignoring latency and cost.
- Do not send unauthorized documents to the LLM.
- Do not change multiple retrieval components at once if you need to understand which change helped.
Frequently Asked Questions
What is the best way to improve RAG retrieval?
Start by improving document quality and chunking, then choose an appropriate embedding model and retrieval strategy. Hybrid search, metadata filtering, reranking, and query processing can provide additional improvements when evaluation shows they are needed.
Does better retrieval always require a better embedding model?
No. Poor chunking, duplicate content, missing metadata, insufficient retrieval depth, and weak query processing can all cause retrieval failures. Improving those components may provide a larger benefit than changing the embedding model.
Should RAG use keyword and vector search together?
Hybrid search is often useful when the dataset contains both conceptual information and exact terms such as API names, error codes, identifiers, or version numbers. Simpler applications may work well with only one retrieval method.
How does reranking improve RAG?
Reranking takes an initial candidate set and reorders it using a more detailed relevance model. It can improve precision when the correct documents are present but are ranked below less relevant results.
How many documents should RAG retrieve?
There is no universal number. The candidate count should be large enough to achieve good recall but small enough to maintain acceptable latency and reranking cost. The correct value should be determined through evaluation.
Can RAG retrieval be too good?
Retrieval can become counterproductive when the system sends excessive amounts of loosely relevant information to the LLM. A focused context containing the most useful evidence is generally preferable to a very large collection of marginally relevant chunks.
Conclusion
Improving RAG retrieval is primarily an engineering and evaluation problem rather than a matter of simply choosing a more powerful language model. The quality of source documents, chunking strategy, embeddings, indexing, query processing, retrieval methods, metadata, reranking, and context selection all influence the final result.
A strong RAG system usually starts with clean documents and well-designed chunks, uses an embedding model appropriate for the data, and retrieves enough candidates to achieve good recall. Keyword or hybrid search can improve exact-term retrieval, while metadata filtering can eliminate irrelevant or incorrect versions. Reranking can then improve precision when relevant candidates are already available.
The most important principle is to measure every change. Build a representative evaluation dataset, inspect retrieval failures, identify whether the problem is recall, ranking, chunking, filtering, or context selection, and optimize the specific stage responsible. This approach produces more reliable RAG systems while avoiding unnecessary complexity, latency, and cost.