AI

    Hybrid Search in RAG: Combining Semantic and Keyword Search

    Neither pure semantic search nor keyword search is optimal for RAG. Hybrid search combines both approaches for retrieval quality that exceeds either method alone.

    VE
    8 min read
    Share

    Key Takeaways

    • Hybrid search improves recall by 10-25% over semantic-only search by capturing both meaning-based and term-based matches.
    • Reciprocal Rank Fusion (RRF) is the simplest and most effective method for combining semantic and keyword results without complex tuning.
    • Factual queries benefit from keyword weight, while conceptual queries benefit from semantic weight. Dynamic weighting based on query type maximizes quality.
    • Weaviate, Qdrant, and Elasticsearch support native hybrid search, eliminating the need to manage separate search systems.
    • Sparse embeddings (SPLADE) represent a newer approach that captures keyword importance as vectors, enabling hybrid-like behavior in a single vector space.

    Why Hybrid Search Outperforms Either Approach Alone

    Query TypeSemantic Search AloneKeyword Search AloneHybrid Search
    "Q4 2024 revenue"May miss exact term matchFinds exact matchFinds both exact and related
    "How to improve customer satisfaction"Understands intent wellMisses synonymsBest of both approaches
    "Error code ERR-4521"Poor (no semantic meaning)Perfect exact matchKeyword component captures it
    "employee onboarding process"Finds related conceptsMisses 'new hire orientation'Captures both terms and concepts
    "John Smith contract renewal"May confuse namesMatches name preciselyPrecise name + related context
    When Keyword Search Wins

    Semantic search struggles with proper nouns, product codes, error codes, version numbers, and other identifiers that have no inherent semantic meaning. For knowledge bases containing technical content with specific codes and identifiers, hybrid search is essential, not optional.

    Implementation Approaches

    ApproachHow It WorksProsConsRecommended When
    Reciprocal Rank FusionScore by 1/(rank+k) from both lists, sumSimple, no tuning neededEqual weight to both signalsStarting point (recommended)
    Weighted linear combinationalpha*semantic + (1-alpha)*keyword scoresTunable balanceRequires score normalizationKnown query patterns
    Cross-encoder rerankingRerank merged results with cross-encoderHighest qualityAdds latency (100-300ms)Quality-critical applications
    Sparse-dense hybridSPLADE + dense vectors in one spaceSingle index, simpleNewer, less provenCutting-edge implementations
    Native database hybridWeaviate/Qdrant built-in fusionZero additional codeDatabase-specificAlready using these databases

    Reciprocal Rank Fusion (RRF) is the recommended starting point. It requires no score normalization, no tuning, and consistently outperforms pure semantic search. The formula scores each result as 1/(rank + k), where k is typically 60, then sums scores across both result lists.

    Weight Tuning and Dynamic Balancing

    Query CharacteristicSemantic WeightKeyword WeightReasoning
    Conceptual (how, why, explain)0.7-0.80.2-0.3Meaning matters more than terms
    Factual (what, when, who)0.5-0.60.4-0.5Need both meaning and specifics
    Identifier-based (codes, names)0.2-0.30.7-0.8Exact match is critical
    Short queries (1-3 words)0.4-0.50.5-0.6Limited semantic signal
    Long queries (10+ words)0.7-0.80.2-0.3Rich semantic context
    Dynamic Weighting

    Classify incoming queries (using a lightweight model or rules) and apply different weights accordingly. A query classifier that detects 'identifier' vs 'conceptual' queries can improve hybrid search quality by 5-10% compared to static weights.

    Implementation with Popular Databases

    • Weaviate: use the `hybrid` search operator with `alpha` parameter (0 = pure keyword, 1 = pure vector). Default alpha of 0.75 works well. No additional setup required beyond standard Weaviate configuration.
    • Qdrant: use sparse vectors (BM25 or SPLADE) alongside dense vectors in the same collection. Query with both and fuse results. Qdrant handles the scoring internally.
    • Pinecone + external BM25: Pinecone is vector-only. Run BM25 separately (Elasticsearch, OpenSearch) and implement RRF in your application code. Adds infrastructure but gives full control.
    • pgvector + PostgreSQL: combine pgvector similarity search with PostgreSQL's built-in full-text search (tsvector). Join results in a single SQL query for efficient hybrid search.
    • Elasticsearch 8.x: use kNN search alongside traditional BM25 in a single query. Elasticsearch handles both natively with configurable boosting.

    Frequently Asked Questions

    Need Help Implementing This?

    Our team can help you put these insights into practice.

    Schedule a Consultation