Instruction 01

Introduction

Hybrid search is a distinct method which integrates various types of searches into a single query. Traditional search, also known as keyword or lexical search, works with textual data and identifies text through direct matches, whether complete or partial.

Semantic search — powered by vector search — locates results based on contextual meanings, and works with various data types.

A hybrid search in Azure AI Search combines both keyword search with semantic search.

Understanding Hybrid Search with Azure AI Search

Azure AI Search enables hybrid search by allowing vector fields with embeddings to coexist with standard textual data in the same document.

From the previous lesson, you can see this in the docVectors.json file. The embeddings are represented by arrays of negative and positive integers, like [-0.028984629, 0.032270152, -0.007246157, -0.047212537, -0.03762601, ...], while the textual data is stored in JSON format, like [{"id": "1", "title": "Stranger Things", "content": "Set in the 1980s in the small town of Hawkins, ...}].

This seemingly simple structure represents a powerful capability where both structured and unstructured data can be stored and retrieved in a single query. This isn’t possible with traditional or vector searches alone, and attempting this manually would require implementing both search types independently, as most existing libraries and tools support only one at a time.

In other words, you’d have to design data structures and algorithms to perform both searches simultaneously, whereas Azure AI Search provides this functionality right out of the box.

Reciprocal Rank Fusion (RFF)

Azure AI Search’s ability to perform hybrid searches isn’t solely due to its support for both textual data and embeddings. After completing both search types, the results need to be unified before being returned in a response. Azure AI Search uses the Reciprocal Rank Fusion (RRF) algorithm to achieve this.

The RRF algorithm considers the strengths of both searches, assigns an appropriate score, and returns a unified response based on this ranking. Note that only fields designated as searchable in the index, or specified in searchFields within the query, contribute to scoring. Similarly, fields must be marked as retrievable in the index, or specified in the select property within the query, to be included in the search results with their respective search scores.

RRF allows leveraging the strengths of multiple search types, delivering improved results simply and efficiently. You can use it with multi-modal search scenarios, where searches are performed over data from different embedding models, such as text, images, audio, video, and more.

Bearing all this in mind, RRF is a key component that enables hybrid search in Azure AI Search.

Identifying the Impact of Weighted Scores

You can weight vector queries before using them in RRF ranking. Since the same query is used in multiple searches before combining them, the score for each search type may not have the same weight or relevance. A keyword search that produces a perfect score for a query should be assessed differently from a vector search that scored around 0.8.

Specifying a weight for vector queries is known as vector weighting. This factor is multiplied with the score of a query before using it in RRF to determine the overall rank of a result. The default value is 1.0. Depending on your use case, you can specify a lower factor, such as 0.5, or a higher one, such as 2.0. Increasing the weight for a score increases its value and its chances of ranking higher in the final ranking. The converse is also true.

Azure AI Search creates a hybrid search from your query for use in hybrid searches. Continue to the next segment to see how a sample hybrid query looks, as well as the various properties and configurations available to you.

See forum comments
Download course materials from Github
Previous: Introduction Next: Instruction 02