Explore topic-wise interview questions and answers.
Hybrid Search
QUESTION 01
What is hybrid search and why is it used in RAG systems?
๐ DEFINITION:
Hybrid search combines multiple retrieval methods, typically dense vector search (semantic) and sparse keyword search (lexical), to leverage their complementary strengths. Vector search finds semantically similar content even with different wording, while keyword search excels at exact matches for proper nouns, IDs, and domain terminology. Together, they provide more robust and comprehensive retrieval than either alone.
โ๏ธ HOW IT WORKS:
Hybrid search executes two (or more) retrievers in parallel: 1) Dense retriever - embeds query and finds nearest vectors using ANN search, capturing semantic meaning. 2) Sparse retriever - uses BM25 or TF-IDF to find exact keyword matches, important for precision. Results from both are combined using fusion algorithms like Reciprocal Rank Fusion (RRF) or weighted linear combination. The merged result set benefits from both semantic understanding and lexical precision, with documents that match both methods ranked highest.
๐ก WHY IT MATTERS:
Pure vector search can miss documents that use different terminology but are relevant - it may fail on proper names, product codes, or domain jargon. Pure keyword search misses synonyms and conceptual matches. In production RAG, both failures are problematic. Hybrid search provides the best of both: recall from semantic, precision from keyword. Studies show 5-15% improvement over single-method retrieval. It's particularly valuable for domains with both conceptual content and precise terminology (medical, legal, technical).
๐ EXAMPLE:
Query: 'iPhone 13 battery replacement cost'. Vector search finds documents about 'iPhone 13 battery service price' (semantic match). Keyword search finds documents with exact 'battery replacement cost'. Hybrid combines: documents containing both 'iPhone 13' and cost-related terms with semantic relevance to 'battery replacement' get highest rank. Result includes official Apple pricing page (keyword match) and third-party repair guides (semantic match). Without hybrid, might miss official pricing (vector-only) or miss repair guides (keyword-only).
QUESTION 02
What is BM25 and how does it rank documents?
๐ DEFINITION:
BM25 (Best Matching 25) is a ranking function used in information retrieval to score documents based on query term frequency, with saturation and document length normalization. It's the modern standard for keyword search, improving upon TF-IDF by handling term saturation (diminishing returns for multiple occurrences) and document length normalization.
โ๏ธ HOW IT WORKS:
BM25 score for document D given query Q with terms q1...qn is: score(D,Q) = ฮฃ IDF(qi) ร (f(qi,D) ร (k1+1)) / (f(qi,D) + k1 ร (1 - b + b ร |D|/avgdl)). Components: IDF(qi) - inverse document frequency (rarer terms more important). f(qi,D) - term frequency in document (saturated by k1, typically 1.2-2.0). |D|/avgdl - document length relative to average (normalized by b, typically 0.75). Saturation prevents a term appearing 100 times from being 100x more important than appearing once. Length normalization prevents long documents from scoring higher just because they have more words.
๐ก WHY IT MATTERS:
BM25 remains essential despite neural advances. It's interpretable, requires no training, works instantly on any corpus, and excels at exact matching for proper nouns, codes, and terminology. It's also computationally efficient, running on inverted indexes in milliseconds. In hybrid search, BM25 provides the lexical precision that vector search lacks. For domains with specialized terminology, BM25 often outperforms pure vector search on precision.
๐ EXAMPLE:
Query: 'Find documents about COVID-19 vaccine efficacy'. BM25 scores documents with many occurrences of 'COVID-19', 'vaccine', 'efficacy' highly, but saturates so 10 mentions isn't 10x better than 5. Normalizes for length so a short abstract mentioning terms isn't penalized vs a long paper. Document with 'COVID-19' in title and 'efficacy' in abstract scores well. Document mentioning 'SARS-CoV-2 immunization effectiveness' (synonyms) scores poorly - that's where vector search helps. BM25 captures exact matches, vector captures synonyms, together they're comprehensive.
QUESTION 03
What is the difference between sparse retrieval (BM25/TF-IDF) and dense retrieval (vector search)?
๐ DEFINITION:
Sparse retrieval (BM25, TF-IDF) represents documents as high-dimensional sparse vectors where each dimension corresponds to a vocabulary term and values reflect term importance. Dense retrieval uses neural networks to compress documents into low-dimensional dense vectors capturing semantic meaning. They represent fundamentally different approaches to information retrieval.
โ๏ธ HOW IT WORKS:
Sparse retrieval: Build inverted index mapping terms to documents. At query time, compute scores based on term overlap, term frequency, and document statistics. No training required, interpretable, fast on CPU. Handles exact matches perfectly but misses synonyms and conceptual relationships. Dense retrieval: Train or use pre-trained embedding model to convert text to vectors. Build ANN index for fast similarity search. Captures semantics - 'car' and 'automobile' are close in vector space. Requires training/compute, less interpretable, but finds conceptually related content.
๐ก WHY IT MATTERS:
Each has complementary strengths. Sparse is irreplaceable for: proper names ('iPhone 15'), IDs ('INV-2024-001'), domain terminology ('myocardial infarction'), and when precision on exact terms is critical. Dense excels at: conceptual queries ('ways to improve customer satisfaction'), synonyms, and when query and document use different vocabulary. Neither alone is sufficient for production RAG - hybrid combines them. Understanding the difference guides when to emphasize each: for product search, sparse critical for SKUs; for research, dense critical for concepts.
๐ EXAMPLE:
Query: 'treatment for hypertension'. Sparse retrieval finds documents with 'treatment' and 'hypertension'. Dense retrieval also finds documents with 'therapy for high blood pressure' (semantic match). For query: 'Find bug #12345 in JIRA', sparse essential - dense would fail on exact ID. For query: 'How to improve team morale', dense finds articles about 'employee engagement', 'workplace happiness' that sparse would miss. Both needed for comprehensive search.
QUESTION 04
What is Reciprocal Rank Fusion (RRF) and how does it combine results from multiple retrievers?
๐ DEFINITION:
Reciprocal Rank Fusion (RRF) is a method for combining multiple ranked result lists from different retrieval systems into a single ranking. It uses the rank positions, not scores, making it robust to different scoring scales across methods. RRF gives higher weight to documents that appear consistently highly ranked across systems.
โ๏ธ HOW IT WORKS:
For each document d, RRF computes a combined score: score(d) = ฮฃ 1/(k + rank_r(d)) where rank_r(d) is the rank of document d in the result list from retriever r (or infinity if not present), and k is a constant (typically 60). Documents not retrieved by a system get rank โ, contributing 0 from that system. Documents appearing in multiple lists with good ranks accumulate higher scores. The constant k reduces the impact of high rankings - the difference between rank 1 and 2 is 1/(1+60) - 1/(2+60) โ 0.016, while between 100 and 101 is negligible. After computing scores for all documents, they're sorted for final ranking.
๐ก WHY IT MATTERS:
RRF elegantly solves the problem of combining scores from different systems (vector similarity, BM25) that may have incomparable scales. It doesn't require normalization or tuning across systems. It's simple, effective, and widely adopted. RRF tends to boost documents that multiple methods agree on, reducing noise from any single method. Studies show RRF often outperforms weighted linear combination, especially when system performances vary.
๐ EXAMPLE:
Vector search returns: [docA, docB, docC] ranks 1,2,3. BM25 returns: [docB, docD, docA] ranks 1,2,3. With k=60, RRF scores: docA: 1/(1+60) + 1/(3+60) = 0.0164 + 0.0159 = 0.0323. docB: 1/(2+60) + 1/(1+60) = 0.0161 + 0.0164 = 0.0325. docC: 1/(3+60) = 0.0159. docD: 1/(2+60) = 0.0161. Final order: docB, docA, docD, docC. DocB ranked highly by both systems wins, docC only in one loses despite higher vector rank. This consensus-based ranking improves overall precision.
QUESTION 05
When does keyword search outperform semantic search?
๐ DEFINITION:
Keyword search (BM25) outperforms semantic search in scenarios requiring exact term matching, handling rare or specialized terminology, and when precision on specific identifiers is critical. Despite semantic advances, certain query types remain best served by traditional lexical matching.
โ๏ธ HOW IT WORKS:
Scenarios where keyword excels: 1) Proper names and entities - 'iPhone 15 Pro Max', 'Dr. Sarah Johnson'. Semantic may retrieve similar names but miss exact. 2) IDs and codes - 'INV-2024-001', 'CPT 99213'. Dense embeddings of IDs are meaningless. 3) Domain terminology where exactness matters - 'myocardial infarction' vs 'heart attack' (clinically different). 4) Rare words - embeddings poorly trained for rare terms. 5) Queries with multiple required terms - 'must include X and Y'. Keyword can enforce AND logic. 6) Precision-critical applications - legal, medical where retrieving wrong document unacceptable.
๐ก WHY IT MATTERS:
Understanding when keyword outperforms prevents over-reliance on semantic search. In production, these scenarios are common: product search, customer support (ticket IDs), medical coding, legal citation lookup. A RAG system using only semantic search would fail on these, frustrating users. Hybrid search addresses this by keeping keyword as a component. The key insight: semantic and lexical are complementary, not competitive.
๐ EXAMPLE:
User searches 'Find bug REPORT-1234 in JIRA'. Semantic search embeds query and retrieves documents about 'bug reports' generally, maybe documents mentioning '1234' in different contexts - useless. Keyword search finds exact 'REPORT-1234' instantly. Another: doctor searches 'CPT code 99213 for established patient office visit'. Semantic might retrieve documents about office visits but not the specific code. Keyword finds exact code documentation. In both cases, keyword essential, semantic insufficient.
QUESTION 06
When does semantic search outperform keyword search?
๐ DEFINITION:
Semantic search (dense retrieval) outperforms keyword search when queries and documents use different vocabulary to express the same concepts, when understanding meaning matters more than exact words, and for exploratory or conceptual queries where users don't know the exact terminology.
โ๏ธ HOW IT WORKS:
Scenarios where semantic excels: 1) Synonym handling - 'automobile' vs 'car', 'joyful' vs 'happy'. Keyword misses if terms don't match exactly. 2) Conceptual queries - 'ways to improve customer satisfaction' matches 'enhancing user experience' semantically. 3) Cross-lingual search - query in English finds documents in Spanish with same meaning. 4) Queries with no term overlap - 'how to fix leaking faucet' matches 'repair dripping tap' (zero word overlap but same meaning). 5) Natural language questions - 'What causes migraines?' matches documents about 'headache etiology'. 6) User misspellings - semantic embeddings can be robust to typos.
๐ก WHY IT MATTERS:
Users often don't know the exact terminology in documents. They describe concepts in their own words. Semantic search bridges this lexical gap, finding relevant content keyword search would miss entirely. For knowledge bases, research papers, and general information seeking, semantic is essential. The improvement in recall (finding relevant documents) can be 20-40% over keyword for conceptual queries.
๐ EXAMPLE:
User searches company knowledge base: 'How do I get reimbursed for travel expenses?' Keyword search looks for 'reimbursed', 'travel', 'expenses'. Might find documents with those words, but misses document titled 'Employee Expense Policy' which contains 'business trip compensation' - zero term overlap. Semantic search matches concept, retrieves the policy document. User finds answer. Another: 'ways to reduce stress' matches articles about 'anxiety management techniques', 'relaxation methods', 'mindfulness practices' - all conceptually related, lexically different. Semantic makes this possible.
QUESTION 07
How do you implement hybrid search in Elasticsearch or OpenSearch?
๐ DEFINITION:
Implementing hybrid search in Elasticsearch/OpenSearch combines dense vector search (via the dense_vector field type) with traditional BM25 keyword search, merging results using reciprocal rank fusion or score combination. These engines provide native support for both retrieval methods, enabling hybrid search without external components.
โ๏ธ HOW IT WORKS:
Steps: 1) Index mapping - define fields: text for keyword search, dense_vector for embeddings (with dimension and similarity metric). 2) Ingestion - store both raw text and pre-computed embeddings. 3) Query execution - run two sub-queries in parallel: match query for BM25 on text field, knn query for vector search on embedding field. 4) Fusion - use search API with rank parameter (Elasticsearch 8.8+) to combine results via RRF, or manually merge results client-side. 5) Optional - add boosting to weight one method more. 6) Filtering - apply metadata filters to both sub-queries. Performance considerations: vector search requires appropriate index configurations (HNSW) and may need separate vector-optimized nodes.
๐ก WHY IT MATTERS:
Elasticsearch/OpenSearch are already widely deployed for log analytics and search. Adding vector search capabilities turns them into unified platforms for hybrid search, avoiding separate vector database infrastructure. This simplifies architecture, reduces operational overhead, and enables combining structured filters, keyword, and vector search in one query. For organizations already using Elastic, it's the natural choice for hybrid RAG.
๐ EXAMPLE:
Product search with Elasticsearch: GET /products/_search with query: { "query": { "match": { "description": "wireless headphones" } }, "knn": { "field": "embedding", "query_vector": [...], "k": 10 }, "rank": { "rrf": { "window_size": 100 } } }. Returns products that match keywords 'wireless headphones' AND/OR are semantically similar. BM25 finds exact matches, vector finds conceptually similar products with different descriptions. Combined results give users comprehensive options.
QUESTION 08
How do you implement hybrid search with a vector database like Weaviate or Qdrant?
๐ DEFINITION:
Modern vector databases like Weaviate and Qdrant have built-in hybrid search capabilities that combine vector similarity with BM25-style keyword search, handling fusion internally. This provides a unified API for hybrid retrieval without managing separate systems or manual result merging.
โ๏ธ HOW IT WORKS:
Implementation steps: 1) Schema definition - define collections with both vectorizer configuration and text fields for keyword search. 2) Ingestion - store documents with text and vectors (or let database generate vectors via integrated modules). 3) Hybrid query - use hybrid search parameter specifying query text, vector (or auto-embed), and fusion parameters (alpha for linear combination, or RRF). 4) Database executes both searches internally, applies fusion, returns combined results. Weaviate uses bm25 and nearText combined with hybrid search type. Qdrant uses query with prefetch for multiple retrievers and rrf fusion. Both support adjusting weights between methods.
๐ก WHY IT MATTERS:
Native hybrid search simplifies development - no custom fusion code, no managing two result sets, no double latency from separate calls. The database optimizes execution, possibly parallelizing retrievers. This reduces complexity and ensures consistent performance. For teams using vector databases as their primary store, native hybrid is the most straightforward path to combining lexical and semantic search.
What is SPLADE and how does it create learned sparse representations?
๐ DEFINITION:
SPLADE (Sparse Lexical and Expansion) is a learned sparse retrieval model that generates high-dimensional sparse vectors where dimensions correspond to vocabulary terms, but values are learned via neural networks. Unlike BM25's term frequency-based scores, SPLADE learns to expand queries with related terms and weight them optimally, combining the interpretability of sparse retrieval with neural learning.
โ๏ธ HOW IT WORKS:
SPLADE uses a BERT-based encoder to process text and outputs logits over the vocabulary for each token. These logits are aggregated (via max or sum pooling) to produce a sparse vector where non-zero entries represent terms from both the original text and semantically related terms the model learns to activate. For example, query 'car' might activate 'automobile', 'vehicle', 'auto'. During training, it optimizes for retrieval metrics using contrastive learning, with a regularization term encouraging sparsity (few non-zero entries). The resulting sparse vectors can be indexed with standard inverted indexes, enabling efficient retrieval with neural-quality expansion.
๐ก WHY IT MATTERS:
SPLADE bridges the gap between sparse and dense retrieval. It offers: interpretability (you can see which terms matched), efficiency (inverted indexes), and strong performance often matching or exceeding dense retrievers. It's particularly effective for domains where explainability matters (legal, medical) and for handling out-of-vocabulary terms via expansion. SPLADE models consistently rank high on BEIR benchmarks, proving learned sparsity can compete with dense.
๐ EXAMPLE:
Query 'How to treat hypertension?' SPLADE expands to terms: 'treat', 'treatment', 'therapy', 'hypertension', 'high blood pressure', 'antihypertensive', 'medication'. Document about 'managing high blood pressure with medication' matches via 'high blood pressure' and 'medication' even though not in original query. Inverted index with SPLADE vectors finds this document efficiently. BM25 would miss without exact 'hypertension' term. Dense would find but can't explain why. SPLADE provides neural-quality retrieval with sparse interpretability.
QUESTION 10
What are the latency trade-offs of running two retrieval systems in parallel?
๐ DEFINITION:
Running two retrieval systems in parallel for hybrid search adds latency from the slower system, plus fusion overhead. The overall latency is determined by the maximum of the two retrievers (since they run in parallel) plus a small fusion step. Understanding these trade-offs is crucial for meeting latency SLAs while benefiting from hybrid.
โ๏ธ HOW IT WORKS:
In parallel execution, both retrievers start simultaneously. Total latency = max( latency_vector, latency_keyword ) + fusion_time. Vector search latency depends on index type (HNSW faster, IVF slower), dimensionality, and dataset size (typically 10-100ms). Keyword search latency depends on inverted index size and query complexity (typically 5-50ms). Fusion adds minimal overhead (1-5ms). The slower system determines overall latency. If vector takes 80ms, keyword 20ms, total ~85ms. If both 50ms, total ~55ms. Caching can reduce latency for frequent queries. Some systems optimize by running retrievers sequentially with early termination if first system highly confident.
๐ก WHY IT MATTERS:
Hybrid search adds latency compared to single-method retrieval. For applications with strict latency requirements (<100ms), this matters. If vector search is already near limit, adding keyword may not increase latency (if faster). If keyword is slow due to complex parsing, it could become bottleneck. Understanding trade-offs helps choose configurations: tune vector index for speed (HNSW with smaller efSearch), optimize keyword indexes, consider caching. For ultra-low latency, may need to accept slightly lower recall from single method or use approximate fusion.
๐ EXAMPLE:
RAG system with 200ms latency budget. Vector search 60ms, keyword 40ms, fusion 5ms = 65ms total - well within budget. After scaling to 100M documents, vector search increases to 120ms (HNSW slower). Now total 125ms - exceeds budget. Options: tune vector index (reduce efSearch, accept slight recall drop) to 90ms โ 95ms total. Or move vector to faster hardware. Without understanding trade-offs, might incorrectly blame keyword or fusion. Latency analysis guides optimization.
QUESTION 11
How do you tune the weighting between sparse and dense results in hybrid search?
๐ DEFINITION:
Tuning the weighting between sparse (keyword) and dense (vector) results determines how much each method influences the final ranking. The optimal balance depends on query types, domain characteristics, and performance metrics. Weighting can be static (fixed per system) or dynamic (adjusted per query based on query properties).
โ๏ธ HOW IT WORKS:
Approaches: 1) Linear combination - score = ฮฑ * vector_score + (1-ฮฑ) * keyword_score. Need normalized scores (e.g., 0-1). ฮฑ tuned on validation set. 2) Reciprocal Rank Fusion (RRF) - automatically weights by rank, with k parameter influencing balance (smaller k gives more weight to top ranks). 3) Dynamic weighting - classify query (e.g., entity-heavy vs concept-heavy) and adjust weights accordingly. 4) Learning to rank - train model to combine features from both systems. Tuning process: create validation set with relevance judgments, grid search ฮฑ or k, measure nDCG or recall, select optimal. Optimal ฮฑ often 0.3-0.7 depending on domain.
๐ก WHY IT MATTERS:
Wrong weighting degrades performance. Too much vector weight: misses exact matches for IDs, codes. Too much keyword: misses conceptual matches. Optimal balance varies by domain: e-commerce product search (many IDs) may need higher keyword weight (ฮฑ=0.3). Research paper search (conceptual) may need higher vector weight (ฮฑ=0.7). Tuning on your data ensures best performance. Dynamic weighting can further improve by adapting to query type - entity queries use more keyword, exploratory more vector.
๐ EXAMPLE:
Legal document search tuning. Validation set of 1000 queries with relevance judgments. Test ฮฑ=0.2,0.3,0.4,0.5,0.6,0.7. Results: ฮฑ=0.4 gives best nDCG@10 (0.82). ฮฑ=0.2 (more keyword) scores 0.79 (misses conceptual matches). ฮฑ=0.6 (more vector) scores 0.80 (misses case citations). Optimal balance captures both. For queries with citation IDs, dynamic weighting could increase keyword weight further, improving overall. Tuning turns hybrid from good to great.
QUESTION 12
What is the role of re-ranking after hybrid retrieval?
๐ DEFINITION:
Re-ranking after hybrid retrieval applies a more accurate (but slower) model to refine the ranking of candidates produced by hybrid search. While hybrid combines sparse and dense for broad retrieval, re-ranking uses cross-encoders or other deep interaction models to precisely order the top candidates, improving precision at the top of the results.
โ๏ธ HOW IT WORKS:
Two-stage process: Stage 1 (retrieval): hybrid search (vector + keyword) retrieves N candidates (typically 100-200) efficiently. Stage 2 (reranking): for each candidate, compute more accurate relevance score using cross-encoder (query+document processed together) or late interaction model (ColBERT). This is O(N) with N small, feasible. Reranker can capture fine-grained interactions missed by bi-encoders. Top M (10-20) after reranking used for generation or final results. Reranking can also use ensemble of multiple models or query-specific features.
๐ก WHY IT MATTERS:
Hybrid retrieval improves recall but may still rank marginally relevant documents above highly relevant ones. Reranking corrects this, ensuring the most relevant documents are at the top. This is critical for RAG where top-k context determines answer quality. Studies show reranking after hybrid improves precision@k by 5-15%. The additional latency (50-200ms) is usually worth it for high-stakes applications. Reranking also enables using different relevance criteria (freshness, authority) at final stage.
๐ EXAMPLE:
Product search: hybrid retrieves 200 candidates. At position 5: product with exact keyword match but old model (less relevant). At position 15: newer model with semantic match but lower initial rank. Cross-encoder reranker correctly scores newer model higher, moves to position 2. Generation now uses best product info. Without reranking, might recommend outdated product. Reranking after hybrid combines broad recall with precise ranking.
QUESTION 13
How does hybrid search handle domain-specific terminology (e.g., medical or legal jargon)?
๐ DEFINITION:
Hybrid search handles domain terminology particularly well because sparse and dense methods complement each other: keyword search excels at exact jargon terms (which are often rare and precisely defined), while semantic search handles conceptual relationships between terms. This synergy is especially valuable in specialized domains like medicine and law.
โ๏ธ HOW IT WORKS:
For domain terminology, keyword search (BM25) is essential because: 1) Jargon terms are often rare, so embeddings may be poorly trained. 2) Exactness matters - 'myocardial infarction' and 'heart attack' are clinically different. 3) Codes (ICD-10, CPT) have no semantic meaning. Vector search complements by: 1) Finding documents that explain terms in plain language. 2) Connecting related concepts ('hypertension' to 'antihypertensive medications'). 3) Handling user queries that use lay terms instead of jargon. Hybrid combines both: keyword ensures precision on exact terms, vector ensures recall on conceptual matches.
๐ก WHY IT MATTERS:
In specialized domains, retrieval failures have serious consequences. Medical search missing a contraindication could harm patients. Legal search missing a precedent could lose cases. Hybrid provides the robustness needed: it won't miss exact code lookups (keyword) and won't miss conceptual connections (vector). The combination ensures both precision and recall where both matter.
๐ EXAMPLE:
Medical query: 'Treatment for HTN with CKD'. Keyword finds documents with exact 'HTN' and 'CKD' (hypertension, chronic kidney disease). Vector finds documents about 'managing high blood pressure in patients with kidney disease' (lay explanation). Hybrid retrieves both. A clinician gets precise clinical guidelines (keyword match) and patient education materials (vector match). Another query: 'CPT code 99213' - keyword essential, vector useless. Hybrid adapts, still retrieves via keyword. Domain-specific hybrid is more than sum of parts.
QUESTION 14
What is the difference between pre-filtering and post-filtering in hybrid search?
๐ DEFINITION:
Pre-filtering applies metadata filters before retrieval, limiting search to only documents matching filter criteria. Post-filtering retrieves documents first, then applies filters to the result set. The choice affects performance, especially in hybrid search where multiple retrievers are involved.
โ๏ธ HOW IT WORKS:
Pre-filtering: during query, metadata filters are applied to both sparse and dense indexes before search. Vector search only considers vectors in filtered subset; keyword search only considers documents matching filter. This ensures all results satisfy filters but may miss relevant documents if filter too restrictive. Post-filtering: retrieve N documents from both methods ignoring filters, then remove those not matching filters. Simpler but may waste compute retrieving documents later filtered out, and may have fewer than N results after filtering if many filtered out.
๐ก WHY IT MATTERS:
Choice significantly impacts latency and result quality. Pre-filtering is efficient when filters are highly selective (e.g., 'year=2024' selects 10% of data) because search works on smaller set. But if filters are applied to vector index, pre-filtering may require specialized index support (filtered HNSW) which can be slower. Post-filtering is simpler and always works, but may retrieve many irrelevant documents, wasting compute and potentially reducing result count if filters selective. In hybrid search, need consistent approach across both retrievers.
๐ EXAMPLE:
E-commerce with filter 'category = electronics' (30% of products). Pre-filtering: vector search only on electronics (smaller index) โ faster, all results relevant. Post-filtering: search all products (3x larger), retrieve 100, then filter - may get only 30 electronics, less than desired. Conversely, filter 'price > $1000' (5% of products) pre-filtering may be inefficient due to index limitations, post-filtering may retrieve 100, keep only 5 - too few. Optimal choice depends on filter selectivity and index capabilities.
QUESTION 15
How do you evaluate the effectiveness of hybrid search vs. dense-only or sparse-only?
๐ DEFINITION:
Evaluating hybrid search requires comparing its retrieval quality against both dense-only and sparse-only baselines using standard IR metrics on a representative test set. The evaluation must capture whether hybrid truly combines strengths or just adds complexity without benefit.
โ๏ธ HOW IT WORKS:
Process: 1) Create test set of queries with relevance judgments (binary or graded). 2) Run three retrieval systems: sparse-only (BM25), dense-only (vector), hybrid (combined). 3) For each system, retrieve ranked lists for each query. 4) Compute metrics: recall@k (proportion of relevant documents in top-k), precision@k, nDCG@k (graded relevance), MRR (first relevant rank). 5) Compare across systems, ideally with statistical significance testing. 6) Analyze per query category: where does hybrid help most? (entity queries, conceptual queries). 7) Measure latency and resource usage trade-offs. Hybrid should improve recall without sacrificing precision.
๐ก WHY IT MATTERS:
Hybrid adds complexity and potentially latency. Evaluation quantifies whether benefits justify costs. Often hybrid improves recall by 5-15% with minimal precision loss. But sometimes one method dominates - if domain is mostly conceptual, dense may suffice. Evaluation reveals this. It also guides tuning: if hybrid recall gain is from rare queries, maybe acceptable; if from frequent queries, critical. Without evaluation, you're guessing.
๐ EXAMPLE:
Medical search evaluation on 500 queries. Results: dense-only recall@10 0.78, sparse-only 0.72, hybrid 0.84 (+6% over dense, +12% over sparse). Precision@10: dense 0.81, sparse 0.79, hybrid 0.83. Hybrid wins on both. Category breakdown: entity queries (drug names, codes): sparse 0.85, dense 0.60, hybrid 0.86. Conceptual queries: dense 0.82, sparse 0.58, hybrid 0.83. Hybrid matches best of both in each category. This justifies hybrid deployment. Without evaluation, might incorrectly choose dense-only and fail on entity queries.
QUESTION 16
What is ColBERT and how does it implement late interaction for efficient retrieval?
๐ DEFINITION:
ColBERT (Contextualized Late Interaction over BERT) is a retrieval model that combines the efficiency of bi-encoders with the accuracy of cross-encoders through late interaction. It encodes queries and documents into bags of token embeddings, then uses a lightweight 'MaxSim' operator to score relevance by matching query tokens against document tokens, preserving fine-grained interaction while enabling pre-computation.
โ๏ธ HOW IT WORKS:
ColBERT processes query through BERT to produce set of query embeddings Q = [q1,...,qm]. Documents are pre-processed similarly to produce document embeddings D = [d1,...,dn] (stored in index). At query time, relevance score = ฮฃ_i max_j (qi ยท dj) - for each query token, find maximum similarity with any document token, sum across query tokens. This captures matches like query 'machine learning' matching 'learning' in document even if 'machine' absent. Late interaction is more accurate than single-vector (bi-encoder) because it preserves token-level matching, yet efficient because document embeddings are pre-computed and MaxSim is fast (mรn comparisons, m small). ColBERTv2 adds compression and residual representations for scalability.
๐ก WHY IT MATTERS:
ColBERT achieves state-of-the-art retrieval quality, often rivaling cross-encoders, while being 100x faster and enabling pre-computation. It's particularly effective for queries with multiple concepts where token-level matching matters. In hybrid search, ColBERT can serve as the dense component or as a reranker. Its interpretability (you can see which tokens matched) adds value for debugging.
๐ EXAMPLE:
Query 'presidential election results 2020'. ColBERT matches 'presidential', 'election', 'results', '2020' separately against document. Document '2020 US Presidential Election Outcome' matches all four strongly. Document '2020 Election Results by State' also matches. Document 'Presidential History' matches 'presidential' only, scores lower. This token-level matching captures multi-concept queries better than single-vector compression. MaxSum finds best matches per token, ensuring all concepts considered.
QUESTION 17
How do you handle multilingual hybrid search?
๐ DEFINITION:
Multilingual hybrid search combines keyword and semantic retrieval across multiple languages, enabling queries in one language to find relevant documents in others. This requires multilingual embeddings for dense retrieval and multilingual analyzers for keyword search, plus strategies for cross-language result fusion.
โ๏ธ HOW IT WORKS:
For dense retrieval, use multilingual embedding models (LaBSE, multilingual E5, mBERT) that map texts from different languages into shared vector space. Queries in any language find semantically similar documents in any language. For keyword search, use language-specific analyzers (stemmers, tokenizers) for each document language. Index may have separate keyword fields per language or unified field with multi-language analysis. Fusion: results from both methods combined via RRF or weighted combination. Challenges: balancing across languages (some may have better coverage), handling queries mixing languages, and ensuring keyword search works for each language.
๐ก WHY IT MATTERS:
Global organizations have documents in multiple languages. Users expect to search in their preferred language and find relevant content regardless of source language. Multilingual hybrid makes this possible: dense provides cross-lingual semantic matching, keyword provides precision for language-specific terminology. Without hybrid, cross-lingual dense may miss exact matches; keyword alone fails cross-lingually.
๐ EXAMPLE:
Multinational company with documents in English, Spanish, Japanese. User searches in Japanese: 'ๆฐ่ฃฝๅใฎ็บๅฃฒๆฅ' (new product release date). Dense retrieval finds English documents about 'product launch timeline' and Spanish 'fecha de lanzamiento del producto'. Keyword search finds Japanese documents with exact terms. Hybrid combines: Japanese documents with exact terms (from keyword) rank high; English/Spanish relevant docs (from dense) also appear. User gets comprehensive results across languages. Without hybrid, might only get Japanese exact matches (keyword-only) or miss Japanese docs entirely (dense-only if query not in training).
QUESTION 18
What infrastructure considerations are there when scaling hybrid search?
๐ DEFINITION:
Scaling hybrid search requires infrastructure that can support both dense (vector) and sparse (inverted) indexes at scale, with considerations for hardware, memory, latency, and cost. The dual nature of hybrid adds complexity beyond single-method systems.
โ๏ธ HOW IT WORKS:
Key infrastructure considerations: 1) Hardware - vector search benefits from GPUs or fast SSDs for ANN; keyword search runs efficiently on CPU with enough RAM for inverted indexes. Hybrid may need both or separate clusters. 2) Memory - dense indexes (HNSW graphs) can be memory-hungry; sparse indexes also need RAM for fast access. Total memory = vector index + inverted index + overhead. 3) Indexing pipeline - need to generate both embeddings and keyword tokens, potentially doubling processing time. 4) Query processing - parallel execution of two searches may require coordinating across clusters. 5) Caching - cache both vector and keyword results, or fused results. 6) Monitoring - need metrics for both systems and fusion. 7) Scaling strategy - scale components independently based on bottlenecks.
๐ก WHY IT MATTERS:
Underestimating infrastructure needs leads to performance degradation or unexpected costs. At billion-scale, hybrid can require terabytes of RAM and significant compute. Planning for hybrid means provisioning for both retrieval methods, not just one. Understanding bottlenecks helps: if vector search is bottleneck, add GPU nodes; if keyword, optimize indexes. Without planning, hybrid may become too slow or expensive.
๐ EXAMPLE:
500M document hybrid search. Vector: 768-dim vectors = 1.5TB, HNSW index adds 0.5TB = 2TB RAM. Keyword: inverted index 0.5TB. Total 2.5TB RAM. With 128GB nodes, need ~20 nodes. Query: vector 50ms, keyword 30ms, fusion 5ms = 55ms. If vector on GPU nodes (faster but expensive), keyword on CPU nodes (cheaper). Design: separate clusters for vector and keyword, coordinate via orchestrator. This architecture scales to 1B documents. Without planning, might try single cluster and fail.
QUESTION 19
How would you present the case for hybrid search to a product team?
๐ DEFINITION:
Presenting hybrid search to product teams requires translating technical benefits into user and business outcomes: improved search quality, better user satisfaction, reduced failed searches, and ultimately higher conversion or engagement. The case must address both the 'what' and the 'why' in business terms.
โ๏ธ HOW IT WORKS:
Key talking points: 1) User problems solved: 'Users often can't find what they're looking for because they use different words than our documents. Hybrid fixes this by understanding both exact terms and concepts.' 2) Quantified improvement: 'Our tests show hybrid improves search success rate by 15%, meaning 15% fewer frustrated users.' 3) Business impact: 'Better search leads to higher conversion, lower support costs, increased user retention.' 4) Competitive advantage: 'Competitors may still use basic search; hybrid sets us apart.' 5) Implementation effort: 'We can implement with existing stack (Elastic) or minimal new infrastructure.' 6) Risks and mitigations: 'Slight latency increase, but within acceptable range.'
๐ก WHY IT MATTERS:
Product teams care about user outcomes, not technical elegance. Framing hybrid in terms of user frustration, search success rates, and business metrics gets buy-in. A/B test results showing concrete improvements are most convincing. Without product alignment, technical initiatives may be deprioritized.
๐ EXAMPLE:
Presentation to e-commerce product team: 'Currently, 8% of searches return no results. Analysis shows half of these are users using different words than our product descriptions - e.g., searching 'trainers' when we say 'sneakers'. Hybrid search would understand these are the same. Our prototype shows 40% reduction in zero-result searches. That's 3.2% more searches finding products, estimated to increase conversion by 1.5% and revenue by $2M annually. Implementation takes 2 months with our current Elastic stack.' This resonates. Without business framing, would sound like technical debt.
QUESTION 20
What are the maintenance challenges of running a hybrid retrieval system in production?
๐ DEFINITION:
Maintaining a hybrid retrieval system involves ongoing challenges across both sparse and dense components: keeping indexes synchronized, monitoring two systems, tuning parameters as data evolves, and debugging failures that could originate in either method. These operational complexities require systematic approaches.
โ๏ธ HOW IT WORKS:
Key challenges: 1) Index synchronization - when documents update, need to update both vector and keyword indexes consistently. Failure leads to inconsistency. 2) Monitoring - need separate metrics for each retriever (latency, recall) plus fusion, increasing observability complexity. 3) Tuning - optimal weighting (ฮฑ in hybrid) may drift as data changes; requires periodic re-evaluation. 4) Debugging - a bad result could be due to vector failure (poor embedding), keyword failure (missing term), or fusion (wrong weighting). Need to isolate. 5) Upgrades - updating embedding model requires re-indexing all vectors (expensive); updating keyword analyzer may need re-indexing. 6) Cost management - two systems mean two sets of infrastructure costs; need to monitor efficiency.
๐ก WHY IT MATTERS:
Hybrid adds operational complexity. Without processes, maintenance becomes burdensome, and system quality may degrade silently. Automated monitoring, regular retuning, and clear debugging procedures are essential. The benefits (improved search) must outweigh maintenance costs. For some teams, simpler single-method may be preferable if hybrid gains modest.
๐ EXAMPLE:
E-commerce hybrid search team has monthly maintenance: check sync status (vector vs keyword counts), run golden dataset evaluation to detect drift (if recall drops 2%, investigate), review latency metrics (if vector slower, maybe index needs rebuild). When upgrading embedding model, plan 1-week migration with dual indexes. Debugging failed query: check if relevant documents exist (corpus issue), if vector found them (embedding problem), if keyword found them (analyzer problem). This systematic maintenance keeps quality high but requires dedicated engineering time.