Book a free call

How to Implement Hybrid Search Step by Step

Hybrid search pairs keyword matching with vector search so a query finds exact terms and related meaning. Here is how to build it, from data preparation to ranking.

Hertiv engineering teamReviewed by a senior engineer
7 min read
How to Implement Hybrid Search Step by Step
On this page

Short answer

Hybrid search is implemented by indexing each document twice, once for exact keyword matching and once as a vector embedding, then combining the two result lists with a ranking method such as reciprocal rank fusion. The work is mostly data preparation, scoring rules and testing, not new infrastructure.

Hybrid search is a search method that combines keyword matching with vector search in a single query. Keyword matching finds documents that contain the exact words the user typed, while vector search finds documents whose meaning is close to the query, even when the words differ.

Neither method is enough on its own. Keyword search misses a document that says 'refund policy' when the user types 'money back', and vector search can miss a document that contains an exact product code or error number. Used together, they cover both cases.

The idea is simple to state and takes real work to run well. Each document is indexed twice, the two searches run in parallel, and a fusion step merges the two ranked lists into one. The rest of this article covers each step in order.

How does hybrid search work?

Hybrid search works by running two different searches over the same documents and then merging the results. The keyword side uses a method such as BM25, which scores documents by how often the query words appear and how rare those words are. The vector side turns the query and each document into a list of numbers, called an embedding, and measures how close they are.

MethodGood atWeak at
Keyword (BM25)Exact terms, product codes, names, numbersSynonyms, paraphrases, related meaning
Vector (embeddings)Meaning, synonyms, questions in plain wordsExact codes, rare terms, short queries
Hybrid (both)Exact terms and related meaning togetherNeeds tuning and two indexes to maintain

The fusion step decides how much each side counts. A common method is reciprocal rank fusion, which gives points based on each document's position in each list rather than its raw score. That matters because keyword scores and vector scores live on different scales and cannot be added directly.

Most search engines now support this out of the box. The choice is usually between a hosted search service with hybrid search built in and a self-run setup, and the right answer depends on how much control the team wants over tuning. Teams that already run retrieval for language models often reuse the same store, since semantic search and hybrid search share the same embedding pipeline.

What do you need before you start?

Before building hybrid search, you need a clean document set, a way to turn documents into embeddings, and a search store that can run both kinds of query. The document set matters most: search quality follows the quality of what is indexed.

Start by deciding what a single searchable unit is. For a help centre, one article is usually one unit. For long manuals, each section or each page works better, because a single embedding of a 50-page document says little about any one part of it. The unit should be small enough that its content is about one thing.

Next, pick an embedding model and a vector store. The model turns text into numbers, and the store holds those numbers alongside the keyword index. Many teams start with a hosted embedding model and a search service that already supports vectors, which keeps the moving parts small. A hybrid search setup is only as good as the embeddings it uses, so the model choice is worth testing rather than guessing.

Finally, build a test set before writing any ranking code. Collect 50 to 100 real user questions and note which document should answer each one. Without that list, tuning becomes guesswork.

How to implement hybrid search in six steps

You implement hybrid search by preparing the documents, indexing them twice, running both searches, fusing the results and testing against real questions.

  1. Split documents into units. Break long documents into sections of a few hundred words each, keeping headings and context with each unit.
  2. Build the keyword index. Index the text with stemming and stop-word handling, so 'running' and 'run' match and common words do not dominate.
  3. Generate embeddings. Run each unit through the embedding model and store the vectors next to the keyword index, with the same document id on both sides.
  4. Run both searches per query. Send the query to the keyword search and the vector search at the same time, and take the top results from each.
  5. Fuse the lists. Combine the two ranked lists with reciprocal rank fusion or a weighted score, and return one merged list.
  6. Test and tune. Run the test set, measure how often the right document appears in the top three results, and adjust the fusion weight and the number of results each side contributes.

Keep the first version simple. A plain fusion of the top 20 results from each side, with equal weight, is a sensible starting point. Tuning comes after the pipeline works end to end.

How do you tune the ranking?

You tune hybrid search ranking by changing how much each side counts and measuring the result on the test set. If users mostly search for exact product codes and error numbers, the keyword side should weigh more. If they mostly ask questions in plain words, the vector side should weigh more.

A practical way to tune is to run the test set with several weight settings and record the share of questions where the right document lands in the top three. Move the weight in steps, keep the setting that scores best, and check that the change also helps on a second, held-out set of questions, so the tuning does not just fit one list.

Two other settings matter. The first is how many results each side contributes to the fusion: taking the top 50 from each side catches more candidates but adds noise. The second is the reranking step, where a second model re-scores the top results.

Reranking usually improves the top three results, but it adds latency, so it is worth measuring before keeping it. The cost of hybrid search rises with embeddings and reranking, so the budget should cover both.

Watch the failures, not just the average. A handful of failed queries usually share a cause, such as documents split in the wrong place or a missing synonym, and fixing the cause helps more than moving a weight.

Example (hypothetical): a software company has 8,000 help articles. Keyword search answers 62 of 100 test questions correctly, because users describe problems in their own words and the articles use product terms. The team adds hybrid search.

They split long articles into sections, index the text for keyword search and generate embeddings for each section. The first version fuses the top 20 keyword results and the top 20 vector results with equal weight. On the same 100-question test set, the right article now appears in the top three for 88 questions, up from 62.

Latency is 120 milliseconds for the keyword side and 180 milliseconds for the vector side, run in parallel, so a query takes about 200 milliseconds end to end. The team then tunes the weights: with the vector side weighted higher, the score rises to 91 of 100, but three product-code queries get worse, so they keep the equal weight and fix the code queries by adding a rule that boosts exact code matches.

The lesson is that the test set, not a hunch, should decide the tuning. The team keeps the 100 questions and re-runs them after every change.

What are the common mistakes?

The most common hybrid search mistakes are indexing whole documents, skipping the test set, and tuning by feel instead of measurement.

  • Indexing whole documents. A 50-page manual as one unit produces one vague embedding; split it into sections first.
  • No test set. Without real questions and known answers, every tuning change is a guess.
  • Adding raw scores together. Keyword and vector scores live on different scales, so use rank-based fusion or normalise first.
  • Ignoring exact matches. A user typing a product code or error number wants the exact document, not a related one.
  • Too many results in the fusion. Fusing the top 100 from each side adds noise; start with the top 10 to 20.
  • Forgetting to refresh embeddings. When documents change, their embeddings must be regenerated or search returns stale content.

Key takeaways

  • Hybrid search runs keyword matching and vector search together, then merges the two ranked lists
  • Keyword search catches exact terms and codes; vector search catches meaning and synonyms
  • Split documents into small units before indexing, or the embeddings say too little
  • Use rank-based fusion, since keyword and vector scores live on different scales
  • Build a test set of real questions first and let it decide every tuning change

Frequently asked questions

Is hybrid search better than vector search alone?

Usually, yes, for mixed content. Vector search handles meaning well but can miss exact product codes, names and numbers, which keyword search catches. Hybrid search covers both, at the cost of maintaining two indexes and tuning the fusion.

What is reciprocal rank fusion?

It is a method for merging two ranked lists by giving each document points based on its position in each list, not its raw score. A document ranked first in one list and fifth in another scores higher than one ranked tenth in both. It works well because it needs no score normalisation.

Do I need a vector database for hybrid search?

Not always. Many search engines now store vectors alongside keyword indexes, so one system can run both searches. A separate vector database makes sense when the vector workload is large or needs its own scaling, but it adds a system to maintain.

How many documents do I need for hybrid search?

There is no minimum, but the benefit grows with content size and variety. With a few dozen short pages, keyword search is often enough. Hybrid search pays off when the collection is large, the wording varies and users ask questions in plain language.

How do I measure hybrid search quality?

Build a test set of real user questions with the correct document for each, then measure how often the right document appears in the top three results. Track that number after every change, and look at the failed queries to find the cause.

Does hybrid search cost more than keyword search?

Yes, mainly for embedding generation and storage, plus any reranking step. Embedding a document set is usually a one-off cost, while reranking adds cost per query. The cost of hybrid search depends on the model, the collection size and how many queries reranking handles.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building search or RAG into your product? Talk to Hertiv.

A senior engineer replies within one business day. Or see our RAG Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call