Mahamudul Hasan Rubel
HomeAboutProjectsSkillsExperienceBlogPhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • About
  • Projects
  • Skills
  • Experience
  • Blog
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
AI/MLJune 20, 20264 min read

Hybrid Search in RAG Pipelines: Boosting Retrieval Accuracy

Hybrid search in RAG pipelines combines vector and keyword matching to solve retrieval failures. Learn how to implement it for better search relevance.

RAGhybrid searchvector databasessemantic searchinformation retrievalLLM developmentAILLMPrompt Engineering
View of large industrial pipelines running through a lush forest landscape.

We’ve all been there: you spend three weeks building a sophisticated RAG pipeline, only to have it fail the first time a user types a specific product SKU or a niche technical term. It’s frustrating, but it’s the classic "semantic search trap." Dense embeddings are great at capturing intent, but they are notoriously bad at exact-match retrieval.

After building a small RAG pipeline end to end in Python, the next logical step in your engineering journey is acknowledging that vector search isn't a silver bullet. If you want production-grade accuracy, you need to stop relying on embeddings alone and start implementing hybrid search.

Why Vector Search Isn't Enough

Vector databases are excellent at understanding that "canine" and "dog" are semantically similar. However, they struggle with "out-of-vocabulary" terms or precise identifiers. If your user searches for "Error-502-AX," a pure vector search might return results about general server errors rather than the specific, documented issue.

Early in my current project, I relied solely on text-embedding-3-small from OpenAI. My recall on technical documentation was around 65%—too low for a production tool. I spent about two days trying to fine-tune embeddings, but the real issue wasn't the model's intelligence; it was the loss of lexical signal during the vectorization process.

The Hybrid Search Architecture

Close-up of a vintage typewriter with paper displaying 'Domain Search' text, ideal for retro themes.

Hybrid search solves this by combining two distinct retrieval methods:

  1. Dense Retrieval (Vector Search): Uses embeddings to capture conceptual meaning.
  2. Sparse Retrieval (Keyword Search): Uses BM25 or TF-IDF to capture exact string matches.

When you combine these, you get the best of both worlds. The keyword search handles the acronyms and SKUs, while the vector search handles the natural language queries.

Implementation Strategy

You don't need to rebuild your entire stack to add this. Most modern vector databases—like Pinecone, Weaviate, or Qdrant—now support native hybrid search. The core challenge is "Reciprocal Rank Fusion" (RRF). RRF is the algorithm that merges the ranked lists from your vector search and your keyword search into a single, high-relevance output.

Here is a simplified look at how you might structure this in Python using a hypothetical client:

PYTHON
# Conceptual implementation of hybrid search logic
def search(query, vector_db, keyword_index):
    # 1. Get vector embeddings
    vector_results = vector_db.query(query, top_k=10)
    
    # 2. Get BM25 results
    keyword_results = keyword_index.search(query, top_k=10)
    
    # 3. Merge using RRF
    # The formula usually looks like: score = 1 / (k + rank)
    combined_results = reciprocal_rank_fusion(vector_results, keyword_results)
    
    return combined_results[:5]

Practical Trade-offs and Latency

Before you jump in, remember that controlling LLM cost and latency: A practical production guide is crucial. Adding hybrid search introduces complexity. You are now querying two indices instead of one, and you have to normalize scores between two very different scoring systems.

I’ve found that the overhead is usually negligible—often adding only around 30-50ms to the total retrieval time. However, the operational complexity is real. You now have to manage two indexes for every document update. If you forget to update your BM25 index when a document changes, your search results will get stale, leading to hallucinations.

Lessons Learned from the Trenches

Close-up of a notebook with handwritten notes and drawings on a wooden desk.

One mistake I made early on was weighting the vector search too heavily in the fusion step. I wanted the "AI" to be smart, so I gave it an 80% weight. It turned out that for our specific dataset, a 50/50 split was significantly better. Don't be afraid to tune your weights based on your own evaluation metrics.

If you are currently struggling with retrieval relevance, stop trying to prompt-engineer your way out of it. Most of the time, the fix is at the retrieval layer. If you find your RAG system is still slow or expensive, you might also need to look at prompt patterns that survive contact with production to ensure the retrieved context is actually being used effectively by the LLM.

I’m still experimenting with learned sparse retrievers like SPLADE, which essentially bridge the gap between keyword and vector search by creating sparse, high-dimensional vectors. It’s promising, but I’m not sure it’s ready for every production use case yet. For now, a standard BM25 + Vector hybrid approach remains the most stable, predictable way to improve your RAG pipeline's relevance.

Back to Blog

Similar Posts

A detailed view of assorted coins in a jar under warm light, depicting financial wealth.
AI/MLJune 20, 20264 min read

LLM Caching Strategies to Slash Latency and API Costs

Master LLM caching strategies to cut latency and API costs. Learn how to implement exact and semantic caches to optimize your production AI workflows.

Read more
Detailed image of a modern industrial control panel featuring multiple connectors and buttons.
AI/ML
June 20, 2026
5 min read

LLM Guardrails for Production: Input Validation and Output Filtering

LLM guardrails are essential for production AI. Learn how to implement reliable input validation and output filtering to keep your LLM apps safe and secure.

Read more
Aerial view of a modern highway interchange at dusk with flowing traffic.
AI/MLJune 20, 20265 min read

LLM Routing: A Strategy for Multi-Model Architectures

Master LLM routing to optimize costs and latency in production. Learn how to build a deterministic multi-model architecture for your AI application.

Read more