RAG Beyond Vector Search: Hybrid Retrieval, Reranking and Context Optimisation
Published on Sep 1 hour ago · By FlipCode Team
Most teams building Retrieval-Augmented Generation (RAG) systems start the same way:
embed your documents, store them in a vector database, and let cosine similarity do the rest.
It works in a demo — clean questions, small corpus, forgiving evaluation. Then it hits
production traffic, and the cracks show: exact-match queries return nothing useful,
semantically "close" chunks turn out to be contextually wrong, and the context window fills
up with three near-identical paragraphs while the one fact the model actually needed never
made the cut.
The fix isn't a bigger embedding model. It's a better retrieval architecture. This post
covers the techniques that separate prototype RAG from production-grade RAG: hybrid retrieval,
reranking, context optimisation, and the supporting layers — query transformation and
evaluation — that make the whole pipeline trustworthy. This is the architecture Flipcode
Solutions reaches for when a client's RAG system needs to hold up under real usage, not just a demo.
Dense vector search is excellent at capturing semantic similarity, but it has predictable,
well-documented blind spots:
These gaps are exactly why production RAG systems increasingly combine multiple retrieval
signals rather than relying on embeddings alone.
Before touching retrieval strategy, it's worth acknowledging that a large share of RAG
failures start with the query itself. Users ask vague, underspecified, or multi-part
questions, and feeding that raw text directly into a retriever often produces mediocre
results regardless of how good the retrieval stack is downstream.
Common query transformation techniques:
This step is cheap relative to what it saves downstream — a well-formed query makes both
hybrid retrieval and reranking meaningfully more effective.
Hybrid retrieval fuses two complementary approaches:
RRF score:
Where
Some systems use a weighted linear combination instead of RRF:
With
Most production-grade vector databases (Weaviate, Qdrant, Pinecone, Elasticsearch, Vespa)
now support hybrid search natively, so this is often a configuration change rather than a rebuild.
Hybrid retrieval gets you a better candidate pool — but the initial ranking still relies
on relatively cheap similarity metrics computed independently for query and document.
Reranking adds a second stage: a more expensive but far more accurate model that re-scores
the top 20–100 candidates before final context selection.
First-stage retrieval (dense or sparse) scores query and document independently, then
compares vectors or term overlap. Cross-encoder rerankers, by contrast, feed the query
and document together into a transformer, letting the model directly attend to how the
two relate token-by-token.
This joint encoding is computationally heavier — which is why it's applied only to a
shortlist, not the full corpus — but it produces meaningfully better relevance judgments,
often closing gaps that no amount of embedding fine-tuning fixes.
Even with great retrieval and reranking, dumping the top-K chunks straight into the
context window is a mistake. Context optimisation is about curating what the LLM
actually sees, in what order, and in what form.
None of the above matters if you can't measure whether it's improving answers.
Production RAG teams typically evaluate at two levels:
Does the pipeline find the right chunks? Does the final answer hold up?
Frameworks like RAGAS, TruLens, or a custom labeled evaluation set (even 50–100 hand-labeled
query/answer pairs) let you A/B test changes — a new reranker, a different chunking strategy,
an added hybrid weight — against a baseline instead of guessing.
This is the step teams most often skip, and it's usually why "we tried reranking and it
didn't help" turns out to mean "we never actually measured it."
This layered approach costs more in latency and infrastructure than naive vector-only RAG,
but it directly addresses the failure modes teams hit in production: missed exact matches,
irrelevant chunks, context-window bloat, and — critically — the inability to know whether
any of it is actually working.
Vector search is a strong starting point for RAG, but it's not the finish line. Query
transformation cleans up what enters the pipeline. Hybrid retrieval closes the gap on
exact-match queries. Reranking sharpens relevance beyond what embeddings alone can judge.
Context optimisation ensures the LLM sees a clean, non-redundant, well-ordered set of
evidence. And evaluation ties it all together, turning "we think this is better" into
something you can actually prove.
Together, these layers are what separate a RAG demo from a RAG system that holds up under
real usage.
Why Vector Search Alone Falls Short
Query Transformation: Fixing the Problem Before Retrieval Even Starts
Hybrid Retrieval: Combining Sparse and Dense Search
How It Works in Practice
RRF_score(doc) = Σ 1 / (k + rank_i(doc))
rank_i(doc) is the document's rank in retrieval system
i, and k is a small constant (typically 60) that dampens
the influence of very high ranks so no single system dominates the fused ranking.
Weighted Hybrid Variants
score = α · dense_score + (1 − α) · sparse_score
α tuned per domain. This requires normalizing both score distributions
(e.g., min-max scaling) and tends to need more manual tuning than RRF, but can outperform
it once tuned for a specific corpus.
When Hybrid Retrieval Matters Most
Reranking: A Second, Smarter Pass
Why Rerankers Outperform First-Stage Retrieval
Common Reranking Approaches
Method
Description
Trade-off
Cross-encoder rerankers
(e.g., Cohere Rerank, BGE-reranker, Jina Reranker)
Jointly encode query + document and output a relevance score.
High accuracy, higher latency, one forward pass per candidate.
LLM-based reranking
Prompt an LLM to score or reorder candidates, optionally with chain-of-thought.
Flexible and explainable, but costly and slow at scale.
ColBERT-style late interaction
Token-level similarity between query and document embeddings.
Balances speed and accuracy; more infrastructure complexity.
Learning-to-rank (LTR) models
Classical ML models (e.g., LightGBM) trained on relevance features.
Fast and interpretable, but needs labeled training data.
Practical Guidance
Context Optimisation: What Actually Goes Into the Prompt
Key Techniques
A Simple Context Assembly Pipeline
Evaluating the Pipeline: How to Know It's Actually Working
Retrieval-Level Metrics
Generation-Level Metrics
Common Pitfalls Worth Naming
Putting It Together: A Production RAG Architecture
Query
│
├── Query Rewriting / Expansion / Decomposition
│
├── Sparse Retrieval (BM25) ──┐
├── Dense Retrieval (Vector) ─┼──> RRF Fusion ──> Top 50
│
├── Cross-Encoder Reranker ──> Top 10–15 Candidates
│
├── Dedup + MMR + Compression ──> Final Context Window
│
├── LLM Answer Generation
│
└── Evaluation Loop (Recall@k, Faithfulness, Answer Relevance)
Conclusion