GuidesUnderstanding AI
Hybrid search: keywords and meaning, together
What each one misses
Keywords (BM25)
Meaning (embeddings)
Rank fusion
- 1Two listsThe top 50 of each search.
- 2A score per rank1 / (60 + rank) in each list.
- 3SumA document ranked well on both sides moves ahead.
function rrf(lists: string[][], k = 60) {
const score = new Map<string, number>();
for (const list of lists) list.forEach((id, i) => score.set(id, (score.get(id) ?? 0) + 1 / (k + i + 1)));
return [...score.entries()].sort((a, b) => b[1] - a[1]).map(([id]) => id);
}
Where to use it
| Case | Why hybrid |
|---|---|
| RAG on documentation | Free questions and exact function names |
| Store search | Intents and product references |
| Customer support | Varied wording and order numbers |
Vectors: the vector database. The next step: reranking. An example: semantic search for online stores.
Frequently asked questions
- How do you fuse two rankings with different scores?
- The most common method, reciprocal rank fusion (RRF), ignores the scores and adds up 1 / (k + rank) for each document in each list, with k often set to 60.
- Do I need a specialized engine?
- No. PostgreSQL does both with its full-text search and the pgvector extension. Dedicated search engines also offer hybrid search.
- When is hybrid search useless?
- When queries are always exact codes (keywords alone are enough) or always free questions on a small corpus (meaning alone may be enough).