Skip to content

Advanced Search: hybrid search and re-ranking

Summary

A single vector search is insufficient for large knowledge bases. A hybrid search (semantic + keywords) and re-ranking of results are used.

Vector search searches by semantic meaning but often misses exact names: articles, model numbers, rare terms. Classic keyword search (BM25) searches exactly but does not understand synonyms. The solution is to combine.

Hybrid Search (vectors + BM25)

  1. Vector Search searches by semantic meaning.
  2. BM25 searches by exact keywords.
  3. The results are combined (in LangChain — EnsembleRetriever), and the top 20 candidates are retrieved.

Re-ranking (reranking)

The top 20 candidates are run through a re-ranker model:

  • Cohere Rerank
  • Cross-Encoder (open models)

The re-ranker resorts the list by relevance and leaves only the top 3–5 most accurate fragments. This sharply reduces token costs and increases answer accuracy.

Process Flow

flowchart LR
    A[Query] --> B[Vector Search]
    A --> C[BM25 Search]
    B --> D[Top-20 candidates]
    C --> D
    D --> E[Re-ranker]
    E --> F[Top-3 fragments]
    F --> G[Prompt for LLM]

See Also