TL;DR

Hybrid search blends keyword (sparse) and vector (dense) scores through a single alpha weight, which becomes a tunable hyperparameter of a RAG retriever.

Summary

Keyword search finds exact terms such as method names or error messages but misses synonyms; semantic search handles paraphrase but struggles with out-of-domain terms. Hybrid search scores both and combines them as (1 - alpha) * sparse + alpha * dense, where alpha = 0 is pure keyword and alpha = 1 is pure vector search. Because retrieved context is the only input the LLM sees, tuning alpha directly affects answer quality. Stack Overflow’s mix of natural-language questions and pasted errors is the motivating example.

Key takeaways

  1. Combine sparse and dense retrieval: sparse vectors (TF-IDF/BM25) capture exact keywords; dense vector embeddings capture meaning.
  2. Use a weighted score: hybrid_score = (1 - alpha) * sparse_score + alpha * dense_score, with alpha between 0 and 1.
  3. Treat alpha as a hyperparameter of the RAG pipeline and calibrate it per content type and query style.
  4. Swap the retriever, not the pipeline: in LangChain, replace vectorstore.as_retriever() with WeaviateHybridSearchRetriever(alpha=0.5, ...); the rest stays the same.
  5. Expect the biggest gains where queries mix prose and exact identifiers: search portals, e-commerce, support FAQs, legal and medical retrieval.

Tools and concepts

ItemRole in the page
RAGThe pipeline whose retriever is being improved
VDBDense side of the search (Weaviate used in the example)
ElasticsearchTypical home of the BM25 keyword side (not named in the page)
scikit-learn TfidfVectorizerUsed in the sparse-search code sample
LangChain WeaviateHybridSearchRetrieverReady-made hybrid retriever, alpha defaults to 0.5

When to use

  1. When deciding how to weight keyword vs semantic search in a RAG retriever.
  2. When explaining why pure vector search fails on exact identifiers or error messages.
  3. When wiring a hybrid retriever in LangChain with a single alpha knob.

Caveats

  • The “BM25” code sample actually uses TF-IDF, and the section on mixing “hybrid and vector” search is confusing; read it as a score blend.
  • No benchmark or recommended alpha value; the only evidence is the Stack Overflow narrative.
  • Score-weighted fusion needs comparable score scales; see the rank-based alternative in Better RAG results with Reciprocal Rank Fusion and Hybrid Search.

RAG LLM VDB Elasticsearch Better RAG results with Reciprocal Rank Fusion and Hybrid Search RAG-Fusion - a New Take on Retrieval-Augmented Generation Retrieval-Augmented Generation for Large Language Models - A Survey