Lesson 1 of 4 Advanced Retrieval Techniques

Combining Semantic and Keyword Search with Hybrid Search

This lesson explains how hybrid search combines semantic search, which understands meaning, with keyword search, which finds exact terms, in Amazon OpenSearch Service and Amazon Bedrock Knowledge Bases.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain why semantic search alone misses exact terms.
  • Build hybrid queries with score normalisation in OpenSearch.
  • Use hybrid search in Bedrock Knowledge Bases.

Why semantic search alone falls short

Semantic search works well when users describe a concept, but it struggles with exact terms. Embeddings capture general meaning, so identifiers with little meaning of their own, such as an error code "ERR-4471" or a part number "X200-B", may produce vectors close to many unrelated codes, and the correct document may not rank first. Rare domain terms that the embedding model never saw during training are also represented poorly.

Keyword search has the opposite strengths. The BM25 ranking function scores documents by how often the query terms appear in them, weighted by how rare each term is across the collection, so an exact match on a rare identifier scores very highly. It fails, however, when users describe something in different words from the document. Hybrid search runs both searches and combines the results, so that queries benefit from exact matching and from semantic matching at the same time.

Sort into groups

Keyword, semantic or both?

Exam skills 1.5.4

Decide which retrieval approach handles each query best.

Log in to try this activity Interactive activities are free with an account.

Hybrid search in OpenSearch

In Amazon OpenSearch Service, a hybrid query contains a lexical subquery, for example a match query on the text field, and a vector subquery, a knn or neural query. The two produce scores on different scales: BM25 scores are unbounded, while vector similarity scores fall in a fixed range. Adding them directly would let one dominate.

A search pipeline with a normalisation processor solves this. It rescales each subquery's scores, for example with min-max normalisation to the range 0 to 1, and combines them with weights, for example an arithmetic mean that gives 30% weight to keyword relevance and 70% to semantic relevance. The weights are tuned with a retrieval test set. Rank-based combination, such as reciprocal rank fusion, is an alternative that combines the positions of documents in each result list and ignores raw scores entirely. Bedrock Knowledge Bases with supported vector stores can also perform hybrid search through the overrideSearchType setting.

PUT /_search/pipeline/hybrid-pipeline
{"phase_results_processors": [{"normalization-processor": {
   "normalization": {"technique": "min_max"},
   "combination": {"technique": "arithmetic_mean", "parameters": {"weights": [0.3, 0.7]}}}}]}

GET /manuals/_search?search_pipeline=hybrid-pipeline
{"query": {"hybrid": {"queries": [
   {"match": {"body": "ERR-4471 pump pressure"}},
   {"neural": {"body_embedding": {"query_text": "ERR-4471 pump pressure", "model_id": "bedrock-titan-v2", "k": 20}}}
]}}}

The following diagram shows the scores before and after normalisation for one query.

Combining keyword and vector scores in an OpenSearch hybrid query. BM25 scores are unbounded and vector scores fall in a fixed range, so a normalisation processor rescales each to 0 to 1 with min-max normalisation and then combines them with weights, here 30% keyword and 70% semantic. The manual with the exact code ranks first.
The scores and weights are illustrative; tune weights on a labelled evaluation set.
Scenario questions

Combining scores

Exam skills 1.5.4 · 4.2.2

Practise configuring hybrid search in OpenSearch.

Log in to try this activity Interactive activities are free with an account.

Hybrid search in Bedrock Knowledge Bases and custom scoring

Bedrock Knowledge Bases support a hybrid search type for vector stores that have a text field that can be searched, such as OpenSearch Serverless, Aurora PostgreSQL and MongoDB Atlas. The application sets overrideSearchType to HYBRID in the retrieval configuration, or leaves the choice to the knowledge base.

Custom scoring tunes how results are combined for the domain: weights that favour lexical matches when the query contains identifiers, boosts for recent documents or authoritative sources, and metadata filters applied before scoring. Weights are tuned on a labelled evaluation set by measuring recall and mean reciprocal rank for each setting. The following table compares the search types.

Search typeStrengthWeakness
Keyword (BM25)Exact terms, identifiers, rare wordsMisses synonyms and paraphrases
Semantic (vector)Meaning, paraphrases, cross-languageWeak on codes and unseen terms
HybridBoth exact and semantic matchesNeeds score normalisation and weight tuning
Worked example

Error codes not found

Engineers ask a troubleshooting assistant about specific error codes. Retrieval returns documents about similar but different errors, though the exact code appears in one manual.

This is the classic failure of pure semantic search on identifiers. Switching the knowledge base retrieval to hybrid search (or an OpenSearch hybrid query with a normalisation pipeline) makes the manual with the exact code rank highly, while descriptive questions still benefit from the vector component.

Check yourself

Which knowledge base setting requests hybrid search on a supported vector store?

Show answer

overrideSearchType set to HYBRID in the retrieval configuration.

Exam Tips

Remember for the exam

  • Exact identifiers missed by semantic search: hybrid search.
  • OpenSearch hybrid: hybrid query plus a normalisation search pipeline.
  • Knowledge Bases: overrideSearchType HYBRID on supported stores.
  • Tune hybrid weights on a labelled evaluation set.