Hybrid retrieval

When Semantic Search Misses an Exact Match

Use exact identifier fields, BM25 and dense retrieval together, with a worked example of reciprocal rank fusion.

A related result can still be the wrong part

Take a search for “connector AX-450-B07”. The catalogue also contains AX-450-B70, AX-450-C07 and a family installation guide. In an embedding-only search the family guide can rank highly because its wording is close to the query, and the two near-identical codes share much of their surrounding text. That is a plausible ranking for someone browsing the product family. A technician asking for a specific connector needs the exact record or a clear indication that the requested code could not be found within their access.

Dense semantic retrieval compares learned representations. It can match “stops when it overheats” to a guide on a “thermal shutdown event” even when the two phrases share few words. Some models do learn useful signals for product names, short codes and numbers. A high similarity, however, is not a guarantee that a particular identifier or constant matched exactly. One flipped digit, decimal place, unit, or hardware revision can change the result that matters to a user. Design a path that checks those constraints explicitly.

Make identifiers searchable as identifiers

Suppose you index AX-450-B07 in a normal text field. An analyser may lowercase it, split on hyphens and index the pieces separately. Then AX-450-B70 can match several of the same pieces. A lexical search score for the result still need not certify equality. Add a separate product-ID field whose canonical value represents the business identifier. Use exact equality there when the user supplies a full, recognised ID. Keep the original display value for the result and for downstream actions.

Agree on valid normalisation with the catalogue owner. You may safely trim surrounding whitespace or support a known case-insensitive alias. Removing leading zeros or punctuation is a business decision. If AX-05 and AX-5 refer to different parts, a normaliser that rewrites both into the same string corrupts the lookup. Numeric constants need the same care. An operating limit with units and a tolerable range belongs in structured data if your index supports range queries. A match for “40” inside “140” is no proof that a part meets a stated 40 A limit.

Apply identity and document filters before revealing matches. Two suppliers or tenants may use the same code. When multiple authorised records fit, a short clarification around revision, site or supplier is preferable to picking one by embedding similarity.

What BM25 actually ranks

BM25(q, d) = Σₜ∈q IDF(t) × weight(t, d) weight(t, d) = f(t, d) × (k₁ + 1) / [f(t, d) + k₁ × (1 − b + b × |d| / avgdl)] IDF(t) = ln(1 + (N − n(t) + 0.5) / (n(t) + 0.5))

BM25 is a family of lexical ranking formulas built around query term matches. Rare query terms in the indexed corpus generally contribute more than ubiquitous terms. Repeated matches help with diminishing returns, and document-length normalisation reduces the advantage of long texts with many opportunities to match. A common scoring form sums an inverse document frequency term multiplied by a term-frequency factor for each query term. The k1 parameter influences term-frequency saturation. The b parameter controls the degree of length normalisation. Exact formula details vary across implementations.

For “B07 thermal trip”, terms shared by many documents, such as “thermal”, contribute differently from a rare code token such as “b07”. If the catalogue record includes B07 repeatedly, that alone will not make the score increase without bound. A concise passage directly on the problem can rank ahead of a long installation guide. This behaviour depends on field analysis and index statistics. If B07 is split or transformed unexpectedly, inspect the actual indexed tokens before tuning k1 or b.

BM25 matches what the index considers terms. It can use an analyser that performs stemming, normalisation or synonym expansion, but the formula itself does not infer that “switches itself off” and “trips” mean the same thing. It also does not enforce phrase order or a structured equality constraint on its own. Use the search engine's query operators when phrase matching or exact values are required.

In this common positive-IDF form, f(t, d) counts term occurrences in the document, |d| is document length and avgdl is average document length. N counts indexed documents and n(t) counts documents that contain the term. The formula assumes one scored field and omits optional query weights. Some implementations omit constant score factors or calculate length statistics differently.

For a single term appearing in 10 of 1,000 documents, IDF is about 4.56. If the term occurs twice in a 200-token document and average length is 100 tokens, k₁ = 1.2 and b = 0.75 give a term weight of about 1.07. The resulting contribution is about 4.89 in this form of the equation.

Build parallel paths around intent

A useful pipeline keeps the original question and any verified identifiers. It may also construct a standalone semantic query using conversation context. For “Does that model trip at low voltage?”, carry the resolved model ID into a structured filter if the user is asking about that exact unit. The lexical query can keep terms such as the code and “low voltage”, while the semantic branch searches for passages about comparable symptoms. Both branches must use the same access, version and corpus rules for this user.

For hard constraints, decide how to behave when no exact result exists. A search for an explicitly supplied ID can return “I could not find an approved record for AX-450-B07. Can you check the last two digits?” Related records can be presented as suggestions if the interface clearly labels them. Do not let a suggestion feed a downstream order as though it were the requested identifier. For exploratory queries with no hard constraints, run both branches and combine the candidates on relevance.

The two branches can also surface different representations of the same evidence. If BM25 returns a passage and vector search returns an overlapping child from the same version, map them to comparable identifiers or merge their source spans. Keep document-revision distinctions that affect applicability. A merge that drops revision B because revision C shares a title hides exactly the distinction hybrid search was meant to recover.

Hybrid retrieval workflow. Apply the same access scope to both branches and enforce any verified identifier filter before scoring. Fuse the eligible result lists, then pass distinct evidence to the reranker.

Compute a fusion score you can inspect

RRF(d) = Σᵢ 1 / (k + rankᵢ(d))

BM25 and vector similarity have different score scales. Adding the raw numbers often gives one branch disproportionate influence. Reciprocal rank fusion, or RRF, uses positions instead. Here d is a document, i is a result list, and rank starts at 1. A list contributes zero when it does not contain d. With k set to 60, a first-place result contributes 1/61. Treat the rank constant as a design parameter to evaluate. It is distinct from how many candidates you retrieve from each branch.

In this illustrative query, the lexical branch ranks the exact record A first, an obsolete bulletin C second and the service guide B third. The semantic branch ranks B first, A second and a troubleshooting note D third. A receives 1/61 plus 1/62, about 0.03252. B receives 1/63 plus 1/61, about 0.03227. C receives only 1/62, about 0.01613. D receives only 1/63, about 0.01587. Fusion ranks A then B, with the single-list results behind them. If C was obsolete and therefore out of scope, ideally it would have been excluded before both ranking stages.

Now move A to rank 15 in the semantic branch while keeping B first in that branch and third in lexical. A falls behind B under ordinary RRF. That is acceptable if both are candidates for an exploratory search. For an exact product-ID query, use a trusted exact constraint or preserve the verified record in the final candidate pool by design. Rank fusion is an ordering method, and agreement between two rankers does not turn an incorrect identifier into a correct one.

Worked RRF example with k = 60
CandidateBM25 rankVector rankRRF score
A · Exact record120.03252
B · Service guide310.03227
C · Obsolete bulletin2Absent0.01613
D · Troubleshooting noteAbsent30.01587

Use candidates, reranking and failure handling deliberately

Retrieve enough from each branch for fusion to see the difference. A branch limited to three candidates cannot introduce the right passage at rank four. On the other hand, fetching hundreds of overlapping chunks can consume resources without improving the final evidence set. Log the candidate counts, contribution from each branch and which source spans survive deduplication. Introduce reranking after you understand whether either branch already recovers the applicable passages.

If one search backend times out, define the degraded behaviour. A paraphrase search may still produce useful semantic candidates when the lexical backend is unavailable. Exact lookup and eligibility checks should respect their stricter guarantees. If the authorised lookup service cannot establish the ID, report the lookup as incomplete. Measure degraded paths in integration tests and inspect whether any fallback runs with broader access or different version filters. An improvement in average recall is of little use if one branch can return a restricted record.

Deduplication rules need to follow the units you are searching. A catalogue document and its symptom bulletin are different evidence. Two chunks that differ only by a small overlap can be collapsed for packing. Two revisions of the same bulletin can also share text, yet the current version may be the only valid one. Use a real version relation or validity rule before collapsing those records.

Evaluate lexical, semantic and hybrid against the same labels

Build separate query slices for full identifiers, paraphrased symptoms, questions with a hard constraint and ambiguous follow-ups. Include cases with adjacent IDs and punctuation variants. In each case, label the record or passage, the relevant version and whether the actor can see it. Test the actual analyzers and filters, and include an unanswerable case such as a retired identifier with no authorised replacement.

Compare lexical-only, vector-only and the fused setup using the same source snapshot and candidate budget. Measure exact-ID success and count wrong-ID substitutions in the answerable slice. For symptom queries, use passage hit rate or graded ranking. For questions that need both an inventory record and a procedure, check whether both appear. Watch p95 latency and query timeouts for each branch. In the final answer, check that the cited passage actually satisfies the identifier or numeric constraint.

BEIR provides a broader comparison of lexical and neural retrieval across tasks and treats BM25 as a robust baseline. Dense Passage Retrieval shows what encoding queries and passages can do for open-domain question answering. Neither benchmark proves a winner on your product catalogue. Use them to inform experimental design, then run your own labelled cases before picking a retrieval path.

Analyse the query before changing the ranking weights

To diagnose an exact lookup miss, use a test index and inspect which tokens were actually written for the relevant document and which tokens the query sends. For AX-450-B07, compare the tokens on the descriptive text field with the stored canonical key. Include a copy-pasted query with a different dash character. If your business rules treat that character as equivalent, normalise it deliberately and test both inputs. If the lexical branch missed because the key was never indexed, increasing its fusion weight will change the order of the wrong candidates.

When discussing a reported number, also check whether it was a literal part of the query or a requested threshold. A search for the phrase “24 V relay” can benefit from lexical and semantic hits. A query asking for parts rated at least 24 V should evaluate a structured field and unit. The same text can represent two different functions.

Make the result easy to explain

For the example query, record why the final system returned A. If it was an exact lookup, show the canonical ID and applicable revision. If the technician asked for guidance, cite the service guide and say which device constraint was used to select it. If the lookup failed, ask for the missing information. Showing the distinction in the result also gives you an audit trail when a user questions a match.

A phased implementation can start with exact identifier fields and a BM25 baseline, then add semantic candidates for intents where wording differs from documentation. Introduce fusion with visible branch diagnostics. Test whether reranking further helps on difficult cases. Do the evaluation on your operational data distribution rather than on a list of clean queries with unique answers. The comparison is useful when it reveals which path found the evidence and what the assistant did when the evidence disagreed.

More in the retrieval engineering series

Contact Cortex IR