Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hybrid RAG Search

Hybrid search combines dense (semantic) and sparse (keyword) retrieval for better search quality than either method alone.

Overview

MethodStrengthsWeaknesses
Dense (Semantic)Synonyms, meaning, paraphrasingRare terms, exact matches
Sparse (BM25)Exact terms, product codes, namesNo semantic understanding
HybridBest of bothSlightly more computation

How It Works

User Query
    │
    ├──────────────────┐
    ▼                  ▼
Dense Search      Sparse Search
(Weight: 0.7)     (Weight: 0.3)
    │                  │
    └────────┬─────────┘
             ▼
    Reciprocal Rank Fusion
             │
             ▼
    Optional Reranking
             │
             ▼
       Final Results

Reciprocal Rank Fusion (RRF):

RRF_score(d) = Σ 1 / (k + rank_i(d))

Configuration

In config.csv:

name,value
rag-hybrid-enabled,true
rag-dense-weight,0.7
rag-sparse-weight,0.3
rag-top-k,10
rag-rrf-k,60
rag-reranker-enabled,false

Weight Tuning

Content TypeDenseSparseUse Case
Balanced0.70.3General purpose
Semantic-Heavy0.90.1Conversational, multilingual
Keyword-Heavy0.40.6Technical docs, product catalogs
Equal0.50.5When unsure

Reranking

Optional LLM-based reranking for highest quality:

name,value
rag-reranker-enabled,true
rag-reranker-model,quality
rag-reranker-top-n,20
AspectWithoutWith Reranking
Latency~50ms~500ms
QualityGoodExcellent
CostNoneLLM API cost

Use for: Legal, medical, financial, compliance-critical queries.

Usage

Hybrid search is automatic when enabled. No code changes needed:

USE KB "company-policies"
' Queries automatically use hybrid search

Performance

MetricTarget
MRR (Mean Reciprocal Rank)> 0.7
Recall@10> 0.9
Latency P95< 200ms
Cache Hit Rate> 40%

Caching

name,value
rag-cache-enabled,true
rag-cache-ttl,3600
rag-cache-max-size,10000

Troubleshooting

IssueSolution
Poor resultsAdjust weights for content type
High latencyReduce rag-top-k, enable caching, disable reranking
Missing expected resultsCheck document indexed, verify no filters excluding it

See Also