# Hybrid Search: Keywords Plus Vectors

> Combine BM25-style keyword search with semantic search so exact names, codes and rare terms are found along with paraphrases. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/ai-engineer/hybrid-search
Last updated: 2026-11-28

Combine BM25-style keyword search with semantic search so exact names, codes and rare terms are found along with paraphrases.

Intermediate · about 4 hours · difficulty 3/5

Learn first: [RAG Fundamentals](https://www.internhack.in/roadmaps/tracks/ai-engineer/rag-basics)

Vector search is great at meaning and bad at exactness. Ask for "error E-4021" or a specific person's name and embeddings may return vaguely related chunks. **Keyword search** (BM25, the classic ranking algorithm behind search engines) nails exact matches but misses paraphrases. Use both.

### How hybrid search works

1. Run a keyword query and a vector query in parallel.
2. Merge the two ranked lists. **Reciprocal Rank Fusion (RRF)** is the popular, tuning-free method: each result scores the sum of `1 / (k + rank)` over the lists it appears in.
3. Optionally rerank the merged list (next topic).

### Implementations

- Postgres: `tsvector` full-text search plus pgvector, fused in SQL or in code.
- Search engines: Elasticsearch, OpenSearch and Vespa support both natively.
- Vector databases like Qdrant and Weaviate offer hybrid modes, sometimes with sparse vectors.

### Query-side improvements

- **Metadata filters** extracted from the question ("in 2024", "for the HR team").
- **Query rewriting**: use an LLM to turn a conversational follow-up ("what about for interns?") into a standalone query.

### Good enough to move on

You can show a set of queries where vector-only search fails, keyword-only search fails, and hybrid gets both right.

## Key concepts

- **BM25 keyword search**
- **Reciprocal Rank Fusion**
- **Postgres full-text plus pgvector**
- **Sparse vectors (SPLADE-style)**
- **Metadata filter extraction**
- **Query rewriting for follow-ups**

## Mini project

Add BM25 or Postgres full-text search to your RAG app, fuse it with vector results using RRF, and build a 30-query comparison table of keyword, vector and hybrid hit rates.

## Check yourself

Give an example query where semantic search is likely to fail but keyword search succeeds, and explain why.

## Free resources

- [Okapi BM25](https://en.wikipedia.org/wiki/Okapi_BM25) (Wikipedia)
- [Qdrant: hybrid queries](https://qdrant.tech/documentation/concepts/hybrid-queries/) (Qdrant)
- [PostgreSQL full text search](https://www.postgresql.org/docs/current/textsearch.html) (postgresql.org)

Previous: [Document Ingestion and Parsing](https://www.internhack.in/roadmaps/tracks/ai-engineer/document-ingestion) · Next: [Reranking Retrieved Results](https://www.internhack.in/roadmaps/tracks/ai-engineer/reranking)

## More in Retrieval-Augmented Generation

- [RAG Fundamentals](https://www.internhack.in/roadmaps/tracks/ai-engineer/rag-basics)
- [Document Ingestion and Parsing](https://www.internhack.in/roadmaps/tracks/ai-engineer/document-ingestion)
- [Hybrid Search: Keywords Plus Vectors](https://www.internhack.in/roadmaps/tracks/ai-engineer/hybrid-search)
- [Reranking Retrieved Results](https://www.internhack.in/roadmaps/tracks/ai-engineer/reranking)
- [Citations and Grounded Answers](https://www.internhack.in/roadmaps/tracks/ai-engineer/citations-grounding)
- [Evaluating Retrieval Quality](https://www.internhack.in/roadmaps/tracks/ai-engineer/retrieval-evaluation)
- [Advanced RAG Patterns](https://www.internhack.in/roadmaps/tracks/ai-engineer/advanced-rag)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [AI Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/ai-engineer)
