Kayavak / Databases / DB·63 Search Engines and Hybrid Search / Deeper
Deeper · Databases
Search Engines and Hybrid Search
The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.
Why does this exist?
Libraries indexed books by subject long before computers, and information retrieval as a field (Gerard Salton's SMART system, from the 1960s) asked how to find the most relevant documents, not just the matching ones. The inverted index (a map from each word to the documents containing it) and weighting rare words above common ones (Karen Spärck Jones's inverse document frequency, 1972) became its foundations. Stephen Robertson and colleagues' BM25 (Okapi, mid-1990s) remains a strong ranking function today.
Doug Cutting wrote Lucene in 1999, the engine under Elasticsearch (2010), Solr and OpenSearch. Then embeddings changed the field: neural models map text to vectors where similar meanings lie close together, and approximate nearest-neighbour indexes such as HNSW (Malkov and Yashunin, 2016) search them quickly. Since meaning-based and keyword-based search fail in different ways, systems now combine them (hybrid search), often merging rankings with reciprocal rank fusion (Cormack and others, 2009).
The mental model
Try it yourself first: write your own model in the Mental Model Explorer, then compare.
Search is ranking, not matching. Text is analysed into terms or vectors, every candidate gets a relevance score, and quality is measured by whether the right results appear near the top, not whether every match is returned.
| Question | Answer |
|---|---|
| What is it? | Systems that retrieve and rank documents by relevance to a query |
| Problem it solves | Finding what people mean in large text collections, tolerating typos, synonyms and vague queries |
| Parts | Analysers (tokenise, normalise, stem), inverted indexes, BM25, embeddings and vector indexes, hybrid fusion, reranking, evaluation |
| How it works | Build indexes offline; at query time retrieve candidates fast, score them, optionally rerank the top with a heavier model |
| Assumptions | The index is kept in sync with the source data; relevance can be judged and measured |
| When they change | A stale index returns deleted or outdated documents; untested ranking changes make results worse unnoticed |
| Where it fails | Exact identifiers in pure vector search; meaning and paraphrase in pure keyword search |
| Related ideas | Indexes (ch58); retrieval for AI systems (Applied AI Systems); evaluation metrics |
What if?
What if you used only vector search for a product catalogue?
Reason it through, then open
Queries like "waterproof hiking boots" would work well, but exact searches like a part number "XR-2041B" might return similar-looking codes instead of the one product, because embeddings capture meaning, not exact strings. Keyword search gets exact identifiers right. Hybrid search runs both and fuses the rankings.
What if common words like "the" counted as much as rare ones?
Reason it through, then open
Documents would rank high for containing "the" many times, and a query's distinctive terms would be drowned out. Inverse document frequency weights a term by how rare it is across the collection: matching a rare word says much more about relevance than matching a common one.
Where the boundary is
| Aspect | Keyword (BM25) | Semantic (vectors) |
|---|---|---|
| Matches | The same terms (after analysis) | Similar meanings |
| Strong at | Names, codes, rare terms, exact phrases | Paraphrases, synonyms, natural-language questions |
| Explainable | Yes: which terms matched | Hardly |
| Cost | Cheap | Embedding every document and query; vector index memory |
How sure are we?
| Claim | How it's known | Where from |
|---|---|---|
| Inverse document frequency (1972) | Historical | Spärck Jones, A statistical interpretation of term specificity |
| BM25 is a strong baseline | Measured | Decades of TREC and BEIR benchmarks; neural models don't beat it on every dataset |
| Hybrid search often beats either alone | Measured | Many published evaluations; depends on data and queries |
Still open
How best to combine lexical, dense and learned sparse retrieval, and how to evaluate search without large labelled datasets (using AI models as judges, for instance), are active research questions.
What would change your mind? If your evaluation set showed vector search alone matching hybrid on identifier queries, you could drop the keyword index. Test with your real queries.
Recall
What does inverse document frequency do?
Weights terms by rarity, so distinctive words count more than common ones.
Why combine keyword and vector search?
They fail differently: keywords miss paraphrases, vectors miss exact identifiers.
What is an inverted index?
A map from each term to the documents (and positions) containing it.
How is search quality judged?
By whether relevant results appear near the top, using metrics such as nDCG on judged queries.
Reflect
Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.