Skip to content

Commit 2722c98

Browse files
committed
fix semantic ranker documentation
1 parent 8b0dfe9 commit 2722c98

File tree

1 file changed

+68
-11
lines changed

1 file changed

+68
-11
lines changed

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

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,27 @@ A few query capabilities bypass relevance scoring, which makes them incompatible
5151

5252
## Set up the query
5353

54-
In this step, add parameters to the query request. To be successful, your query should be full text search (using the `search` parameter to pass in a string) or a vector query, and the index should contain text fields with rich semantic content and a semantic configuration.
54+
By default, queries do not use semantic ranking. To use semantic ranking, two different parameters may be used. Each parameter supports a different set of scenarios:
55+
56+
1. Specify `queryType` as `"semantic"`:
57+
+ [Text search](search-lucene-query-architecture.md) with a simple plain text query. Empty queries result in no semantic ranking being applied to the results.
58+
+ [Hybrid search](hybrid-search-overview.md).
59+
+ [Simple](query-simple-syntax.md) or [full](query-lucene-syntax.md) syntax cannot be used.
60+
1. Specify `semanticQuery`:
61+
+ [Text search](search-lucene-query-architecture.md) using the [simple](query-simple-syntax.md) or [full](query-lucene-syntax.md) syntax.
62+
+ [Vector search](vector-search-overview.md).
63+
+ [Hybrid search](hybrid-search-overview.md).
64+
+ The query specified for `semanticQuery` must be a simple plain text query. Empty queries are not supported.
65+
66+
The following table illustrates the supported scenarios depending on which semantic ranking parameter is used:
67+
| Semantic Ranker Parameter | Plain text search | [Simple text search syntax](query-simple-syntax.md) | [Full text search syntax](query-lucene-syntax.md) | [Vector search](vector-search-overview.md) | [Hybrid Search](hybrid-search-overview.md) | [Semantic answers](semantic-answers.md) and captions |
68+
|-|-|-|-|-|-|-|
69+
| Set "queryType" to "semantic" |||||||
70+
| Set "semanticQuery"<sup>1</sup> |||||||
71+
72+
<sup>1</sup> "semanticQuery" is not supported in the portal [search explorer](search-explorer.md).
73+
74+
Regardless of the parameter chosen, the index should contain text fields with rich semantic content and a [semantic configuration](semantic-how-to-configure.md).
5575

5676
### [**Azure portal**](#tab/portal-query)
5777

@@ -67,11 +87,11 @@ In this step, add parameters to the query request. To be successful, your query
6787

6888
1. Enter a query, such as "historic hotel with good food", and select **Search**.
6989

70-
1. Alternatively, select **JSON view** and paste definitions into the query editor:
90+
1. Alternatively, select **JSON view** and paste definitions into the query editor. The portal does not support using `"semanticQuery"`, so setting `"queryType"` to `"semantic"` is required:
7191

7292
:::image type="content" source="./media/semantic-search-overview/semantic-portal-json-query.png" alt-text="Screenshot showing JSON query syntax in the Azure portal." border="true":::
7393

74-
Here's a JSON example that you can paste into the view:
94+
JSON example for setting query type to semantic that you can paste into the view:
7595

7696
```json
7797
{
@@ -81,7 +101,6 @@ In this step, add parameters to the query request. To be successful, your query
81101
"semanticConfiguration": "my-semantic-config",
82102
"captions": "extractive|highlight-true",
83103
"answers": "extractive|count-3",
84-
"queryLanguage": "en-us",
85104
"highlightPreTag": "<strong>",
86105
"highlightPostTag": "</strong>",
87106
"select": "HotelId,HotelName,Description,Category"
@@ -92,31 +111,30 @@ In this step, add parameters to the query request. To be successful, your query
92111

93112
Use [Search Documents](/rest/api/searchservice/documents/search-post) to formulate the request.
94113

95-
A response includes an `@search.rerankerScore` automatically. If you want captions or answers in the response, add captions and answers to the request.
114+
A response includes an `@search.rerankerScore` automatically. If you want captions or answers in the response, enable semantic ranking by setting `"queryType"` to `"semantic"` or setting ``"semanticQuery"` and adding captions and answers to the request
96115

97116
The following example in this section uses the [hotels-sample-index](search-get-started-portal.md) to demonstrate semantic ranking with semantic answers and captions.
98117

99-
1. Paste the following request into a web client as a template. Replace `search-service-name` with your search service name and replace `hotels-sample-index` if you have a different index name.
118+
If you want to set `"queryType"` to `"semantic"`, paste the following request into a web client as a template. Replace `search-service-name` with your search service name and replace `hotels-sample-index` if you have a different index name.
100119

101120
```http
102-
POST https://[search-service-name].search.windows.net/indexes/hotels-sample-index/docs/search?api-version=2024-07-01     
121+
POST https://[search-service-name].search.windows.net/indexes/hotels-sample-index/docs/search?api-version=2024-07-01
103122
{
104123
"search": "interesting hotel with restaurant on site and cozy lobby or shared area",
105124
"count": true,
106125
"queryType": "semantic",
107126
"semanticConfiguration": "semantic-config",
108127
"captions": "extractive|highlight-true",
109128
"answers": "extractive|count-3",
110-
"queryLanguage": "en-us",
111129
"highlightPreTag": "<strong>",
112130
"highlightPostTag": "</strong>",
113131
"select": "HotelId,HotelName,Description,Category"
114132
}
115133
```
116134

117-
1. Set "queryType" to "semantic".
135+
1. Set `"queryType"` to `"semantic"`.
118136

119-
1. Set "search" to a full text search query. Your search string can support either the [simple syntax](query-simple-syntax.md) or [full Lucene syntax](query-lucene-syntax.md). Semantic ranking is an extension of full text search, so while "search" isn't required, you won't get an expected outcome if it's an empty search (`"search": "*"`).
137+
1. Set "search" to a simple plain text query. Since the "queryType" is set to semantic, neither [simple syntax](query-simple-syntax.md) or [full Lucene syntax](query-lucene-syntax.md) are supported. Supplying `*` or an empty string results in no semantic ranking being applied to the query.
120138

121139
1. Set "semanticConfiguration" to a [predefined semantic configuration](semantic-how-to-configure.md) that's embedded in your index.
122140

@@ -136,6 +154,29 @@ The following example in this section uses the [hotels-sample-index](search-get-
136154

137155
1. Send the request to execute the query and return results.
138156

157+
If you want to use "semanticQuery" in order to use [vector search](vector-search-overview.md), [simple text syntax](query-simple-syntax.md), or [full text syntax](query-lucene-syntax.md), adjust your request to the following:
158+
159+
```http
160+
POST https://[search-service-name].search.windows.net/indexes/hotels-sample-index/docs/search?api-version=2024-07-01
161+
{
162+
"search": "Description:breakfast",
163+
"semanticQuery": "interesting hotel with restaurant on site and cozy lobby or shared area",
164+
"count": true,
165+
"queryType": "full",
166+
"semanticConfiguration": "semantic-config",
167+
"captions": "extractive|highlight-true",
168+
"answers": "extractive|count-3",
169+
"highlightPreTag": "<strong>",
170+
"highlightPostTag": "</strong>",
171+
"select": "HotelId,HotelName,Description,Category"
172+
}
173+
```
174+
175+
1. Set `"queryType"` to the search syntax you are using, either [simple](query-simple-syntax.md) or [full](query-full-syntax.md)
176+
177+
1. Set `"semanticQuery"` to the simple plain text query you want to use for semantic ranking. Empty queries are not supported.
178+
179+
139180
### [**.NET SDK**](#tab/dotnet-query)
140181

141182
Use QueryType or SemanticQuery to invoke semantic ranker on a semantic query. The [following example](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/search/Azure.Search.Documents/samples/Sample08_SemanticSearch.md) is from the Azure SDK team.
@@ -151,7 +192,6 @@ SearchResults<Hotel> response = await searchClient.SearchAsync<Hotel>(
151192
QueryCaption = new(QueryCaptionType.Extractive),
152193
QueryAnswer = new(QueryAnswerType.Extractive)
153194
},
154-
QueryLanguage = QueryLanguage.EnUs,
155195
QueryType = SearchQueryType.Semantic
156196
});
157197

@@ -187,6 +227,23 @@ await foreach (SearchResult<Hotel> result in response.GetResultsAsync())
187227
Console.WriteLine($"Total number of search results:{count}");
188228
```
189229

230+
To use `"semanticQuery"` instead of setting `"queryType"` to `"semantic"`, the search code snippet can be replaced with the following code snippet:
231+
232+
```csharp
233+
SearchResults<Hotel> response = await searchClient.SearchAsync<Hotel>(
234+
"Luxury hotel",
235+
new SearchOptions
236+
{
237+
SemanticSearch = new()
238+
{
239+
SemanticConfigurationName = "my-semantic-config",
240+
QueryCaption = new(QueryCaptionType.Extractive),
241+
QueryAnswer = new(QueryAnswerType.Extractive),
242+
SemanticQuery = "Is there any hotel located on the main commercial artery of the city in the heart of New York?"
243+
}
244+
});
245+
```
246+
190247
---
191248

192249
## Evaluate the response

0 commit comments

Comments
 (0)