Create a hybrid query in Azure AI Search

Hybrid search combines text (keyword) and vector queries in a single search request. Both queries execute in parallel. The results are merged and reordered by new search scores, using Reciprocal Rank Fusion (RRF) to return a unified result set.

In this article, learn how to:

  • Set up a basic hybrid request
  • Add parameters and filters
  • Improve relevance using semantic ranking or vector weights
  • Optimize query behaviors by controlling inputs (maxTextRecallSize)

Prerequisites

Choose an API or tool

  • Search Explorer in the Azure portal (supports both stable and preview API search syntax) has a JSON view that lets you paste in a hybrid request.

  • Stable REST APIs or a recent preview API version if you're using preview features like maxTextRecallSize and countAndFacetMode(preview).

    For readability, we use REST examples to explain how the APIs work. You can use a REST client like Visual Studio Code with the REST extension to build hybrid queries. You can also use the Azure SDKs. For more information, see Quickstart: Vector search.

Set up a hybrid query

This section explains the basic structure of a hybrid query and how to set one up in either Search Explorer or for execution in a REST client.

Results are returned in plain text, including vectors in fields marked as retrievable. Because numeric vectors aren't useful in search results, choose other fields in the index as a proxy for the vector match. For example, if an index has "descriptionVector" and "descriptionText" fields, the query can match on "descriptionVector" but the search result can show "descriptionText". Use the select parameter to specify only human-readable fields in the results.

  1. Sign in to the Azure portal and find your search service.

  2. Under Search management > Indexes, select an index that has vectors and non-vector content. Search Explorer is the first tab.

  3. Under View, switch to JSON view so that you can paste in a vector query.

  4. Replace the default query template with a hybrid query. A basic hybrid query has a text query specified in search, and a vector query specified under vectorQueries.vector. The text query and vector query can be equivalent or divergent, but it's common for them to share the same intent.

    This example is from the vector quickstart that has vector and nonvector content, and several query examples. For brevity, the vector is truncated in this article.

    {
        "search": "historic hotel walk to restaurants and shopping",
        "vectorQueries": [
            {
                "vector": [0.01944167, 0.0040178085, -0.007816401 ... <remaining values omitted> ], 
                "k": 7,
                "fields": "DescriptionVector",
                "kind": "vector",
                "exhaustive": true
            }
        ]
    }
    
  5. Select Search.

    Tip

    Search results are easier to read if you hide the vectors. In Query Options, turn on Hide vector values in search results.

  6. Here's another version of the query. This one adds a count for the number of matches found, a select parameter for choosing specific fields, and a top parameter to return the top seven results.

     {
         "count": true,
         "search": "historic hotel walk to restaurants and shopping",
         "select": "HotelId, HotelName, Category, Tags, Description",
         "top": 7,
         "vectorQueries": [
             {
                 "vector": [0.01944167, 0.0040178085, -0.007816401 ... <remaining values omitted> ], 
                 "k": 7,
                 "fields": "DescriptionVector",
                 "kind": "vector",
                 "exhaustive": true
             }
         ]
     }