Skip to content

Commit b37b687

Browse files
authored
Merge pull request #1600 from eric-urban/eur/query-rewrites
query rewrites edit
2 parents 8b5bbd7 + af51b21 commit b37b687

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

articles/search/semantic-how-to-query-rewrite.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ ms.date: 11/19/2024
1717

1818
[!INCLUDE [Feature preview](./includes/previews/preview-generic.md)]
1919

20-
Query rewriting is the process of transforming a user's query into a more effective one. The search service sends the search query (or a variation of it) to a generative model that generates alternative queries.
20+
Query rewriting is the process of transforming a user's query into a more effective one, adding more terms and refining search results. The search service sends the search query (or a variation of it) to a generative model that generates alternative queries.
21+
22+
Query rewriting improves results from [semantic ranking](search-get-started-semantic.md) by correcting typos or spelling errors in user queries, and expanding queries with synonyms.
2123

2224
Search with query rewriting works like this:
2325
- The user query is sent via the `search` property in the request.
@@ -27,23 +29,16 @@ Search with query rewriting works like this:
2729
Query rewriting is an optional feature. Without query rewriting, the search service just uses the original query to retrieve search results.
2830

2931
> [!NOTE]
30-
> Query rewriting is currently available in the East US, North Europe, and Southeast Asia regions.
31-
32-
## Why use query rewriting?
33-
34-
When you enable query rewriting in Azure AI Search, you might or might not see higher BM25 scores, which indicate how relevant a document is to a query. Query rewriting uses generative AI to expand the original query, adding more terms and refining search results.
32+
> The rewritten queries might not contain all of the exact terms the original query had. This might impact search results if the query was highly specific and required exact matches for unique identifiers or product codes.
3533
36-
When query rewriting might be helpful:
37-
- Correcting typos or spelling errors in user queries.
38-
- Expanding queries with synonyms to improve search results.
34+
## Prerequisites
3935

40-
When query rewriting might not be helpful:
41-
- For highly specific queries that require exact matches.
42-
- When searching for unique identifiers or product codes.
36+
+ A search service, Basic tier or higher.
4337

44-
## Prerequisites
38+
> [!NOTE]
39+
> Query rewriting is currently available in the East US, North Europe, and Southeast Asia regions.
4540
46-
+ A search service, Basic tier or higher, with [semantic ranker enabled](semantic-how-to-enable-disable.md). Review [semantic ranking](semantic-search-overview.md) if you need an introduction to the feature.
41+
+ Your search service must have [semantic ranker enabled](semantic-how-to-enable-disable.md). Review [semantic ranking](semantic-search-overview.md) if you need an introduction to the feature.
4742

4843
> [!IMPORTANT]
4944
> Semantic ranker is currently required for query rewriting.
@@ -82,7 +77,11 @@ In this REST API example, we use [Search Documents](/rest/api/searchservice/docu
8277
- We set "queryRewrites" to "generative|count-5" to get up to five query rewrites. You can set the count to any value between 1 and 10.
8378
- We set "queryLanguage" to the target language ("en-US") of the query rewrites. The supported locales are:
8479
`en-AU`, `en-CA`, `en-GB`, `en-IN`, `en-US`, `ar-EG`, `ar-JO`, `ar-KW`, `ar-MA`, `ar-SA`, `bg-BG`, `bn-IN`, `ca-ES`, `cs-CZ`, `da-DK`, `de-DE`, `el-GR`, `es-ES`, `es-MX`, `et-EE`, `eu-ES`, `fa-AE`, `fi-FI`, `fr-CA`, `fr-FR`, `ga-IE`, `gl-ES`, `gu-IN`, `he-IL`, `hi-IN`, `hr-BA`, `hr-HR`, `hu-HU`, `hy-AM`, `id-ID`, `is-IS`, `it-IT`, `ja-JP`, `kn-IN`, `ko-KR`, `lt-LT`, `lv-LV`, `ml-IN`, `mr-IN`, `ms-BN`, `ms-MY`, `nb-NO`, `nl-BE`, `nl-NL`, `no-NO`, `pa-IN`, `pl-PL`, `pt-BR`, `pt-PT`, `ro-RO`, `ru-RU`, `sk-SK`, `sl-SL`, `sr-BA`, `sr-ME`, `sr-RS`, `sv-SE`, `ta-IN`, `te-IN`, `th-TH`, `tr-TR`, `uk-UA`, `ur-PK`, `vi-VN`, `zh-CN`, `zh-TW`.
85-
- We set "debug" to "queryRewrites" to get the query rewrites in the response. Set the `"debug": "queryRewrites"` property for testing purposes. For better performance, don't use debug in production.
80+
- We set "debug" to "queryRewrites" to get the query rewrites in the response.
81+
82+
> [!TIP]
83+
> Only set `"debug": "queryRewrites"` for testing purposes. For better performance, don't use debug in production.
84+
8685
- We set "top" to 1 to return only the top search result.
8786
8887
1. Send the request to execute the query and return results.
@@ -146,7 +145,7 @@ Here's an example of a response that includes query rewrites:
146145
```
147146

148147
Here are some key points to note:
149-
- Because we set the "debug" property to "queryRewrites", the response includes a `@search.debug` object with the text input query and query rewrites.
148+
- Because we set the "debug" property to "queryRewrites" for testing, the response includes a `@search.debug` object with the text input query and query rewrites.
150149
- Because we set the "queryRewrites" property to "generative|count-5", the response includes up to five query rewrites.
151150
- The `"inputQuery"` value is the query sent to the generative model for query rewriting. The input query isn't always the same as the user's `"search"` query.
152151

@@ -202,7 +201,10 @@ Here's an example of a response without query rewrites.
202201

203202
You can include vector queries in your search request to combine keyword search and vector search into a single request and a unified response.
204203

205-
Here's an example of a query that includes a vector query with query rewrites. We modified a [previous example](#make-a-search-request-with-query-rewrites) to include a vector query.
204+
Here's an example of a query that includes a vector query with query rewrites. We modify a [previous example](#make-a-search-request-with-query-rewrites) to include a vector query.
205+
206+
- We add a "vectorQueries" object to the request. This object includes a vector query with the "kind" set to "text".
207+
- The "text" value is the same as the "search" value. These values must be identical for query rewriting to work.
206208

207209
```http
208210
POST https://[search-service-name].search.windows.net/indexes/hotels-sample-index/docs/search?api-version=2024-11-01-preview
@@ -221,22 +223,19 @@ POST https://[search-service-name].search.windows.net/indexes/hotels-sample-inde
221223
"queryType":"semantic",
222224
"queryRewrites":"generative|count-5",
223225
"queryLanguage":"en-US",
224-
"debug":"queryRewrites",
225226
"top": 1
226227
}
227228
```
228229

229-
Here are some key points to note:
230-
- We added a "vectorQueries" object to the request. This object includes a vector query with the "kind" set to "text".
231-
- The "text" value is the same as the "search" value. These values must be identical for query rewriting to work.
232-
233230
The response includes query rewrites for both the text query and the vector query.
234231

235-
## Debugging query rewrites
232+
## Test query rewrites with debug
236233

237234
You should test your query rewrites to ensure that they're working as expected. Set the `"debug": "queryRewrites"` property in your query request to get the query rewrites in the response. Setting `"debug"` is optional for testing purposes. For better performance, don't set this property in production.
238235

239-
You might observe that the response includes an empty array for the `text.rewrites` and `vectors` properties.
236+
### Partial response reasons
237+
238+
You might observe that the debug (test) response includes an empty array for the `text.rewrites` and `vectors` properties.
240239

241240
```json
242241
{
@@ -256,7 +255,9 @@ You might observe that the response includes an empty array for the `text.rewrit
256255
}
257256
```
258257

259-
In the preceding example, the response includes a `@search.semanticPartialResponseReason` property with a value of "Transient". This message means that at least one of the queries failed to complete. The response also includes a `@search.semanticQueryRewriteResultType` property with a value of "OriginalQueryOnly". This message means that the query rewrites are unavailable. Only the original query is used to retrieve search results.
258+
In the preceding example:
259+
- The response includes a `@search.semanticPartialResponseReason` property with a value of "Transient". This message means that at least one of the queries failed to complete.
260+
- The response also includes a `@search.semanticQueryRewriteResultType` property with a value of "OriginalQueryOnly". This message means that the query rewrites are unavailable. Only the original query is used to retrieve search results.
260261

261262
## Next steps
262263

0 commit comments

Comments
 (0)