<- all tokdocs

BM25: The Search Algorithm That Still Powers Production Systems Without Any AI

Watch on TikTok

View on TikTok ->

Vector search is not always the answer. BM25 is a ranking algorithm that requires zero training, zero embeddings, and zero GPUs. It still powers Elasticsearch, OpenSearch, and most production search systems today. Understanding when and why to use it is essential for building effective RAG systems.

How BM25 Works

BM25 ranks documents using three simple ideas. No neural networks, no training data, just math.

Title card showing "Understanding BM25 Algorithm" with topics including search engines, information retrieval, and TF-IDF

Rare words matter more. Every document contains common words like "system" or "error." Those carry almost no signal. But a specific term like "8407" is highly distinctive. BM25 automatically gives rare, specific terms much higher weight.

Diagram showing "Rare Words Matter More" with common words like system, error, file contrasted against the specific term 8407, which carries stronger ranking weight

Repetition helps, but only to a point. If "invoice" appears multiple times in a document, that is a relevance signal. But repeating it 100 times does not make the document 100 times more relevant. BM25 has built-in saturation that prevents keyword stuffing from gaming the ranking.

Diagram showing "Repetition Helps, But Only to a Point" with a saturation curve illustrating diminishing returns from keyword repetition

Document length is normalized. A 40-page manual will naturally contain more keyword hits than a 2-page troubleshooting guide. BM25 adjusts for that so longer documents do not dominate results simply because they are longer.

Where BM25 Beats Vector Search

BM25 is extremely strong at exact matching. If someone searches "invoice error code 8407," vector search might return documents about similar invoice issues. BM25 will surface the document that contains "8407" exactly.

Side-by-side comparison: Vector Search returns "Similar invoice issues" like billing code 8000 series, while BM25 returns an exact match for error code 8407

This is why hybrid search is now the default in serious RAG systems. BM25 handles precision and exact matching. Vector search handles semantic meaning and conceptual similarity. Together, they provide both accuracy and understanding.

Key Takeaways

  • BM25 uses three principles: rare term weighting, repetition saturation, and length normalization
  • It requires no training, no embeddings, and no GPUs, yet still powers most production search
  • BM25 excels at exact matching where vector search returns only approximate results
  • Hybrid search (BM25 + vector) is the current standard for production RAG systems

Resources

  • Elasticsearch -- Search engine that uses BM25 as its default ranking algorithm
  • OpenSearch -- Open-source search and analytics suite built on BM25

Published May 25, 2026. Writeup generated from a favorited TikTok.