AI engineering glossary · RAG vector search

What is hybrid search?

Hybrid search: Combining keyword-based and vector-based retrieval and merging their results into a single ranked list. Keyword search catches exact terms and identifiers, while vector search catches paraphrases, so the mix usually beats either alone.

Level: intermediateTopic: RAG vector search

Hybrid search: an example

A query 'iPhone 15 battery drain' gets exact model matches from BM25 and related troubleshooting articles from embeddings.

Keyword search and vector search each rank documents; reciprocal rank fusion merges themKeyword (BM25)exact terms, IDs, codesVector searchmeaning, paraphrasesFusion (RRF)1 / (60 + rank)Rerankerbest few to the LLM
Hybrid search: two rankings, one list

Hybrid search in Python

A short example you can run (Python 3.11). The output below is what it really prints.

# Reciprocal rank fusion: merge a keyword ranking and a vector ranking
keyword = ["doc_gst", "doc_invoice", "doc_refund"]
vector = ["doc_invoice", "doc_tax", "doc_gst"]

def rrf(*rankings, k=60):
    scores = {}
    for ranking in rankings:
        for rank, doc in enumerate(ranking, start=1):
            scores[doc] = scores.get(doc, 0) + 1 / (k + rank)
    return sorted(scores.items(), key=lambda x: -x[1])

for doc, s in rrf(keyword, vector):
    print(f"{doc:12s} {s:.4f}")

Output

doc_invoice  0.0325
doc_gst      0.0323
doc_tax      0.0161
doc_refund   0.0159

Related terms

More RAG vector search terms

Where you learn it

Hybrid search is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.