Skip to content

Commit 2f8f99c

Browse files
authored
Merge pull request #253014 from HeidiSteen/heidist-freshness
[azure search] Refactor Concept > Search and Concept > Relevance nodes
2 parents d6b4bf4 + f735d80 commit 2f8f99c

14 files changed

+391
-115
lines changed

articles/search/TOC.yml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,32 +123,34 @@
123123
href: samples-rest.md
124124
- name: Concepts
125125
items:
126-
- name: Retrieval Augmented Generation (RAG)
127-
href: retrieval-augmented-generation-overview.md
128126
- name: Search
129127
items:
130128
- name: Full-text search
131-
items:
132-
- name: Overview
133-
href: search-lucene-query-architecture.md
134-
- name: Query types and composition
135-
href: search-query-overview.md
136-
- name: Relevance scoring
137-
href: index-similarity-and-scoring.md
129+
href: search-lucene-query-architecture.md
138130
- name: Vector search
139-
items:
140-
- name: Overview
141-
href: vector-search-overview.md
142-
- name: Vector index size limit
143-
href: vector-search-index-size.md
144-
- name: Vector query execution
145-
href: vector-search-ranking.md
131+
href: vector-search-overview.md
132+
- name: Hybrid search
133+
href: hybrid-search-overview.md
134+
- name: Retrieval Augmented Generation (RAG)
135+
href: retrieval-augmented-generation-overview.md
136+
- name: Other query types
137+
href: search-query-overview.md
138+
- name: Relevance
139+
items:
140+
- name: Scoring in keyword queries (BM25)
141+
href: index-similarity-and-scoring.md
142+
- name: Scoring in vector queries
143+
href: vector-search-ranking.md
144+
- name: Scoring in hybrid queries (RRF)
145+
href: hybrid-search-ranking.md
146146
- name: Semantic search
147147
href: semantic-search-overview.md
148148
- name: Indexing
149149
items:
150150
- name: Search indexes
151151
href: search-what-is-an-index.md
152+
- name: Vector index size limit
153+
href: vector-search-index-size.md
152154
- name: Import
153155
href: search-what-is-data-import.md
154156
- name: Import Data wizard
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
title: Hybrid search
3+
titleSuffix: Azure Cognitive Search
4+
description: Describes concepts and architecture of hybrid query processing and document retrieval. Hybrid queries combine vector search and full text search.
5+
6+
author: robertklee
7+
ms.author: robertlee
8+
ms.service: cognitive-search
9+
ms.topic: conceptual
10+
ms.date: 09/27/2023
11+
---
12+
13+
# Hybrid search using vectors and full text in Azure Cognitive Search
14+
15+
> [!IMPORTANT]
16+
> Hybrid search uses the [vector features](vector-search-overview.md) currently in public preview under [supplemental terms of use](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
17+
18+
Hybrid search is a combination of full text and vector queries that execute against a search index that contains both searchable plain text content and generated embeddings. For query purposes, hybrid search is:
19+
20+
+ A single query request that includes `search` and `vectors` parameters, multiple vector queries, or one vector query targeting multiple fields
21+
+ Parallel query execution
22+
+ Merged results in the query response, scored using [Reciprocal Rank Fusion (RRF)](hybrid-search-ranking.md)
23+
24+
This article explains the concepts, benefits, and limitations of hybrid search.
25+
26+
## How does hybrid search work?
27+
28+
In Azure Cognitive Search, vector indexes containing embeddings can live alongside textual and numerical fields allowing you to issue hybrid full text and vector queries. Hybrid queries can take advantage of existing functionality like filtering, faceting, sorting, scoring profiles, and [semantic ranking](semantic-search-overview.md) in a single search request.
29+
30+
Hybrid search combines results from both full text and vector queries, which use different ranking functions such as BM25 and cosine similarity. To present these results in a single ranked list, a method of merging the ranked result lists is needed.
31+
32+
## Structure of a hybrid query
33+
34+
Hybrid search is predicated on having a search index that contains fields of various types, including plain text and numbers, geo coordinates for geospatial search, and vectors for a mathematical representation of a chunk of text or image, audio, and video. You can use almost all query capabilities in Cognitive Search with a vector query, except for client-side interactions such as autocomplete and suggestions.
35+
36+
A representative hybrid query might be as follows (notice the vector is trimmed for brevity):
37+
38+
```http
39+
POST https://{{searchServiceName}}.search.windows.net/indexes/hotels-vector-quickstart/docs/search?api-version=2023-07-01-Preview
40+
content-type: application/JSON
41+
{
42+
"count": true,
43+
"search": "historic hotel walk to restaurants and shopping",
44+
"select": "HotelId, HotelName, Category, Description, Address/City, Address/StateProvince",
45+
"filter": "geo.distance(Location, geography'POINT(-77.03241 38.90166)') le 300",
46+
"facets": [ "Address/StateProvince"],
47+
"vectors": [
48+
{
49+
"value": [ <array of embeddings> ]
50+
"k": 7,
51+
"fields": "DescriptionVector"
52+
},
53+
{
54+
"value": [ <array of embeddings> ]
55+
"k": 7,
56+
"fields": "Description_frVector"
57+
}
58+
],
59+
"queryType": "semantic",
60+
"queryLanguage": "en-us",
61+
"semanticConfiguration": "my-semantic-config"
62+
}
63+
```
64+
65+
Key points include:
66+
67+
+ `search` specifies a full text search query.
68+
+ `vectors` for vector queries, which can be multiple, targeting multiple vector fields. If the embedding space includes multi-lingual content, vector queries can find the match with no language analyzers or translation required.
69+
+ `select` specifies which fields to return in results, which can be text fields that are human readable.
70+
+ `filters` can specify geospatial search or other include and exclude criteria, such as whether parking is included. The geospatial query in this example finds hotels within a 300-kilometer radius of Washington D.C.
71+
+ `facets` can be used to compute facet buckets over results that are returned from hybrid queries.
72+
+ `queryType=semantic` invokes semantic ranking, applying machine reading comprehension to surface more relevant search results.
73+
74+
Filters and facets target data structures within the index that are distinct from the inverted indexes used for full text search and the vector indexes used for vector search. As such, when filters and faceted operations execute, the search engine can apply the operational result to the hybrid search results in the response.
75+
76+
Notice how there's no `orderby` in the query. Explicit sort orders override relevanced-ranked results, so if you want similarity and BM25 relevance, omit sorting in your query.
77+
78+
A response from the above query might look like this:
79+
80+
```http
81+
{
82+
"@odata.count": 3,
83+
"@search.facets": {
84+
"Address/StateProvince": [
85+
{
86+
"count": 1,
87+
"value": "NY"
88+
},
89+
{
90+
"count": 1,
91+
"value": "VA"
92+
}
93+
]
94+
},
95+
"value": [
96+
{
97+
"@search.score": 0.03333333507180214,
98+
"@search.rerankerScore": 2.5229012966156006,
99+
"HotelId": "49",
100+
"HotelName": "Old Carrabelle Hotel",
101+
"Description": "Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center.",
102+
"Category": "Luxury",
103+
"Address": {
104+
"City": "Arlington",
105+
"StateProvince": "VA"
106+
}
107+
},
108+
{
109+
"@search.score": 0.032522473484277725,
110+
"@search.rerankerScore": 2.111117362976074,
111+
"HotelId": "48",
112+
"HotelName": "Nordick's Motel",
113+
"Description": "Only 90 miles (about 2 hours) from the nation's capital and nearby most everything the historic valley has to offer. Hiking? Wine Tasting? Exploring the caverns? It's all nearby and we have specially priced packages to help make our B&B your home base for fun while visiting the valley.",
114+
"Category": "Boutique",
115+
"Address": {
116+
"City": "Washington D.C.",
117+
"StateProvince": null
118+
}
119+
}
120+
]
121+
}
122+
```
123+
124+
## Benefits
125+
126+
Hybrid search combines the strengths of vector search and keyword search. The advantage of vector search is finding information that's similar to your search query, even if there are no keyword matches in the inverted index. The advantage of keyword or full text search is precision, and the ability to apply semantic ranking that improves the quality of the initial results. Some scenarios, such as product codes, highly specialized jargon, dates, etc. can perform better with keyword search because it can identify exact matches.
127+
128+
Benchmark testing on real-world and benchmark datasets indicates that hybrid retrieval with semantic ranking offers significant benefits in search relevance.
129+
130+
## See also
131+
132+
[Outperform vector search with hybrid retrieval and ranking (Tech blog)](https://techcommunity.microsoft.com/t5/azure-ai-services-blog/azure-cognitive-search-outperforming-vector-search-with-hybrid/ba-p/3929167)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Hybrid search scoring (RRF)
3+
titleSuffix: Azure Cognitive Search
4+
description: Describes the Reciprocal Rank Fusion (RRF) algorithm used to unify search scores from parallel queries in Azure Cognitive Search.
5+
6+
author: yahnoosh
7+
ms.author: jlembicz
8+
ms.service: cognitive-search
9+
ms.topic: conceptual
10+
ms.date: 09/27/2023
11+
---
12+
13+
# Relevance scoring in hybrid search using Reciprocal Rank Fusion (RRF)
14+
15+
> [!IMPORTANT]
16+
> Hybrid search uses the [vector features](vector-search-overview.md) currently in public preview under [supplemental terms of use](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
17+
18+
For hybrid search scoring, Cognitive Search uses the Reciprocal Rank Fusion (RRF) algorithm. RRF combines the results of different search methods - such as vector search and full text search or multiple vector queries executing in parallel - to produce a single relevance score. RRF is based on the concept of *reciprocal rank*, which is the inverse of the rank of the first relevant document in a list of search results. 
19+
20+
The goal of the technique is to take into account the position of the items in the original rankings, and give higher importance to items that are ranked higher in multiple lists. This can help improve the overall quality and reliability of the final ranking, making it more useful for the task of fusing multiple ordered search results.
21+
22+
In Azure Cognitive Search, RRF is used whenever there are two or more queries that execute in parallel. Each query produces a ranked result set, and RRF is used to merge and homogenize the rankings into a single result set, returned in the query response.
23+
24+
## How RRF ranking works
25+
26+
RRF works by taking the search results from multiple methods, assigning a reciprocal rank score to each document in the results, and then combining the scores to create a new ranking. The concept is that documents appearing in the top positions across multiple search methods are likely to be more relevant and should be ranked higher in the combined result.
27+
28+
Here's a simple explanation of the RRF process:
29+
30+
1. Obtain ranked search results from multiple queries executing in parallel for full text search and vector search.
31+
32+
1. Assign reciprocal rank scores for result in each of the ranked lists. RRF generates a new **`@search.score`** for each match in each result set. For each document in the search results, we assign a reciprocal rank score based on its position in the list. The score is calculated as `1/(rank + k)`, where `rank` is the position of the document in the list, and `k` is a constant, which was experimentally observed to perform best if it's set to a small value like 60. **Note that this `k` value is a constant in the RRF algorithm and entirely separate from the `k` that controls the number of nearest neighbors.**
33+
34+
1. Combine scores. For each document, the engine sums the reciprocal rank scores obtained from each search system, producing a combined score for each document. 
35+
36+
1. Rank documents based on combined scores and sort them. The resulting list is the fused ranking.
37+
38+
Only fields marked as `searchable` in the index are used for scoring. Only fields marked as `retrievable`, or fields that are specified in `searchFields` in the query, are returned in search results, along with their search score.
39+
40+
### Parallel query execution
41+
42+
RRF is used anytime there's more than one query execution. The following examples illustrate query patterns where parallel query execution occurs:
43+
44+
+ A full text query, plus one vector query (simple hybrid scenario), equals two query executions.
45+
+ A full text query, plus one vector query targeting two vector fields, equals three query executions.
46+
+ A full text query, plus two vector queries targeting five vector fields, equals 11 query executions
47+
48+
## Scores in a hybrid search results
49+
50+
Whenever results are ranked, **`@search.score`** property contains the value used to order the results. Scores are generated by ranking algorithms that vary for each method. Each algorithm has its own range and magnitude.
51+
52+
The following chart identifies the scoring property returned on each match, algorithm, and range of scores for each relevance ranking algorithm.
53+
54+
| Search method | Parameter | Scoring algorithm | Range |
55+
|---------------|-----------|-------------------|-------|
56+
| full-text search | `@search.score` | BM25 algorithm | No upper limit. |
57+
| vector search | `@search.score` | HNSW algorithm, using the similarity metric specified in the HNSW configuration. | 0.333 - 1.00 (Cosine), 0 to 1 for Euclidean and DotProduct. |
58+
| hybrid search | `@search.score` | RRF algorithm | Upper limit is only bounded by the number of queries being fused, with each query contributing a maximum of approximately 1 to the RRF score. |
59+
| semantic ranking | `@search.rerankerScore` | Semantic ranking | 1.00 - 4.00 |
60+
61+
Semantic ranking doesn't participate in RRF. Its score (`@search.rerankerScore`) is always reported separately in the query response. Semantic ranking can rerank full text and hybrid search results, assuming those results include fields having semantically rich content.
62+
63+
## Number of ranked results in a hybrid query response
64+
65+
By default, if you aren't using pagination, the search engine returns the top 50 highest ranking matches for full text search, and it returns `k` matches for vector search. In a hybrid query, `top` determines the number of results in the response. Based on defaults, the top 50 highest ranked matches of the unified result set are returned. Full text search is subject to a maximum limit of 1,000 matches (see [API response limits](search-limits-quotas-capacity.md#api-response-limits)). Once 1,000 matches are found, the search engine no longer looks for more.
66+
67+
You can use `top`, `skip`, and `next` for paginated results. Paging results is how you determine the number of results on each logical page and navigate through the full payload. For more information, see [How to work with search results](search-pagination-page-layout.md).
68+
69+
## See also
70+
71+
+ [Learn more about hybrid search](hybrid-search-overview.md)
72+
+ [Learn more about vector search](vector-search-overview.md)

0 commit comments

Comments
 (0)