{"slug": "bm25-vs-semantic-search-vs-hybrid-rag-what-my-benchmarks-revealed", "title": "BM25 vs Semantic Search vs Hybrid RAG: What My Benchmarks Revealed", "summary": "A developer building an open-source codebase RAG system called AI Codebase Intelligence benchmarked four retrieval methods and found that equal-weight hybrid RRF underperformed semantic search alone, scoring an MRR@5 of 0.692 versus 0.854. Adding cross-encoder reranking after RRF recovered the gap, reaching a Hit@5 of 1.000 and MRR@5 of 0.875, slightly above semantic search. The developer cautioned that the evaluation set was small and measured retrieval quality only, not end-to-end answer accuracy or latency.", "body_md": "I built a codebase RAG system using BM25, semantic search, reciprocal rank fusion (RRF), and cross-encoder reranking.\n\nI expected hybrid search to outperform semantic search alone.\n\n**It didn't.**\n\nOn my evaluation set, semantic search achieved an MRR@5 of 0.854, while hybrid RRF dropped to 0.692.\n\nAdding cross-encoder reranking changed the result.\n\nHere's what I tested and what I learned.\n\nSearching a codebase isn't the same as searching ordinary text.\n\nA developer might ask:\n\nWhere does the application check whether a user is logged in?\n\nBut the relevant implementation could be a function named `decode_access_token`.\n\nBM25 can find exact identifiers. Semantic search can match questions to code with different wording.\n\nI wanted to see whether combining both approaches would improve retrieval quality.\n\nMy project, **AI Codebase Intelligence**, indexes software repositories and lets developers ask questions about their code.\n\nThe system uses:\n\nThe retrieval pipeline looks like this:\n\n```\nQuestion\n   |\n   v\nBM25 + Semantic Search\n   |\n   v\nReciprocal Rank Fusion\n   |\n   v\nCross-Encoder Reranking\n   |\n   v\nRelevant Code Chunks\n   |\n   v\nLocal LLM\n   |\n   v\nAnswer + Source Citations\n```\n\nI created a small ground-truth evaluation set and compared four retrieval methods.\n\nI measured:\n\n**Hit@5:** Whether at least one relevant result appears in the top five.\n\n**MRR@5:** How highly the first relevant result ranks within the top five, averaged across queries.\n\nHere are the results:\n\n| Retrieval Method | Hit@5 | MRR@5 | \n|---|---|---|\n| BM25 | 0.750 | 0.500 | \n| Semantic Search | 1.000 | 0.854 | \n| Hybrid RRF | 0.875 | 0.692 | \n| RRF + Reranking | **1.000** | **0.875** | \n\nThese results come from my project's evaluation set, not a standardized public benchmark.\n\n**Hybrid RRF performed worse than semantic search alone.**\n\nCombining BM25 and semantic search actually reduced both Hit@5 and MRR@5 in this experiment.\n\nThe initial hybrid implementation used equal-weight RRF.\n\nOne possible explanation is that combining the ranked lists pushed some relevant semantic results lower. However, I haven't isolated the exact cause.\n\nThe important point is that adding another retrieval component did not automatically improve the results.\n\nI added a cross-encoder reranker after RRF.\n\nInstead of relying only on the original retrieval rankings, the cross-encoder evaluates the query and each candidate together to produce a new ordering.\n\nThe result:\n\nCompared with semantic search alone, the final pipeline achieved the same Hit@5 and a slightly higher MRR@5.\n\nThat improvement gave me a measurable reason to keep the reranking stage.\n\nThe project also includes the engineering needed to make the retrieval system usable.\n\nRepository indexing runs asynchronously using Celery and Redis.\n\nRepeated RAG responses can be cached in Redis.\n\nGenerated answers include source file and line-range citations, making it easier to verify the retrieved evidence.\n\nI also added read-only MCP tools for searching code, retrieving files, listing symbols, and asking questions about a repository.\n\nThis was a small evaluation, so the results shouldn't be treated as universal.\n\nDifferent datasets, repositories, embedding models, fusion parameters, and rerankers may produce different outcomes.\n\nI also measured retrieval quality, not end-to-end answer accuracy or latency.\n\nThose would be important next steps.\n\nThe biggest lesson from this project wasn't that hybrid RAG is better or worse than semantic search.\n\nIt was that **retrieval quality needs to be measured instead of assumed**.\n\nMy first hybrid implementation added complexity while reducing performance.\n\nCross-encoder reranking improved the results, but the benefit only became clear after running the evaluation.\n\nA more complicated RAG architecture isn't automatically a better one.\n\n**Read the full technical article, including the architecture and implementation details:**\n\n[BM25 vs Semantic Search vs Hybrid RAG: What My Benchmarks Revealed](https://borjan.ladinski.com/articles/bm25-semantic-hybrid-rag-benchmarks/)\n\nI'm Borjan Ladinski, an AI Engineer and AI Consultant based in Skopje, North Macedonia. I work on AI agents, LLM applications, RAG, machine learning, and business automation.", "url": "https://wpnews.pro/news/bm25-vs-semantic-search-vs-hybrid-rag-what-my-benchmarks-revealed", "canonical_source": "https://dev.to/borjanladinski/bm25-vs-semantic-search-vs-hybrid-rag-what-my-benchmarks-revealed-2klk", "published_at": "2026-11-27 22:09:47+00:00", "updated_at": "2026-11-27 22:14:15.004317+00:00", "lang": "en", "topics": ["ai-tools", "large-language-models", "ai-agents"], "entities": ["AI Codebase Intelligence", "BM25", "Reciprocal Rank Fusion", "Celery", "Redis", "MCP"], "also_reported_by": [], "takeaway": "On the developer's codebase eval set, equal-weight hybrid RRF scored MRR@5 0.692 versus 0.854 for semantic search alone, and adding cross-encoder reranking lifted the pipeline to 0.875.", "recommendation": {"advice": "Benchmark hybrid retrieval against semantic-only on your own eval set before shipping it, and add cross-encoder reranking after RRF to recover ranking quality.", "playbook": "rag-retrieval", "playbook_url": "https://wpnews.pro/playbooks/rag-retrieval"}, "alternates": {"html": "https://wpnews.pro/news/bm25-vs-semantic-search-vs-hybrid-rag-what-my-benchmarks-revealed", "markdown": "https://wpnews.pro/news/bm25-vs-semantic-search-vs-hybrid-rag-what-my-benchmarks-revealed.md", "text": "https://wpnews.pro/news/bm25-vs-semantic-search-vs-hybrid-rag-what-my-benchmarks-revealed.txt", "jsonld": "https://wpnews.pro/news/bm25-vs-semantic-search-vs-hybrid-rag-what-my-benchmarks-revealed.jsonld"}}