FinalYearKitFinalYearKit
All posts
Architecture13 min read·

Hybrid search in RAG: why keyword + vector beats either alone

Pure vector search misses exact IDs and dates. How BM25 plus embeddings with reciprocal rank fusion fixes blind spots in student RAG projects.

R

Rajan

Founder & kit engineer

Pure vector search is the default in RAG tutorials — and it is the reason many student demos fail on real questions. When a user asks for “Section 4.2 on page 87” or “Q3 2024 revenue for Project Apollo,” embeddings treat similar phrases as interchangeable. Hybrid search runs keyword matching alongside semantic search, then merges rankings. That single design choice is often the difference between a calm viva and an awkward silence when the wrong chunk appears.

This article is for final year students building document or transcript Q&A systems such as Chat with PDF and Chat with YouTube. You do not need an enterprise search platform. You need a clear mental model, one diagram, and a demo that shows why hybrid helps.

What pure vector search misses

Embeddings encode meaning, not spelling. Two chunks about different years, project codes, or clause numbers can sit close in vector space because the surrounding language is similar. Students discover this live when the examiner asks a precise factual question and the system confidently retrieves the neighbor chunk.

Keyword search (commonly BM25) catches exact tokens: years, section numbers, SKUs, names, course codes. Vector search catches paraphrases: “revenue growth” vs “sales increased,” or “penalties” vs “consequences for violation.” Production RAG systems — and viva-ready student projects — need both behaviors.

A viva-friendly one-liner

“Vector search finds meaning; keyword search finds exact tokens; hybrid merges both so we are less likely to miss IDs and dates.” Memorize it, then prove it with a demo.

How hybrid retrieval works

Step 1: Embed the query and retrieve top-N chunks by similarity (often cosine similarity on normalized vectors).

Step 2: Tokenize the query and run BM25 over the same chunk corpus.

Step 3: Merge the two ranked lists. Reciprocal Rank Fusion (RRF) is a popular merge: each chunk gets a score contribution of 1 / (k + rank) from each list, then sums. Chunks that rank well on both lists rise to the top.

RRF avoids painful normalization between BM25 scores and vector distances. For student projects, k is often 60; you rarely need exotic tuning to defend the idea.

Shared chunk IDs are mandatory

Both indexes must refer to the same chunk objects. If BM25 returns “chunk_17” and FAISS returns a different slicing of text without stable IDs, fusion becomes nonsense. Store chunk_id, page or timestamp, and text once; index twice.

Worked example: year and name confusion

Suppose chunk A says “Project Apollo revenue was 2.1M in Q2 2023” and chunk B says “Project Artemis revenue was 3.4M in Q3 2023.” The user asks: “What was Apollo Q3 2023 revenue?”

Pure vector search may return chunk B because “Q3 2023 revenue” language aligns strongly, while “Apollo” vs “Artemis” is only one token difference in a sea of similar finance prose. BM25 penalizes missing “Apollo” in chunk B and boosts chunks containing Apollo. Hybrid merge surfaces a better candidate — or at least makes the miss easier to debug when you log both lists.

Important honesty for viva: if the document never states Apollo Q3 revenue, the correct system behavior is refusal or “not in context,” not a fused wrong answer. Hybrid improves retrieval; it does not invent facts.

When to mention hybrid search in your viva

Say: “We use hybrid retrieval because users ask both conceptual and exact-match questions.” Then demo two prompts:

  1. ▸A question with a specific year, section number, or rare proper noun from the source.
  2. ▸A paraphrased conceptual question with no exact phrasing overlap.

Both should retrieve sensible chunks in a well-tuned system. Show an expander with retrieved text so the panel sees evidence, not only the LLM’s final sentence.

Implementation notes for students

Libraries you can name without claiming enterprise scale: rank_bm25 (BM25Okapi) for keyword; FAISS for vectors; application code for RRF. Index the same chunks in both systems with shared IDs. Log retrieved chunks during testing — you will see when hybrid saves you.

Practical starting point: top-20 vector + top-20 BM25, fuse, take top-5, pass top-3 to the LLM. Adjust chunk size before you obsess over fusion weights. Bad chunking makes both retrievers look worse.

Framework options

Some students use LangChain EnsembleRetriever or LlamaIndex hybrid modes; others write a 30-line merger. In viva, name what you used and one alternative you considered. Depth beats framework name-dropping.

BM25 in plain English

BM25 scores documents by term frequency with saturation — repeating a word helps less after a point — and length normalization so short chunks are not unfairly rewarded or punished. It excels when users paste exact phrases, SKUs, section numbers, or dates. It fails when the user only paraphrases and shares few tokens with the source.

That failure mode is why vector search exists. Hybrid is the compromise.

Reciprocal Rank Fusion (RRF) without mysticism

You run vector search and BM25 separately. Each returns an ordered list. RRF cares about ranks, not raw scores. A chunk that is rank 1 in BM25 and rank 4 in vector search gets strong combined credit. A chunk that is rank 50 in both stays weak.

Debugging tip

Log columns: chunk_id, vector_rank, bm25_rank, rrf_score. When a demo question fails, you can tell whether BM25 never saw the token (tokenization/OCR issue) or vector search drifted (embedding/chunk boundary issue). That log is gold in Chapter 7 and in viva.

When hybrid search hurts or adds little

Tiny corpora under roughly twenty chunks: keyword search may add little beyond scanning everything. Highly semantic queries with no exact tokens: vector alone may suffice. Extremely noisy OCR text: BM25 may latch onto garbage tokens. Explain when you would simplify to vector-only to reduce complexity — examiners like scoped judgment.

Limitations to state honestly

Hybrid search still fails on typos in rare names, severe OCR errors in scanned PDFs, and questions that require arithmetic across many disjoint chunks. Pair hybrid retrieval with citation display so wrong retrievals are visible during demo, not hidden behind fluent prose. For the broader pipeline, see how RAG works.

Tuning for your demo document

Build five questions that tend to fail vector-only search: exact figure, section number, named entity with unusual spelling, course code, table footnote. Show hybrid improving retrieval on those. Document results qualitatively in Chapter 7. You do not need a research-lab benchmark to be credible at undergraduate level — you need honesty and a small labeled set.

Chunking interacts with hybrid search

If you chop mid-sentence and strip section headers, BM25 loses the tokens that make exact match work. Prefer chunking that preserves page boundaries for PDFs and timestamp windows for transcripts. Overlap helps semantic continuity; headers help keywords.

Reporting hybrid search in Chapter 4

Draw two parallel arrows from “User Query” to “Vector Index” and “BM25 Index,” converging at “RRF Merge,” then “Top-k Chunks → Prompt → LLM.” One clear diagram answers a large fraction of architecture questions. Label data stores and note that both indexes share chunk IDs.

Comparison table worth including

| Question type | Vector alone | BM25 alone | Hybrid | | --- | --- | --- | --- | | Paraphrase | Strong | Weak | Strong | | Exact ID / date | Risky | Strong | Strong | | Mixed | Mixed | Mixed | Best default |

Keep the table qualitative unless you measured something.

Libraries and local vs hosted search

Elasticsearch or OpenSearch can host BM25 at larger scale; for final year scope, in-process BM25 plus FAISS is defensible and easier to demo offline. If asked why not Pinecone-only, answer with hybrid needs and local lab constraints — see also FAISS vs Pinecone for student projects.

Prompting still matters after fusion

Better retrieval cannot fix a prompt that encourages guessing. Instruct the model to use only provided context and to cite pages or timestamps. Hybrid reduces bad context; prompting reduces hallucination style.

Demo script that proves the point

  1. ▸Upload your domain PDF or index your transcript.
  2. ▸Ask the exact-match question; open retrieved chunks; point to BM25-friendly tokens.
  3. ▸Ask the paraphrase question; show vector contribution.
  4. ▸Ask an out-of-document question; show refusal.
  5. ▸Optionally disable BM25 in a debug toggle (if you built one) to show a regression — powerful, but only if stable.

Total time: about four minutes if you rehearse.

Common student pitfalls

  • ▸Different chunking for BM25 and vectors.
  • ▸Forgetting to lower-case / tokenize consistently for BM25.
  • ▸Sending twenty huge chunks to the LLM after fusion “just in case.”
  • ▸Claiming hybrid “guarantees correctness.”
  • ▸No logging, so you cannot explain a failure when it happens on stage.

Checklist before viva

  • ▸Diagram drawn from memory in under a minute.
  • ▸Two demo questions prepared (exact + paraphrase).
  • ▸One failure case prepared.
  • ▸RRF explained without reading notes.
  • ▸Honest limitation list ready.
  • ▸Citations visible in UI.

Hybrid search is not a buzzword to sprinkle in the abstract. It is a concrete answer to a concrete failure mode examiners can trigger with one precise question. Kits such as Chat with PDF and Chat with YouTube ship with hybrid retrieval so you can spend time evaluating and explaining rather than wiring indexes from zero under deadline pressure.

Tokenization details students should be ready to mention

BM25 quality depends on how you split text. Lowercasing is common. Simple whitespace tokenization works for demos; for Indian documents with hyphenated course codes, keep codes intact. If you strip all punctuation aggressively, “4.2” may become useless fragments. State your tokenizer choices in Chapter 5 even if simple.

Stopwords: yes or no?

Removing “the” and “and” can help BM25 focus on content tokens. Removing too much can hurt queries that rely on short technical tokens. For final year scope, start with a standard English stopword list and note that domain PDFs may need custom keep-lists for codes.

Embedding model consistency

The query and the chunks must use the same embedding model and the same normalization practice. If you embed documents with model A and queries with model B, hybrid cannot save you from a broken vector channel. Pin model names in requirements and report.

Multilingual and transliteration issues

English paraphrases work well with common embedding models. Queries that mix Hindi transliteration and English PDF text may miss both channels. If your college docs are bilingual, test at least three mixed queries and report what failed. That honesty is stronger than claiming universal language support.

Designing the two-question viva pair

Exact-match candidate examples:

  • ▸“What does section 3.1 say about late submission?”
  • ▸“Find the fine amount for 2024 batch students.”
  • ▸“What is the code for the Data Structures lab?”

Paraphrase candidates:

  • ▸“What happens if I submit my project late?”
  • ▸“How are penalties described?”
  • ▸“Where is programming lab information?”

Pick pairs from your PDF so the demo cannot be derailed by an unfamiliar sample file.

Logging format you can paste into the report

For each test question, record: query text, top vector IDs, top BM25 IDs, fused top-k, whether the expected page appeared in top-3, notes. Ten rows of this table beat a paragraph claiming “accuracy is high.”

Hybrid search and citations together

Retrieval quality is wasted if the UI hides sources. Always show page or timestamp with the answer. When hybrid retrieves the right chunk but the model paraphrases vaguely, citations still let you defend system behavior: “retrieval succeeded; generation was loose; we tightened the prompt.”

Failure taxonomy for Chapter 7

  1. ▸Exact token missing because OCR/parsing dropped it.
  2. ▸Vector drift to a similar but wrong entity.
  3. ▸Correct chunk retrieved but truncated mid-table.
  4. ▸Fusion buried the correct chunk below top-k cutoff.
  5. ▸Question requires multi-hop reasoning across sections.

Assign at least one example from your testing to a bucket. Panels love structured limitation talk.

Why RRF instead of weighted score sums?

Students sometimes multiply BM25 scores with cosine similarities. Those scales differ wildly. RRF sidesteps calibration. If asked about alpha-weighted fusion, say it is valid when you tune on labeled data; RRF is a robust default for undergraduate timelines. Knowing why you did not tune alpha shows maturity.

k in RRF

Explain k as a dampener so rank 1 does not completely dominate, while still preferring higher ranks. You do not need to derive the formula on the board unless invited; you should state the formula and typical k.

YouTube / transcript angle

For transcript RAG, “exact match” may be a spoken name or a topic phrase that appears rarely. Hybrid helps pull the right window before you cite a timestamp. The fusion logic is the same; metadata becomes time instead of page. Mentioning that parallel impresses panels who ask whether your understanding transfers.

What not to say

Do not claim hybrid search makes hallucination impossible. Do not claim BM25 is AI. Do not claim you implemented Elasticsearch if you used rank_bm25. Precise vocabulary is part of architecture marks.

Implementation checklist before freezing the demo

  • ▸Stable chunk IDs shared across indexes.
  • ▸Page/timestamp metadata on every chunk.
  • ▸Log file or debug expander for ranks.
  • ▸Top-k small enough for the model.
  • ▸Two rehearsed questions + one refusal.
  • ▸Diagram matches code module names.
  • ▸Limitations written without panic language.

Hybrid search is a teaching-friendly upgrade over tutorial vector-only RAG. Treat it as core architecture, evaluate it briefly, and let the demo prove the story.

Related reading

See how RAG works for the full pipeline and FAISS vs Pinecone for student projects for vector store choices.

Project kits mentioned

  • ▸Chat with PDF — document Q&A with hybrid retrieval and page citations to defend in viva.
  • ▸Chat with YouTube — transcript RAG where hybrid search helps timestamp-accurate answers.

Takeaway: Hybrid search fixes the exact-match blind spot in vector-only RAG — implement it, log ranks, and explain RRF in your report with a two-question demo. FinalYearKit RAG projects include hybrid retrieval so you can focus on evaluation, citations, and viva clarity.

Ready to work on your own project?

We build complete project kits with source code, report, slides, and viva prep — message us on WhatsApp to get started.

Ask about this on WhatsApp
Message us