# Hybrid Search

> The Hybrid Search is a search technique that combines keyword search with semantic search.

## What is hybrid search and why combine keyword and vector search?

The technique that merges results of classic keyword search, good for exact names and codes, with semantic search, good for meaning. Usually gives better retrieval quality than each method alone.

- Topic: Retrieval
- Type: technique

## Example

Wrong:

```js
const merged = [...keywordHits, ...vectorHits]
  .sort((a, b) => b.score - a.score);
```

Right:

```js
const scores = new Map();
for (const hits of [keywordHits, vectorHits]) {
  hits.forEach((hit, rank) => {
    scores.set(hit.id, (scores.get(hit.id) ?? 0) + 1 / (60 + rank + 1));
  });
}
const merged = [...scores].sort((a, b) => b[1] - a[1]);
```

Reciprocal rank fusion merges by rank, so keyword and vector scores on different scales do not distort the order.

## Common mistakes

- Adding raw keyword and vector scores that use different scales.

## Key points

- Scores from keyword and vector search are merged with a method like rank fusion, not added raw.
- Both searches apply the same filters and access rules.

## Interview questions

### What is reciprocal rank fusion?

A way to merge ranked lists by adding '1 / (k + rank)' for each list a result appears in, with 'k' often set to 60. It uses ranks, not raw scores.

### When is hybrid search better than vector search alone?

When queries mix meaning with exact terms like names, IDs, error codes or rare words.

### Do I need two databases for hybrid search?

Not necessarily. Many search engines and databases support full-text and vector search in one index.

## Related cards

- [Semantic Search](https://wonderium.dev/ai/semantic-search.md)
- [Reranking](https://wonderium.dev/ai/reranking.md)
- [RAG](https://wonderium.dev/ai/rag.md)
- [Vector Database](https://wonderium.dev/ai/vector-database.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/hybrid-search
- Last updated: 2026-11-25
