Intermediate10 min read9 of 40

Reranking

The quality filter — retrieves 10 docs, then a second model re-scores them. Two methods: fast cross-encoder or smarter LLM reranking.

Read first:Simple RAG

Overview

PropertyDetail
PatternReranking — The Quality Filter
Level4 (Better post-retrieval filtering)
Key InnovationSecond model re-scores retrieved docs
MethodsCross-encoder (fast, free) + LLM reranking (slow, smarter)
Notebook09_Reranking.ipynb

Architecture

flowchart TD
    A[User Query] --> B["Stage 1: Embedding Similarity (Qdrant)"]
    B --> C["Retrieve TOP-10 by cosine similarity"]
    C --> D{"Stage 2: Re-score"}
    D -->|Option A| E["Cross-Encoder (ms-marco-MiniLM)\nFast, free, local"]
    D -->|Option B| F["LLM Reranking (Claude)\nSlower but understands intent"]
    E --> G[Return TOP-3 after re-scoring]
    F --> G

Test Results: "What is the capital of France?"

RankBaseline (embedding similarity)After LLM Reranking
#1"The capital of France is huge" (0.87)"The capital of France is great" (8.0/10)
#2"The capital of France is great" (0.84)"The capital of France is beautiful" (7.4/10)
#3"The capital of France is beautiful" (0.75)"The capital of France is huge" (6.9/10)

Key Insight: The LLM scored ALL of these low (4-8/10) because none actually answer "What IS the capital?" — they just mention it. The Paris/Eiffel Tower docs would score much higher with LLM reranking because the LLM understands intent, not just similarity.


Two Reranking Methods

AspectCross-EncoderLLM Reranking
Modelms-marco-MiniLM-L-6-v2Claude Sonnet (Bedrock)
SpeedFast (~50ms for 10 docs)Slow (~2s for 10 docs)
CostFree (local)Paid (API call per doc)
UnderstandingSurface-level relevanceDeep intent matching
Best forHigh-volume, low-latencyHigh-stakes, accuracy-critical

When to Use

ScenarioUse Reranking?
Top-K retrieval returns noiseYes
Need precision over recallYes
Can tolerate +100-200ms latencyYes (cross-encoder)
Need intent-aware scoringYes (LLM method)
Ultra-low latency requiredNo
Already getting good results from embedding searchNo — diminishing returns

Tech Stack

ComponentTechnology
EmbeddingsAWS Bedrock — Amazon Titan Embed Text v2 (1024 dims)
LLMAWS Bedrock — Claude Sonnet
Cross-Encodersentence-transformers (ms-marco-MiniLM-L-6-v2)
Vector DBQdrant Cloud
FrameworkLangChain

Source