Skip to main content
Two-stage retrieval first casts a wide net with fast vector search, then uses a cross-encoder model to precisely score the top candidates. Cross-encoders see query and document together, enabling much finer relevance judgments than embedding similarity alone.

How it works

Reranking implements a two-stage retrieval process to improve search quality over pure vector similarity.

Reranking process

  1. Candidate retrieval - Retrieve top-k candidates using fast ANN search
  2. Cross-encoder scoring - Apply cross-encoder to score query-document pairs
  3. Reranking - Sort candidates by cross-encoder scores
  4. Top-k selection - Return top rerank_k documents
  5. Optional RAG - Generate answer using reranked context

Cross-encoder vs bi-encoder

Bi-encoders (used in vector search)
  • Embed query and documents independently
  • Enable fast approximate nearest neighbor search
  • Cannot capture query-document interactions
  • Used in first-stage retrieval
Cross-encoders (used in reranking)
  • Process query and document together
  • Compute attention across both inputs
  • Capture fine-grained semantic interactions
  • Higher accuracy but slower (O(n) comparisons)
Typical pipelines retrieve candidates with bi-encoders, then rerank top-k with cross-encoders.

Key features

  • Models: modern cross-encoder rerankers and lightweight scoring models
  • Integrated evaluation with contextual recall, precision, and faithfulness metrics
  • Configurable candidate pool size and final result count
  • Compatible with all vector databases

Implementation

Configuration

Required settings

string
required
Vector database API authentication
string
required
Target index for candidate retrieval
string
required
Cross-encoder model for reranking

Optional settings

string
Namespace for document isolation
object
Embedding model for candidate retrieval
object
Optional LLM for RAG answer generation

Example configuration

Search parameters

string
required
Search query text to execute
integer
default:10
Number of candidates to retrieve before reranking. Higher values improve reranking quality but increase latency.
integer
default:5
Number of results to return after reranking. Should match your application’s result display needs.
dict
Optional metadata filters for pre-filtering candidates

Fast models (low latency)

Fast, good accuracy. Best for production systems with latency requirements.
  • Layers: 6
  • Parameters: ~22M
  • Latency: ~10ms per pair
  • Use case: Default choice for most applications
Extremely fast, acceptable accuracy. For high-throughput scenarios.
  • Layers: 2
  • Parameters: ~4M
  • Latency: ~3ms per pair
  • Use case: High QPS, latency-critical

Accurate models (higher quality)

More accurate, slower. For offline evaluation or quality-critical applications.
  • Layers: 12
  • Parameters: ~33M
  • Latency: ~20ms per pair
  • Use case: Batch processing, high quality needs
Multilingual, high accuracy. For global applications.
  • Layers: 12
  • Parameters: ~568M
  • Latency: ~50ms per pair
  • Use case: Multilingual, maximum quality

Performance considerations

Candidate pool sizing

  • top_k controls the candidate pool size
  • Larger values improve reranking quality but increase latency
  • Recommended: 5-10x rerank_k
  • Example: top_k=50, rerank_k=10

Latency optimization

Cross-encoder latency scales linearly with top_k. For latency-sensitive applications:
  1. Use smaller cross-encoder models (6-layer or TinyBERT)
  2. Limit top_k to 20-30 candidates
  3. Cache reranking results for popular queries
Latency formula

Quality vs speed tradeoff

Use cases

When accuracy matters more than recall:

Complex semantic queries

Queries requiring deep understanding:

Domain-specific retrieval

Specialized domains with nuanced relevance:

Evaluation metrics

Reranking performance can be measured with:
  • Contextual recall - Fraction of relevant docs in reranked results
  • Precision@k - Accuracy of top-k reranked results
  • NDCG@k - Normalized discounted cumulative gain
  • MRR - Mean reciprocal rank of first relevant result
  • Faithfulness - Alignment between reranked context and answers

Implementation details

How cross-encoders work

Cross-encoders process query and document together, enabling:
  • Query-document attention
  • Fine-grained token interactions
  • Context-aware relevance scoring

Reranking helper

Semantic search

First-stage candidate retrieval

Hybrid search

Dense + sparse fusion before reranking

Contextual compression

Reduce context after reranking

MMR

Diversity-aware reranking