You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
21
23
22
24
Search with query rewriting works like this:
23
25
- The user query is sent via the `search` property in the request.
@@ -27,23 +29,16 @@ Search with query rewriting works like this:
27
29
Query rewriting is an optional feature. Without query rewriting, the search service just uses the original query to retrieve search results.
28
30
29
31
> [!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.
35
33
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
39
35
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.
43
37
44
-
## Prerequisites
38
+
> [!NOTE]
39
+
> Query rewriting is currently available in the East US, North Europe, and Southeast Asia regions.
45
40
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.
47
42
48
43
> [!IMPORTANT]
49
44
> 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
82
77
- 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.
83
78
- We set "queryLanguage" to the target language ("en-US") of the query rewrites. The supported locales are:
- 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
+
86
85
- We set "top" to 1 to return only the top search result.
87
86
88
87
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:
146
145
```
147
146
148
147
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.
150
149
- Because we set the "queryRewrites" property to "generative|count-5", the response includes up to five query rewrites.
151
150
- 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.
152
151
@@ -202,7 +201,10 @@ Here's an example of a response without query rewrites.
202
201
203
202
You can include vector queries in your search request to combine keyword search and vector search into a single request and a unified response.
204
203
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.
206
208
207
209
```http
208
210
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
221
223
"queryType":"semantic",
222
224
"queryRewrites":"generative|count-5",
223
225
"queryLanguage":"en-US",
224
-
"debug":"queryRewrites",
225
226
"top": 1
226
227
}
227
228
```
228
229
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
-
233
230
The response includes query rewrites for both the text query and the vector query.
234
231
235
-
## Debugging query rewrites
232
+
## Test query rewrites with debug
236
233
237
234
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.
238
235
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.
240
239
241
240
```json
242
241
{
@@ -256,7 +255,9 @@ You might observe that the response includes an empty array for the `text.rewrit
256
255
}
257
256
```
258
257
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.
0 commit comments