AI / LlamaIndex Interview Questions
How do you design a hybrid search system combining vector and keyword retrieval in LlamaIndex?
Pure vector similarity search is excellent at capturing semantic meaning but can miss exact matches on rare terms, product codes, names, or acronyms that a keyword search would catch immediately, since an embedding might not weight an exact token match heavily. Hybrid search combines both so neither weakness dominates.
In LlamaIndex, this typically means running a dense retriever, such as a VectorIndexRetriever, alongside a sparse retriever like BM25Retriever, and merging their results with a fusion retriever such as QueryFusionRetriever. The fusion step can either take a weighted combination of scores or use reciprocal rank fusion to merge the two ranked lists into one, and it can optionally issue several query variations to each retriever for broader coverage before merging.
from llama_index.retrievers.bm25 import BM25Retriever from llama_index.core.retrievers import QueryFusionRetriever vector_retriever = index.as_retriever(similarity_top_k=10) bm25_retriever = BM25Retriever.from_defaults(docstore=index.docstore, similarity_top_k=10) fusion_retriever = QueryFusionRetriever( [vector_retriever, bm25_retriever], similarity_top_k=8, mode="reciprocal_rerank" )
The resulting fused retriever is then used like any other retriever inside a query engine, and it's often paired with a final reranker for an additional precision boost on the merged candidate set.
More Related questions...