BM
Bashar ModallalSOFTWARE · AI · SYSTEMS
← All field notes

AI

Hybrid Search: Combining Keywords and Meaning

Understand how hybrid search combines exact keyword matching and semantic retrieval, how reciprocal rank fusion works, and how to evaluate secure, useful results.

Keyword and semantic search paths converge into one ranked list of results.

Hybrid Search: Combining Keywords and Meaning

Estimated reading time: 9 minutes

Also available in Arabic.

A person may search for “connection reset after Node 22 upgrade” without knowing the exact title of the incident report. Another may enter an exact error code, customer number, or regulation clause. These queries look similar in a search box, but they reward different kinds of evidence. Keyword search is good at precise terms. Vector search is good at related meaning. Hybrid search runs both and combines their ranked results so a system can benefit from each.

This combination is useful for documentation search, product catalogs, support systems, and retrieval-augmented generation (RAG). It is not an automatic guarantee of relevance: the index, filters, chunking, candidate depth, and evaluation set still determine what a user sees.

Two retrieval paths, two kinds of evidence

Full-text search turns text into normalized terms and ranks documents using lexical signals. A term such as ECONNRESET can match precisely; analyzers may also normalize forms or ignore configured stop words. PostgreSQL, for example, exposes query parsers such as websearch_to_tsquery, and ranking functions that can consider lexical frequency, proximity, and structural weights. Its documentation also stresses that relevance is application-specific, so the built-in ranking functions are starting points rather than universal truth. PostgreSQL documents these query and ranking controls.

Vector retrieval represents a query and each indexed passage as numerical embeddings. It can retrieve text about “a socket being closed by the remote peer” for a user who writes “connection reset,” even if the phrasing differs. It can also miss exact identifiers, rare product names, dates, or version strings if the embedding model does not distinguish them well. A vector score is a similarity measure under a particular model and index configuration, not a calibrated probability that the passage answers the question.

Hybrid retrieval submits a lexical query and one or more vector queries against compatible index content, then merges the ranked lists. Azure AI Search describes this as parallel text and vector execution followed by Reciprocal Rank Fusion (RRF). Its hybrid-search overview also notes the complementary behavior: vectors can find conceptually related passages, while text search can be more precise for product codes, jargon, dates, and names.

flowchart LR
  Q["User query"] --> T["Text retrieval"]
  Q --> V["Vector retrieval"]
  T --> F["Rank fusion"]
  V --> F
  F --> R["Unified candidates"]
  R --> S["Optional reranking and policy checks"]
  S --> O["Cited answer or safe fallback"]

The diagram shows retrieval branches, not a guarantee that both return the same documents. The fusion stage combines their ranked evidence. A later reranker may consider richer query-document interactions, while policy checks can enforce permissions, freshness, and answer rules before a model uses the material.

Why combine ranked lists instead of raw scores?

Lexical and vector scores usually live on different scales. Adding a BM25 score to a cosine-derived score can let the larger numerical range dominate for arbitrary reasons. Rank fusion avoids directly comparing those raw values. It asks instead: where did this document appear in each candidate list?

A common RRF form is:

RRF(document) = Σ over result lists [ 1 / (k + rank(document)) ]

Here, rank is the document’s one-based position in a ranked list, and k is a smoothing constant. The RRF paper by Cormack, Clarke, and Buettcher introduced a simple rank-combination approach and evaluated it against other fusion methods; the SIGIR 2009 paper record is the primary reference. Azure’s implementation documentation describes summing reciprocal-rank contributions and distinguishes the fusion constant from the nearest-neighbor k parameter used to select vector candidates. Azure’s RRF guide explains that implementation.

The practical advantage is robustness when two retrieval systems produce scores that cannot be compared directly. The trade-off is that rank alone discards score gaps. A document just below the top position and one far below it contribute according to their positions, not the numeric distance between their underlying relevance scores. Fusion also cannot repair a missing passage, a broken permission filter, or poor chunk boundaries.

Worked example 1: an exact error code and a semantic description

Suppose the index contains three support passages:

Passage Text-search rank for “ECONNRESET Node 22” Vector rank for “connection reset after Node 22 upgrade”
A 1 30
B 7 3
C 20 2

For a small hand calculation, let the RRF smoothing constant be 60:

  • A: (1/(60+1) + 1/(60+30) \approx 0.0274)
  • B: (1/(60+7) + 1/(60+3) \approx 0.0308)
  • C: (1/(60+20) + 1/(60+2) \approx 0.0286)

B ranks highly in both lists, so it wins this illustrative fusion even though A is the exact lexical match and C is the strongest semantic match. The actual retrieval engine may use its own candidate windows, rank conventions, weighting, filters, and later reranking; this calculation teaches the mechanism, not a benchmark result.

If the exact error code must dominate because users often troubleshoot by identifier, adjust the lexical query, field weights, or query plan and evaluate the result. Do not assume the default fusion is the right business policy.

Worked example 2: a product code with a conceptual question

Consider a parts catalog with a query: “replacement cartridge for PX-410 that works in cold storage.” The exact identifier PX-410 matters, but the user may not know the catalog’s wording for cold-temperature compatibility.

A sensible design can search exact text fields for the identifier and run a vector query over descriptions. Then it applies deterministic filters for availability, region, and current product status. In the fused list, a passage matching both the model code and the cold-storage concept can rise above a passage that merely mentions one of them. The system should still display the product code and the specification that supports the compatibility statement. A semantic match alone is not proof that two products are interchangeable.

The example suggests a useful division of labor: retrieval proposes candidates; structured metadata and business rules establish eligibility; citations show the evidence; and a person or explicit policy handles consequential exceptions.

Candidate depth and the shape of the merge

Fusion sees only the candidates that each branch returns. If lexical retrieval contributes ten results and vector retrieval contributes fifty, the candidate pool is asymmetric. A relevant document outside either branch’s recall window cannot appear in the fused output. Increasing candidate depth can improve recall, but may add computation and merge work.

Azure’s query guidance recommends starting with a balanced query and tuning in small steps. It describes separate controls for vector candidate count and, in some API versions, how many text-ranked results enter the hybrid ranker. Those parameters are not interchangeable: k controls vector neighbors, while text recall controls lexical candidates. The guidance also discusses optional semantic ranking after fusion. The hybrid query guide is useful for understanding those controls; confirm the API version and whether any setting is marked preview before adopting it.

A production system should track at least:

  • the lexical and vector candidate counts and their overlap;
  • whether known answer-bearing passages are retrieved at all;
  • the position of the expected evidence after fusion;
  • latency and resource use at realistic query rates;
  • how often users reformulate, open citations, or escalate;
  • permission-filter behavior in each retrieval branch.

These measurements help distinguish retrieval recall problems from ranking problems. If the correct passage never enters either list, changing RRF weights will not solve it. If it appears near the bottom, inspect candidate depth, analyzers, vector quality, and the fusion policy.

Index design still determines quality

A hybrid index needs coherent text and vector representations. A common indexing pipeline extracts content, preserves a stable source ID and version, splits it into passages, generates embeddings, and stores both the passage text and its vector. Keep useful fields such as title, section path, language, source URL, update time, and access labels. These fields support filtering, result presentation, citations, and freshness checks.

Chunk size matters. Very small chunks may lose context; very large chunks can mix topics and dilute a focused passage. Keep headings with their explanations where possible and preserve document and page references. The text side and vector side should generally describe the same passage or clearly mapped units, so a fused result can be deduplicated and cited. If one branch searches whole documents and another searches chunks, define a stable parent mapping and group duplicate chunks deliberately.

Analyzers matter too. A tokenizer that splits a product identifier differently from the source may lose exact matches. Language-specific stemming can help ordinary prose but may harm codes and names. Structured fields for exact IDs, versions, dates, and categories often complement a broad analyzed text field.

Filters, permissions, and deduplication

Apply tenant and access-control constraints as part of retrieval. A system must not fetch an unauthorized passage and rely on a later answer prompt to hide it. If a platform supports filters before and after vector search, understand the chosen semantics and verify they match the security model. A user’s identity and group memberships need to reach every branch consistently.

Deduplication deserves explicit design. Two chunks from the same document may both rank highly, while a user really needs one answer-bearing section. Group by parent document, limit repeated siblings, or apply a diversity rule after fusion. However, diversity should not hide independent corroborating sources when a query needs them. For RAG, return passages with source IDs and offsets so generated claims can link back to evidence.

Evaluate against real information needs

Build a reviewed query set that contains exact-code questions, paraphrases, ambiguous requests, rare names, multilingual queries where relevant, and questions whose answer is absent. For each query, record one or more expected passages and the access context under which they are permitted. Compare lexical-only, vector-only, and hybrid results at the same output depth. Inspect both the ranked list and the evidence shown to a user.

Useful retrieval measures include recall at a chosen cutoff and reciprocal-rank or discounted-gain measures, but the choice depends on the task. Human review should examine whether the passage actually supports the answer, not just whether its words look similar. Evaluate the generator separately: good retrieval does not ensure that a model cites correctly or follows the evidence.

A safe rollout can begin in shadow mode or with a review step. Log the query, retrieved IDs, index version, ranking configuration, and user-visible citations according to privacy and retention rules. Keep a rollback path for embedding or analyzer changes. Do not store sensitive query text longer than the product needs.

A practical tuning sequence

  1. Define what counts as a relevant, accessible passage for the task.
  2. Check extraction, chunk boundaries, and exact searchable fields.
  3. Establish lexical-only and vector-only baselines using the same reviewed queries.
  4. Turn on hybrid fusion with modest candidate depths.
  5. Inspect missed evidence and duplicate-heavy results before changing weights.
  6. Add a semantic reranker only if it improves the measured task and fits latency and cost limits.
  7. Re-run permission, freshness, multilingual, and failure-case checks after every index or query change.

Hybrid search is most useful when a user’s vocabulary varies but precise identifiers still matter. Its central idea is simple: let text and vectors retrieve independently, combine their ranks, and evaluate the resulting evidence in the workflow where it will be used. The engineering work lies in index quality, candidate coverage, safe filtering, clear citations, and measurement—not in assuming that a combined score is automatically correct.

References

YOUR TAKE

What did you think?

Choose one reaction for this article.

Was this useful?

A cookie helps limit repeat responses. Your feedback is private.

Share this noteLinkedIn ↗X ↗Email ↗

Keep exploring.