惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
Recent Announcements
Recent Announcements
V
Visual Studio Blog
博客园 - 叶小钗
H
Help Net Security
aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
U
Unit 42
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Fortinet All Blogs
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
D
DataBreaches.Net
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
M
MIT News - Artificial intelligence

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
RAG Rerank: the Highest-Leverage Upgrade to Your Retrieva...
Devanshu Biswas · 2026-06-16 · via DEV Community

Devanshu Biswas

If your RAG app sometimes answers from the wrong document even though the right one was in your database, the fix usually isn't a better embedding model — it's adding a reranker. It's the single highest-leverage upgrade to a basic retrieval pipeline, and it's easy to bolt on.

This is Day 8 of PromptFromZero, where I break down one technique a day.

Why plain retrieval gets the order wrong

Standard RAG embeds your question and grabs the nearest document vectors. It's lightning fast — but that embedding squashes a whole passage into a single vector, so it often ranks a doc that merely shares words with your question above the one that actually answers it. Good enough for a first pass; not good enough to feed straight to the LLM.

const candidates = await vectorSearch(query, { k: 25 });  // fast, coarse

Bi-encoder vs cross-encoder (the key distinction)

Retrieval uses a bi-encoder: it encodes the query and each document separately, then compares the vectors. Fast, because every doc is pre-encoded once — but it never sees the query and the doc together.

A cross-encoder feeds the pair into the model together, so it can judge true relevance with full context. Far more accurate — at the cost of running once per candidate.

bi-encoder:    sim(embed(query), embed(doc))   ← fast, approximate
cross-encoder: model(query + doc) → score      ← slow, precise

The pattern: retrieve wide, rerank, keep narrow

You can't run an expensive cross-encoder over millions of documents. So:

  1. Retrieve a wide shortlist cheaply — grab the top 25, not the top 3.
  2. Rerank just those 25 with a cross-encoder, which re-reads each (query, doc) pair and assigns a precise relevance score.
  3. Keep only the best 2–4 for the prompt.
const scored  = await reranker.rank(query, candidates);
const context = scored.sort((a, b) => b.score - a.score).slice(0, 3);

In the interactive demo on the page, pick a question and watch the truly-relevant doc (highlighted green) sit at position #5 under plain retrieval, then climb to #1 after reranking. Same documents, much better order.

No reranker model? An LLM can do it

If you don't want a dedicated reranker (Cohere Rerank, bge-reranker, etc.), just ask an LLM to score each candidate:

Rate 0-10 how well this passage answers the question.
Question: {q}
Passage: {doc}
Score:

Run it per candidate, sort by the number. Slower and pricier per query, but zero extra infrastructure and surprisingly strong.

Why fewer, better passages win

After reranking you throw most candidates away. Fewer, higher-quality passages mean a shorter prompt, lower cost, and far less chance the model gets distracted by an irrelevant chunk that happened to share keywords. In RAG, the quality of your context beats the quantity every single time.

The tradeoff

Reranking adds a step — latency and a little cost. But for anything where a wrong answer is expensive (support, legal, medical, internal search), the accuracy jump is well worth it. If your RAG "knows" the answer but won't surface it, reach for a reranker first.

👉 See it reorder live (watch the right doc climb): https://dev48v.infy.uk/prompt/day8-rag-rerank.html

🌐 All techniques: https://dev48v.infy.uk/promptfromzero.php

Tomorrow: HyDE — write a hypothetical answer first, then search with that.