Skip to content

Commit 5d16e6a

Browse files
authored
Merge pull request #252633 from HeidiSteen/heidist-freshness
[azure search] searchFields for early preview APIs is covered in reference docs
2 parents 6574f7b + 8518c7a commit 5d16e6a

File tree

2 files changed

+39
-119
lines changed

2 files changed

+39
-119
lines changed

articles/search/semantic-answers.md

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: HeidiSteen
88
ms.author: heidist
99
ms.service: cognitive-search
1010
ms.topic: conceptual
11-
ms.date: 08/14/2023
11+
ms.date: 09/22/2023
1212
---
1313

1414
# Return a semantic answer in Azure Cognitive Search
@@ -18,7 +18,9 @@ ms.date: 08/14/2023
1818
1919
When invoking [semantic ranking and captions](semantic-how-to-query-request.md), you can optionally extract content from the top-matching documents that "answers" the query directly. One or more answers can be included in the response, which you can then render on a search page to improve the user experience of your app.
2020

21-
In this article, learn how to request a semantic answer, unpack the response, and what content characteristics are most conducive to producing high-quality answers.
21+
A semantic answer is verbatim content in your search index that a reading comprehension model has recognized as an answer to the query posed in the request. It's not a generated answer. For guidance on a chat-style user interaction model that uses generative AI to compose answers from your content, see [Retrieval Augmented Generation (RAG)](retrieval-augmented-generation-overview.md).
22+
23+
In this article, learn how to request a semantic answer, unpack the response, and find out what content characteristics are most conducive to producing high-quality answers.
2224

2325
## Prerequisites
2426

@@ -28,27 +30,25 @@ All prerequisites that apply to [semantic queries](semantic-how-to-query-request
2830

2931
+ Query strings entered by the user must be recognizable as a question (what, where, when, how).
3032

31-
+ Search documents in the index must contain text having the characteristics of an answer, and that text must exist in one of the fields listed in the [semantic configuration](semantic-how-to-query-request.md#2---create-a-semantic-configuration). For example, given a query "what is a hash table", if none of the fields in the semantic configuration contain passages that include "A hash table is ...", then it's unlikely an answer will be returned.
33+
+ Search documents in the index must contain text having the characteristics of an answer, and that text must exist in one of the fields listed in the [semantic configuration](semantic-how-to-query-request.md#2---create-a-semantic-configuration). For example, given a query "what is a hash table", if none of the fields in the semantic configuration contain passages that include "A hash table is ...", then it's unlikely an answer is returned.
34+
35+
> [!NOTE]
36+
> Starting in 2021-04-30-Preview, in [Create or Update Index (Preview)](/rest/api/searchservice/preview-api/create-or-update-index) requests, a `"semanticConfiguration"` is required for specifying input fields for semantic ranking.
3237
3338
## What is a semantic answer?
3439

3540
A semantic answer is a substructure of a [semantic query response](semantic-how-to-query-request.md). It consists of one or more verbatim passages from a search document, formulated as an answer to a query that looks like a question. To return an answer, phrases or sentences must exist in a search document that have the language characteristics of an answer, and the query itself must be posed as a question.
3641

37-
Cognitive Search uses a machine reading comprehension model to pick the best answer. The model produces a set of potential answers from the available content, and when it reaches a high enough confidence level, it will propose one as an answer.
42+
Cognitive Search uses a machine reading comprehension model to recognize and pick the best answer. The model produces a set of potential answers from the available content, and when it reaches a high enough confidence level, it proposes one as an answer.
3843

3944
Answers are returned as an independent, top-level object in the query response payload that you can choose to render on search pages, along side search results. Structurally, it's an array element within the response consisting of text, a document key, and a confidence score.
4045

4146
<a name="query-params"></a>
4247

4348
## Formulate a REST query for "answers"
4449

45-
The approach for listing fields in priority order has changed, with "semanticConfiguration" replacing "searchFields". If you're currently using "searchFields", update your code to the 2021-04-30-Preview API version and use "semanticConfiguration" instead.
46-
47-
### [**Semantic Configuration (recommended)**](#tab/semanticConfiguration)
48-
49-
To return a semantic answer, the query must have the semantic "queryType", "queryLanguage", "semanticConfiguration", and the "answers" parameters. Specifying these parameters doesn't guarantee an answer, but the request must include them for answer processing to occur.
50+
To return a semantic answer, the query must have the semantic `"queryType"`, `"queryLanguage"`, `"semanticConfiguration"`, and the `"answers"` parameters. Specifying these parameters doesn't guarantee an answer, but the request must include them for answer processing to occur.
5051

51-
The "semanticConfiguration" parameter is required. It's defined in a search index, and then referenced in a query, as shown below.
5252

5353
```json
5454
{
@@ -64,52 +64,23 @@ The "semanticConfiguration" parameter is required. It's defined in a search inde
6464

6565
+ A query string must not be null and should be formulated as question.
6666

67-
+ "queryType" must be set to "semantic.
68-
69-
+ "queryLanguage" must be one of the values from the [supported languages list (REST API)](/rest/api/searchservice/preview-api/search-documents#queryLanguage).
70-
71-
+ A "semanticConfiguration" determines which string fields provide tokens to the extraction model. The same fields that produce captions also produce answers. See [Create a semantic configuration](semantic-how-to-query-request.md#2---create-a-semantic-configuration) for details.
72-
73-
+ For "answers", parameter construction is `"answers": "extractive"`, where the default number of answers returned is one. You can increase the number of answers by adding a `count` as shown in the above example, up to a maximum of 10. Whether you need more than one answer depends on the user experience of your app, and how you want to render results.
67+
+ `"queryType"` must be set to "semantic.
7468

75-
### [**searchFields**](#tab/searchFields)
69+
+ `"queryLanguage"` must be one of the values from the [supported languages list (REST API)](/rest/api/searchservice/preview-api/search-documents#queryLanguage).
7670

77-
To return a semantic answer, the query must have the semantic "queryType", "queryLanguage", "searchFields", and the "answers" parameter. Specifying the "answers" parameter doesn't guarantee that you'll get an answer, but the request must include this parameter if answer processing is to be invoked at all.
71+
+ A `"semanticConfiguration"` determines which string fields provide tokens to the extraction model. The same fields that produce captions also produce answers. See [Create a semantic configuration](semantic-how-to-query-request.md#2---create-a-semantic-configuration) for details.
7872

79-
The "searchFields" parameter is crucial to returning a high-quality answer, both in terms of content and order (see below).
80-
81-
```json
82-
{
83-
"search": "how do clouds form",
84-
"queryType": "semantic",
85-
"queryLanguage": "en-us",
86-
"searchFields": "title,locations,content",
87-
"answers": "extractive|count-3",
88-
"count": "true"
89-
}
90-
```
91-
92-
+ A query string must not be null and should be formulated as question.
93-
94-
+ "queryType" must be set to "semantic.
95-
96-
+ "queryLanguage" must be one of the values from the [supported languages list (REST API)](/rest/api/searchservice/preview-api/search-documents#queryLanguage).
97-
98-
+ "searchFields" determines which string fields provide tokens to the extraction model. The same fields that produce captions also produce answers. See [Set searchFields](semantic-how-to-query-request.md#2b---use-searchfields-for-field-prioritization) for details.
99-
100-
+ For "answers", parameter construction is `"answers": "extractive"`, where the default number of answers returned is one. You can increase the number of answers by adding a `count` as shown in the above example, up to a maximum of 10. Whether you need more than one answer depends on the user experience of your app, and how you want to render results.
101-
102-
---
73+
+ For `"answers"`, parameter construction is `"answers": "extractive"`, where the default number of answers returned is one. You can increase the number of answers by adding a `count` as shown in the above example, up to a maximum of 10. Whether you need more than one answer depends on the user experience of your app, and how you want to render results.
10374

10475
## Unpack an "answer" from the response
10576

106-
Answers are provided in the `"@search.answers"` array, which appears first in the query response. Each answer in the array will include:
77+
Answers are provided in the `"@search.answers"` array, which appears first in the query response. Each answer in the array includes:
10778

10879
+ Document key
10980
+ Text or content of the answer, in plain text or with formatting
11081
+ Confidence score
11182

112-
If an answer is indeterminate, the response will show up as `"@search.answers": []`. The answers array is followed by the value array, which is the standard response in a semantic query.
83+
If an answer is indeterminate, the response shows up as `"@search.answers": []`. The answers array is followed by the value array, which is the standard response in a semantic query.
11384

11485
Given the query "how do clouds form", the following example illustrates an answer:
11586

@@ -146,7 +117,7 @@ Given the query "how do clouds form", the following example illustrates an answe
146117

147118
```
148119

149-
When designing a search results page that includes answers, be sure to handle cases where answers are not found.
120+
When designing a search results page that includes answers, be sure to handle cases where answers aren't found.
150121

151122
Within @search.answers:
152123

@@ -156,7 +127,7 @@ Within @search.answers:
156127

157128
By default, highlights are styled as `<em>`, which you can override using the existing highlightPreTag and highlightPostTag parameters. As noted elsewhere, the substance of an answer is verbatim content from a search document. The extraction model looks for characteristics of an answer to find the appropriate content, but doesn't compose new language in the response.
158129

159-
+ **"score"** is a confidence score that reflects the strength of the answer. If there are multiple answers in the response, this score is used to determine the order. Top answers and top captions can be derived from different search documents, where the top answer originates from one document, and the top caption from another, but in general you will see the same documents in the top positions within each array.
130+
+ **"score"** is a confidence score that reflects the strength of the answer. If there are multiple answers in the response, this score is used to determine the order. Top answers and top captions can be derived from different search documents, where the top answer originates from one document, and the top caption from another, but in general the same documents appear in the top positions within each array.
160131

161132
Answers are followed by the **"value"** array, which always includes scores, captions, and any fields that are retrievable by default. If you specified the select parameter, the "value" array is limited to the fields that you specified. See [Configure semantic ranking](semantic-how-to-query-request.md) for details.
162133

0 commit comments

Comments
 (0)