Skip to main content
InterviewHubPRO
Section Overview
Q42

Question 42 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

84%
Vector DBs & RAG (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

Cross-Encoder Re-Ranking: Architecture, latency overhead, and recall improvements.

senior LevelSystem Design

In Simple Words:

  • Bi-Encoder (Vector Search): Encodes Query and Document separately into two vectors, computing similarity via fast dot product ($< 5 ext{ms}$). High speed, but lacks fine token-to-token attention.
  • Cross-Encoder (Re-Ranker like Cohere Rerank or BGE-Reranker): Passes Query and Document together through a transformer cross-attention layer:
    • Every query token attends to every document token simultaneously.
    • Produces an exact relevance score (0.0 to 1.0).
  • Two-Stage Retrieval Pattern:
    1. Vector search fetches the top 50 coarse candidates (5ms).
    2. Cross-Encoder re-ranks the 50 candidates, picking the top 5 highest-quality chunks (30ms).
    3. Eliminates irrelevant chunks before stuffing into the LLM context.