Sub topic 9
Hybrid retrieval: combining both signals
This chapter assumes you have read the two previous chapters, on lexical retrieval (matching the words) and semantic retrieval (matching the meaning). You should know that a lexical search scores documents by shared terms and that a semantic search compares embeddings, which are lists of numbers that represent meaning. No programming is required, but one short Python sketch is included.
Why one signal is not enough
Each retrieval method has a blind spot that the other one covers.
- Lexical retrieval is precise about exact strings. It finds a product code, a person's name, a legal term or a rare phrase. It misses a page that explains the same idea in different words.
- Semantic retrieval is good at paraphrase. A search for "shoes for collapsed arches" can reach a passage about "flat feet". It can be vague about exact details, so it may return a passage about a similar model number instead of the one asked for.
Hybrid retrieval runs both and combines the results. The technique is documented and widely available. Search platforms such as Elasticsearch, OpenSearch, Azure AI Search and Vespa describe hybrid search in their documentation. Which AI search products use it, and how, is mostly not published. Treat "AI search is hybrid" as a reasonable working assumption, not a confirmed fact about any one product.
What each signal rewards
| Situation | Lexical signal | Semantic signal |
|---|---|---|
| Query uses an exact model name, "ZX-4500" | Strong match | May confuse with similar names |
| Query uses everyday words, page uses technical ones | Weak match | Strong match |
| Query contains a rare, specific term | Strong match, because rare terms carry weight | Rare terms may be blurred in the embedding |
| Query is a long natural-language question | Many words, few useful matches | Captures the overall intent |
| Page repeats a keyword many times without saying much | Can score well, though most scoring methods limit the benefit | Little extra credit |
The two signals fail in different places. That is the reason for combining them, because an item that scores well on both is rarely a mistake.
How the two lists are combined
A hybrid system usually retrieves a list of candidates from a keyword index and another from a vector index. It then merges them. Two merging approaches are common.
- Score blending. Each list's scores are rescaled to the same range, then added with weights. Rescaling is needed because a keyword score such as 12.0 and a cosine similarity such as 0.41 are not on comparable scales.
- Rank-based merging. The merge ignores the raw scores and uses only each item's position in each list. Reciprocal rank fusion is the usual example. The chapter on merging results covers it.
Hybrid retrieval happens once per search. With query fan-out, it runs separately for each sub-query. The fusion across sub-queries is a second merge on top of this one.
A worked sketch of score blending
The code below does not use a real search engine. It takes made-up lexical and semantic scores for three pages and blends them. The weight alpha decides how much the keyword signal counts.
def min_max(scores):
"""Rescale scores to the range 0 to 1."""
low, high = min(scores.values()), max(scores.values())
if high == low:
return {doc: 0.0 for doc in scores}
return {doc: (s - low) / (high - low) for doc, s in scores.items()}
def hybrid_scores(lexical, semantic, alpha=0.5):
"""Blend two score dictionaries. alpha is the weight of the lexical signal."""
lex = min_max(lexical)
sem = min_max(semantic)
docs = set(lex) | set(sem)
return {
doc: alpha * lex.get(doc, 0.0) + (1 - alpha) * sem.get(doc, 0.0)
for doc in docs
}
lexical = {"page_a": 12.0, "page_b": 7.5, "page_c": 2.0} # keyword-style scores
semantic = {"page_a": 0.41, "page_b": 0.82, "page_c": 0.78} # cosine similarities
for alpha in (0.5, 0.9):
blended = hybrid_scores(lexical, semantic, alpha)
ranking = sorted(blended, key=blended.get, reverse=True)
print(alpha, ranking)Running it prints:
0.5 ['page_b', 'page_a', 'page_c']
0.9 ['page_a', 'page_b', 'page_c']Read the result carefully.
page_arepeats the query's words, so it wins on the keyword signal but is weak on meaning.page_bis decent on both signals, so it wins when the weights are balanced.- When the keyword signal dominates (
alpha=0.9),page_amoves back to first place.
The ranking changes because of a tuning choice, not because the pages changed. Real systems tune this balance, and you cannot see their settings.
Edge cases and failure modes
Different scales. If scores are blended without rescaling, the signal with the larger numbers dominates. A common implementation mistake is a keyword score in the tens swamping a similarity score below 1.
A document found by only one signal. In the sketch, a missing score counts as 0. Systems differ in how they handle this. Some give such an item a low default, and some drop it.
Min-max sensitivity. Rescaling uses the lowest and highest score in the list. A single extreme outlier can squash everything else toward one end. Rank-based merging avoids this, but it throws away how large the score gaps were.
Candidate depth. Each index returns only its top N results. A page ranked 60th by keywords and 70th by meaning may never reach the merge, even though a blend would have placed it high. This is one reason strong performance on a single signal is safer than moderate performance on both.
Query type changes the best weighting. A query full of codes and names favours the keyword side. A vague, conversational query favours the semantic side. Some systems adjust weights per query. Whether a given AI product does this is unknown.
Embedding model differences. Different products use different embedding models, which are the models that turn text into vectors. The same page can look closer to a query in one system than in another.
What this means for your content
You cannot tune the weights, but you can make a page perform well on both signals. The reasoning follows from the table above.
- Use the exact terms people search for. Product names, model numbers, standards, place names and defined terms should appear as written, ideally in the passage that talks about them. This serves the lexical signal.
- Also explain the idea in plain language. A passage that says what the term means, in the words a customer would use, serves the semantic signal. A page that only repeats a technical term will miss paraphrased queries.
- Keep both in the same passage. Retrieval works on passages, not whole pages. A page that mentions "stability shoes" in a heading and explains overpronation three screens later splits the two signals across different chunks. The chapter on passages and chunking covers this.
- Do not repeat keywords to inflate a score. Keyword scoring methods typically give diminishing returns for repetition, and the semantic signal gains nothing from it. Repetition makes the passage worse to read.
- Define synonyms once. A sentence such as "flat feet, also called fallen arches" gives the keyword side both phrases and gives the semantic side a clear link between them.
Exercise
A page about "Model ZX-4500 treadmill" ranks well when users search the exact model number, but it never appears for the question "which home treadmill is quiet enough for an apartment?" Using what you know about the two signals, give one likely cause and one content change.
Show answer
The page probably wins on the lexical signal (the exact model name) and is weak on the semantic signal for the question, because no passage talks about noise or apartment use in plain language. Add a passage that states, in everyday words, how loud the treadmill is, for example the motor type, a decibel figure if you have one, and its suitability for apartments, and keep the model name in the same passage so both signals point to it.
Exercise
In the code sketch, why does page_a rank first when alpha is 0.9 but second when alpha is 0.5?
Show answer
page_a has the highest keyword score but the lowest semantic score. A high alpha gives the keyword signal most of the weight, so page_a wins. At 0.5 the strong semantic score of page_b outweighs the keyword advantage of page_a.