tensorfolk

Hybrid search and reranking

Combine keyword search (BM25) with vector search, then rerank the merged candidates with a cross-encoder. This is the highest-leverage RAG upgrade.

Stable: this rarely changes. Reviewed 17 Oct 2026.

Key ideas

In code

python
def rrf(result_lists, k=60):
    scores = {}
    for results in result_lists:
        for rank, doc_id in enumerate(results):
            scores[doc_id] = scores.get(doc_id, 0) + 1 / (k + rank + 1)
    return sorted(scores, key=scores.get, reverse=True)

candidates = rrf([bm25_ids, vector_ids])[:50]
top = reranker.rank(query, candidates)[:8]

Common mistakes