Skip to content
Optimal Lab

AI Engineering · interactive

Hybrid search and reranking

Vector search finds meaning but misses exact codes. Keyword search finds exact words but misses paraphrases. Production RAG runs both, fuses the rankings, then lets a reranker pick. Try each query in each mode.

User

asks

Your app

fuses with RRF

Keyword index

BM25

Vector index

cosine

Reranker

cross-encoder

LLM

top 2 notes

An exact code. Keyword search finds it; the vector is vague because E1042 means nothing on its own.

Question

Retrieval

✓ Right note ranked first · wanted “Error E1042”

Step 1 of 5

  1. 1

    Keyword search (BM25)

    Scores notes that share exact terms with the question. Rare terms count more. Great for codes, names and IDs.

    1. 1. Error E1042 · e10421.42
  2. 2

    Vector search

    Embeds the question and finds the notes pointing the same way. Great for paraphrases, weak on codes it has never seen.

    1. 1. Error E20010.84
    2. 2. Error E10420.60
    3. 3. Slow checkout0.47
    4. 4. Card declined0.41
  3. 3

    Fuse with Reciprocal Rank Fusion

    Each list gives a note 1 / (60 + its rank). Add them up. Scores are never compared across methods, only ranks.

    1. 1. Error E10420.0325
    2. 2. Error E20010.0164
    3. 3. Slow checkout0.0159
    4. 4. Card declined0.0156
  4. 4

    Rerank the top few

    A cross-encoder reads the question and each note together. Slower per note, so it only sees a short list, but it is much more precise.

    1. 1. Error E10420.97
    2. 2. Error E20010.31
    3. 3. Slow checkout0.22
    4. 4. Card declined0.05
  5. 5

    Paste the winners into the prompt

    Only these notes reach the model. If the right one is not here, the answer is a guess.

    • Keyword onlyError E1042 ✓
    • Vector onlyError E2001 ✗
    • Hybrid (RRF)Error E1042 ✓
    • Hybrid + rerankError E1042 ✓