你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Question Answering - Get Answers
使用知识库回答指定的问题。
POST {Endpoint}/language/:query-knowledgebases?projectName={projectName}&deploymentName={deploymentName}&api-version=2021-10-01
URI 参数
名称 | 在 | 必需 | 类型 | 说明 |
---|---|---|---|---|
Endpoint
|
path | True |
string |
支持的认知服务终结点(例如 https://.api.cognitiveservices.azure.com). |
api-version
|
query | True |
string |
客户端 API 版本。 |
deployment
|
query | True |
string |
要使用的项目的特定部署的名称。 |
project
|
query | True |
string |
要使用的项目的名称。 |
请求头
名称 | 必需 | 类型 | 说明 |
---|---|---|---|
Ocp-Apim-Subscription-Key | True |
string |
请求正文
名称 | 类型 | 说明 |
---|---|---|
answerSpanRequest |
配置答案范围预测功能。 |
|
confidenceScoreThreshold |
number (double) minimum: 0maximum: 1 |
答案的最低阈值分数,值范围为 0 到 1。 |
context |
包含先前 QnA 信息的上下文对象。 |
|
filters |
根据给定的元数据列表和知识库源筛选 QnA。 |
|
includeUnstructuredSources |
boolean |
(可选)用于启用对非结构化源的查询的标志。 |
qnaId |
integer (int32) |
要从知识库中提取的确切 QnA ID,此字段优先于问题。 |
question |
string |
要查询知识库的用户问题。 |
rankerType |
要使用的排名器的类型。 |
|
top |
integer (int32) |
要为问题返回的最大答案数。 |
userId |
string |
用户的唯一标识符。 |
响应
名称 | 类型 | 说明 |
---|---|---|
200 OK |
从知识库获取答案的成功响应。 |
|
Other Status Codes |
错误响应。 |
安全性
Ocp-Apim-Subscription-Key
类型:
apiKey
在:
header
示例
Successful query
示例请求
POST {Endpoint}/language/:query-knowledgebases?projectName=proj1&deploymentName=production&api-version=2021-10-01
{
"question": "how long it takes to charge surface?",
"top": 3,
"userId": "sd53lsY=",
"confidenceScoreThreshold": 0.2,
"context": {
"previousQnaId": 9,
"previousUserQuery": "Where are QnA Maker quickstarts?"
},
"rankerType": "Default",
"filters": {
"metadataFilter": {
"metadata": [
{
"key": "category",
"value": "api"
},
{
"key": "editorial",
"value": "chitchat"
}
],
"logicalOperation": "AND"
},
"sourceFilter": [
"filename1.pdf",
"https://www.wikipedia.org/microsoft"
],
"logicalOperation": "AND"
},
"answerSpanRequest": {
"enable": true,
"confidenceScoreThreshold": 0.2,
"topAnswersWithSpan": 1
},
"includeUnstructuredSources": true
}
示例响应
{
"answers": [
{
"questions": [
"Power and charging"
],
"answer": "Power and charging**\n\nIt takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.\n\nYou can use the USB port on your Surface Pro 4 power supply to charge other devices, like a phone, while your Surface charges. The USB port on the power supply is only for charging, not for data transfer. If you want to use a USB device, plug it into the USB port on your Surface.",
"confidenceScore": 0.65,
"id": 20,
"source": "surface-pro-4-user-guide-EN.pdf",
"metadata": {
"category": "api",
"editorial": "chitchat"
},
"dialog": {
"isContextOnly": false,
"prompts": [
{
"displayOrder": 1,
"qnaId": 23,
"displayText": "prompt1"
},
{
"displayOrder": 2,
"qnaId": 36,
"displayText": "prompt2"
}
]
},
"answerSpan": {
"text": "two to four hours",
"confidenceScore": 0.3,
"offset": 33,
"length": 50
}
},
{
"questions": [
"Charge your Surface Pro 4"
],
"answer": "**Charge your Surface Pro 4**\n\n1. Connect the two parts of the power cord.\n\n2. Connect the power cord securely to the charging port.\n\n3. Plug the power supply into an electrical outlet.",
"confidenceScore": 0.32,
"id": 13,
"source": "surface-pro-4-user-guide-EN.pdf"
}
]
}
定义
名称 | 说明 |
---|---|
Answers |
用于查询知识库的参数。 |
Answer |
QnA 的应答范围对象。 |
Answers |
表示问题解答列表。 |
enable |
启用或禁用答案范围预测。 |
Error |
错误对象。 |
Error |
人工可读错误代码。 |
Error |
错误响应。 |
Inner |
人工可读错误代码。 |
Inner |
包含有关错误的更具体信息的对象。 根据Microsoft一个 API 指南 - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses。 |
Knowledge |
表示知识库答案。 |
Knowledge |
包含先前 QnA 信息的上下文对象。 |
Knowledge |
与答案关联的对话框。 |
Knowledge |
提示输入答案。 |
Logical |
设置为“OR”或“AND”以使用相应的逻辑作。 |
Metadata |
查找与给定元数据列表关联的 QnA。 |
Metadata |
用于为每个元数据提供键值对的对象。 |
Query |
基于知识库筛选。 |
Ranker |
要使用的排名器的类型。 |
Short |
配置答案范围预测功能。 |
AnswersOptions
用于查询知识库的参数。
名称 | 类型 | 说明 |
---|---|---|
answerSpanRequest |
配置答案范围预测功能。 |
|
confidenceScoreThreshold |
number (double) minimum: 0maximum: 1 |
答案的最低阈值分数,值范围为 0 到 1。 |
context |
包含先前 QnA 信息的上下文对象。 |
|
filters |
根据给定的元数据列表和知识库源筛选 QnA。 |
|
includeUnstructuredSources |
boolean |
(可选)用于启用对非结构化源的查询的标志。 |
qnaId |
integer (int32) |
要从知识库中提取的确切 QnA ID,此字段优先于问题。 |
question |
string |
要查询知识库的用户问题。 |
rankerType |
要使用的排名器的类型。 |
|
top |
integer (int32) |
要为问题返回的最大答案数。 |
userId |
string |
用户的唯一标识符。 |
AnswerSpan
QnA 的应答范围对象。
名称 | 类型 | 说明 |
---|---|---|
confidenceScore |
number (double) minimum: 0maximum: 1 |
答案范围的预测分数,值范围为 0 到 1。 |
length |
integer (int32) |
答案范围的长度。 |
offset |
integer (int32) |
答案范围与答案的开始偏移量。 |
text |
string |
答案范围的预测文本。 |
AnswersResult
表示问题解答列表。
名称 | 类型 | 说明 |
---|---|---|
answers |
表示“答案结果”列表。 |
enable
启用或禁用答案范围预测。
值 | 说明 |
---|---|
True |
Error
错误对象。
名称 | 类型 | 说明 |
---|---|---|
code |
服务器定义的错误代码集之一。 |
|
details |
Error[] |
导致此报告错误的特定错误的详细信息数组。 |
innererror |
包含与当前对象有关错误的更具体信息的对象。 |
|
message |
string |
错误的人工可读表示形式。 |
target |
string |
错误的目标。 |
ErrorCode
人工可读错误代码。
值 | 说明 |
---|---|
AzureCognitiveSearchIndexLimitReached | |
AzureCognitiveSearchIndexNotFound | |
AzureCognitiveSearchNotFound | |
AzureCognitiveSearchThrottling | |
Forbidden | |
InternalServerError | |
InvalidArgument | |
InvalidRequest | |
NotFound | |
OperationNotFound | |
ProjectNotFound | |
ServiceUnavailable | |
TooManyRequests | |
Unauthorized |
ErrorResponse
错误响应。
名称 | 类型 | 说明 |
---|---|---|
error |
错误对象。 |
InnerErrorCode
人工可读错误代码。
值 | 说明 |
---|---|
AzureCognitiveSearchNotFound | |
AzureCognitiveSearchThrottling | |
ExtractionFailure | |
InvalidParameterValue | |
InvalidRequest | |
KnowledgeBaseNotFound |
InnerErrorModel
包含有关错误的更具体信息的对象。 根据Microsoft一个 API 指南 - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses。
名称 | 类型 | 说明 |
---|---|---|
code |
服务器定义的错误代码集之一。 |
|
details |
object |
错误详细信息。 |
innererror |
包含与当前对象有关错误的更具体信息的对象。 |
|
message |
string |
错误信息。 |
target |
string |
错误目标。 |
KnowledgeBaseAnswer
表示知识库答案。
名称 | 类型 | 说明 |
---|---|---|
answer |
string |
回答文本。 |
answerSpan |
回答 QnA 与用户问题相关的跨度对象。 |
|
confidenceScore |
number (double) minimum: 0maximum: 1 |
答案置信度分数,值范围为 0 到 1。 |
dialog |
与答案关联的对话框。 |
|
id |
integer (int32) |
QnA 结果的 ID。 |
metadata |
object |
与答案关联的元数据,可用于对问题答案进行分类或筛选。 |
questions |
string[] |
与答案关联的问题列表。 |
source |
string |
QnA 结果的来源。 |
KnowledgeBaseAnswerContext
包含先前 QnA 信息的上下文对象。
名称 | 类型 | 说明 |
---|---|---|
previousQnaId |
integer (int32) |
上一轮热门答案结果 QnA ID。 |
previousUserQuery |
string |
以前的用户查询。 |
KnowledgeBaseAnswerDialog
与答案关联的对话框。
名称 | 类型 | 说明 |
---|---|---|
isContextOnly |
boolean |
如果提示仅与前面的问题相关,则进行标记。 如果为 true,请不要将此 QnA 作为没有上下文的查询的搜索结果;否则,如果为 false,则忽略上下文,并在搜索结果中包含此 QnA。 |
prompts |
与答案关联的提示列表。 |
KnowledgeBaseAnswerPrompt
提示输入答案。
名称 | 类型 | 说明 |
---|---|---|
displayOrder |
integer (int32) |
提示的索引 - 用于提示排序。 |
displayText |
string maxLength: 200 |
显示用于表示后续问题提示的文本。 |
qnaId |
integer (int32) |
对应于提示的 QnA ID。 |
LogicalOperationKind
设置为“OR”或“AND”以使用相应的逻辑作。
值 | 说明 |
---|---|
AND | |
OR |
MetadataFilter
查找与给定元数据列表关联的 QnA。
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
logicalOperation | AND |
用于联接元数据筛选器的作。 |
|
metadata |
用于为每个元数据提供键值对的对象。 |
MetadataRecord
用于为每个元数据提供键值对的对象。
名称 | 类型 | 说明 |
---|---|---|
key |
string |
QnA 中使用的元数据字典中的元数据密钥。 |
value |
string |
QnA 中使用的元数据字典中的元数据值。 |
QueryFilters
基于知识库筛选。
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
logicalOperation | AND |
用于将元数据筛选器与源筛选器联接的逻辑操作。 |
|
metadataFilter |
查找与给定元数据列表关联的 QnA。 |
||
sourceFilter |
string[] |
查找与知识库中任何给定源列表关联的 QnA。 |
RankerKind
要使用的排名器的类型。
值 | 说明 |
---|---|
Default |
默认排名器。 |
QuestionOnly |
仅询问排名器。 |
ShortAnswerOptions
配置答案范围预测功能。
名称 | 类型 | 说明 |
---|---|---|
confidenceScoreThreshold |
number (double) minimum: 0maximum: 1 |
包含答案范围所需的最小阈值分数,值范围为 0 到 1。 |
enable |
启用或禁用答案范围预测。 |
|
topAnswersWithSpan |
integer (int32) minimum: 1maximum: 10 |
要考虑从 1 到 10 的跨度预测的排名靠前的答案数。 |