Optimizing Retrieval Speed and Relevance
This lesson covers index optimisation, query preprocessing and hybrid search with custom scoring, since in RAG applications retrieval latency adds directly to time to first token and its relevance decides answer quality.
Learning outcomes
After completing this lesson, you will be able to:
- Tune vector index settings for speed and recall.
- Preprocess and filter queries.
- Tune hybrid search weights on labelled queries.
Index optimisation
Vector index settings determine both search speed and recall, the share of true nearest neighbours that a search finds. Most vector stores use the HNSW (Hierarchical Navigable Small World) algorithm, a graph that is searched approximately rather than exhaustively. Its parameter m sets how many connections each vector has, and ef_search sets how many candidates a search examines; lower values are faster but find fewer true neighbours.
Index size also matters, because an index that fits in memory is searched far faster than one that must be read from disk. Quantization, which stores vectors at lower precision, and lower embedding dimensions shrink the index. Correctly sized shards and replicas, removal of deleted and duplicate documents and periodic merging of index segments keep searches efficient. Every change is validated with a retrieval test set, so that a gain in speed does not come with an unnoticed fall in recall.
Speed or recall?
Query preprocessing and filtering
Work done on the query before searching improves both speed and relevance. Query preprocessing normalises text, corrects spelling, expands abbreviations, extracts filters such as a product, date or region mentioned in the question, and rewrites conversational follow-ups into standalone queries.
Metadata pre-filtering then restricts the search to a subset of the index, such as documents about one product line, which reduces the work the search must do and removes irrelevant results before they can distract the model. Simple routing can skip retrieval altogether for greetings or general questions that need no company knowledge. Caching the embeddings of frequent queries saves an embedding call on every repeat of those queries.
Faster, cleaner retrieval
Hybrid search with custom scoring
Hybrid search combines keyword and vector results; custom scoring tunes how. Weights between lexical and semantic scores are tuned on labelled queries, and can differ by query type, for example favouring lexical matches when the query contains an identifier. Additional scoring functions boost recent documents, authoritative sources or documents in the user's language. A reranker on a moderate candidate set adds precision; retrieving fewer final chunks reduces generation latency and cost. The following table summarises retrieval optimisations.
| Optimization | Improves | Validate with |
|---|---|---|
| HNSW and quantisation tuning | Latency and memory | Recall at k on a test set |
| Metadata pre-filtering | Latency and precision | Filter correctness |
| Query rewriting and normalisation | Relevance | Retrieval test set with conversational queries |
| Hybrid weights and boosts | Relevance for mixed query types | MRR and recall by query type |
| Fewer final chunks after reranking | Generation latency and cost | Answer quality evaluation |
The following diagram compares slow, noisy retrieval before and after changes to filtering and index settings.

Slow, noisy retrieval
Retrieval takes 900 ms and returns chunks from all product lines, although users always ask about the product they have open.
Passing the open product as a metadata filter narrows the search, cutting latency and removing irrelevant chunks; tuning ef_search on a test set trims latency further without recall loss; and keeping the top 5 reranked chunks reduces prompt size.
Against what should HNSW and quantisation settings be tuned?
Show answer
A recall test set, so latency gains do not silently reduce retrieval quality.
Exam Tips
Remember for the exam
- Tune HNSW and quantisation against a recall test set.
- Pre-filter on metadata to cut latency and noise.
- Rewrite and normalise queries before searching.
- Tune hybrid weights and boosts per query type.