agentleFS
Goodnight77Goodnight77/rag-skills/skills/retrieval-strategies/multi-pass-retrieval-with-reranking/SKILL.md

multi-pass-retrieval-with-reranking

Skill8 starsChanged 7 months agoMITView on GitHub

Use a two-stage retrieval pipeline with reranking to balance recall, precision, and latency.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Add caching and optimizations for production use.

    line 54
  2. Distinctive:

    When document collections are too large for full cross-encoder search

    line 62
  3. Distinctive:

    When you can tolerate slightly higher latency for better results

    line 64
  4. Distinctive:

    When latency must be minimized (single bi-encoder is faster)

    line 68
  5. Distinctive:

    When bi-encoder already provides excellent relevance

    line 70

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Overview

Multi-pass retrieval with reranking is a two-stage approach that first retrieves a broad set of candidates using fast bi-encoder search, then refines them using a more accurate but slower cross-encoder reranker. This balances recall and relevance while maintaining acceptable latency.

Problem Statement

Single-stage retrieval has inherent trade-offs:

  • Bi-encoder only: Fast but limited relevance - struggles with complex query-document relationships
  • Cross-encoder only: Accurate but too slow for large document collections
  • Fixed top-k: Can't adapt to query difficulty - some queries need more/ fewer candidates
  • Static retrieval: Can't incorporate user feedback or context during retrieval

Key Concepts

  • Bi-Encoder: Fast encoding model that produces fixed vectors for documents and queries
  • Cross-Encoder: Joint query-document encoder for accurate scoring (but slower)
  • Two-Stage Retrieval: Broad retrieval followed by refinement
  • Adaptive Top-K: Dynamically adjust retrieval depth based on query characteristics
  • Reranking Pipeline: Post-retrieval scoring and reordering of candidates

Implementation Guide

Step 1: Set Up Bi-Encoder Retrieval

Implement the first-stage retrieval using your vector database.

Why: Bi-encoder retrieval is fast and scalable but produces approximate scores - suitable for the first pass to narrow candidates.

Step 2: Set Up Cross-Encoder Reranking

Implement the second-stage reranking for accurate scoring.

Why: Cross-encoders produce more accurate relevance scores by jointly encoding query-document pairs, but are too slow for full-scale retrieval.

Step 3: Implement Adaptive Retrieval

Dynamically adjust retrieval parameters based on query characteristics.

Why: Adaptive retrieval ensures complex queries get more candidates for reranking while simple queries remain fast.

Step 4: Build the Multi-Pass Pipeline

Combine all components into a complete retrieval pipeline.

Why: A unified pipeline with timing and explanation makes it easy to optimize and debug the retrieval system.

Step 5: Implement Cache and Optimization

Add caching and optimizations for production use.

Why: Caching reduces computation for repeated queries, which is common in production systems.

For working examples, see Sentence Transformers CrossEncoder docs, Sentence Transformers rerankers, Sentence Transformers retrieve & re-rank, and the MonoT5 paper.

When to Use This Skill

  • Production RAG systems where relevance is critical
  • When document collections are too large for full cross-encoder search
  • For complex queries where bi-encoder precision is insufficient
  • When you can tolerate slightly higher latency for better results
  • For applications with clear performance metrics (NDCG, precision@k)

When NOT to Use This Skill

  • When latency must be minimized (single bi-encoder is faster)
  • For very small collections where full cross-encoder is feasible
  • When bi-encoder already provides excellent relevance
  • For simple keyword searches (BM25 may suffice)

Related Skills

  • Hybrid Search BM25 Dense - First-stage enhancement
  • Semantic Chunking - Better input for retrieval
  • Optimize Retrieval Latency - Performance tuning

Metrics & Success Criteria

  • Relevance: NDCG@10 improvement > 10% over bi-encoder alone
  • Latency: Total retrieval < 500ms for typical queries
  • Recall: Maintain > 95% recall of first stage
  • Reranking Quality: Reranked top-10 should significantly outscore stage-1 top-10
  • Cost Efficiency: Acceptable computational overhead vs. relevance gain

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.