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
Copy file name to clipboardExpand all lines: articles/search/semantic-answers.md
+18-47Lines changed: 18 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ author: HeidiSteen
8
8
ms.author: heidist
9
9
ms.service: cognitive-search
10
10
ms.topic: conceptual
11
-
ms.date: 08/14/2023
11
+
ms.date: 09/22/2023
12
12
---
13
13
14
14
# Return a semantic answer in Azure Cognitive Search
@@ -18,7 +18,9 @@ ms.date: 08/14/2023
18
18
19
19
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.
20
20
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.
22
24
23
25
## Prerequisites
24
26
@@ -28,27 +30,25 @@ All prerequisites that apply to [semantic queries](semantic-how-to-query-request
28
30
29
31
+ Query strings entered by the user must be recognizable as a question (what, where, when, how).
30
32
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.
32
37
33
38
## What is a semantic answer?
34
39
35
40
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.
36
41
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.
38
43
39
44
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.
40
45
41
46
<aname="query-params"></a>
42
47
43
48
## Formulate a REST query for "answers"
44
49
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.
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.
50
51
51
-
The "semanticConfiguration" parameter is required. It's defined in a search index, and then referenced in a query, as shown below.
52
52
53
53
```json
54
54
{
@@ -64,52 +64,23 @@ The "semanticConfiguration" parameter is required. It's defined in a search inde
64
64
65
65
+ A query string must not be null and should be formulated as question.
66
66
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.
74
68
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).
76
70
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.
78
72
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.
103
74
104
75
## Unpack an "answer" from the response
105
76
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:
107
78
108
79
+ Document key
109
80
+ Text or content of the answer, in plain text or with formatting
110
81
+ Confidence score
111
82
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.
113
84
114
85
Given the query "how do clouds form", the following example illustrates an answer:
115
86
@@ -146,7 +117,7 @@ Given the query "how do clouds form", the following example illustrates an answe
146
117
147
118
```
148
119
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.
150
121
151
122
Within @search.answers:
152
123
@@ -156,7 +127,7 @@ Within @search.answers:
156
127
157
128
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.
158
129
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.
160
131
161
132
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.
0 commit comments