TECHNOLOGIESTieInn Technologies

Better retrieval: keyword plus vector search, filters and reranking

RAG & Vector Search · 10 questions

Short notes

Key idea

Vector search alone misses exact terms; keyword search alone misses paraphrases. Hybrid search combines both, metadata filters narrow the candidates, and a reranker reorders the top results by reading query and chunk together.

Syntax

  • Keyword (BM25): scores exact word matches, great for codes, names and rare terms.
  • Hybrid: run both, merge with reciprocal rank fusion: score = Σ 1 / (60 + rank).
  • Filters: department = "HR", date >= 2024, applied before or during search.
  • Reranking: retrieve 30 candidates cheaply, rerank with a cross-encoder or a model, keep the top 5.
  • Query rewriting: expand or clarify the user's question before searching.

Example

"Error E-4021 on the X200 printer": vector search returns general printer pages; BM25 finds the exact error code page. Fused, the right chunk is ranked first.

Traps

  • Adding everything at once: measure each change on your test set.
  • Reranking adds latency and cost; rerank a few dozen, not thousands.
  • Filters on wrong metadata silently hide the right chunk.
  • Rewritten queries can drift from what the user meant; log them.

Want the full lesson with step-by-step examples, a project and a certificate? RAG & Vector Search course, ₹180 →

Questions

Open in Code Lab5 free questions
5 questions

    Better retrieval: keyword plus vector search, filters and reranking

  1. Question 1easy

    Which query is keyword search most likely to handle better than embeddings?

  2. Better retrieval: keyword plus vector search, filters and reranking

  3. Question 2medium

    A word appears in 2 of 37 chunks; another in 30 of 37. Which IDF is larger? What does this print?

    import math
    N = 37
    idf = lambda df: math.log(1 + (N - df + 0.5) / (df + 0.5))
    print(idf(2) > idf(30))
  4. Better retrieval: keyword plus vector search, filters and reranking

  5. Question 3medium

    What does this print?

    from collections import Counter
    total = Counter()
    for ranking in [["X", "Y"], ["Y", "Z"]]:
        for rank, d in enumerate(ranking, start=1):
            total[d] += 1 / (60 + rank)
    print(total.most_common(1)[0][0])
  6. Better retrieval: keyword plus vector search, filters and reranking

  7. Question 4medium

    Why merge keyword and vector results by rank (RRF) instead of adding their scores?

  8. Better retrieval: keyword plus vector search, filters and reranking

  9. Question 5medium

    The app knows a question is about an existing order. What's the best use of that?

5 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.