Knowledgebase - Generate Answer
GenerateAnswer call to query knowledgebase (QnA Maker Managed).
POST {Endpoint}/qnamaker/v5.0-preview.2/knowledgebases/{kbId}/generateAnswer
URI Parameters
Name | In | Required | Type | Description |
---|---|---|---|---|
Endpoint
|
path | True |
string |
Supported Cognitive Services endpoint (e.g., https://< qnamaker-resource-name >.api.cognitiveservices.azure.com). |
kb
|
path | True |
string |
Knowledgebase id. |
Request Header
Name | Required | Type | Description |
---|---|---|---|
Ocp-Apim-Subscription-Key | True |
string |
Request Body
Name | Type | Description |
---|---|---|
answerSpanRequest |
To configure Answer span prediction feature. |
|
context |
Context object with previous QnA's information. |
|
includeUnstructuredSources |
boolean |
Optional Flag to enable Query over Unstructured Sources. |
isTest |
boolean |
Query against the test index. |
qnaId |
string |
Exact qnaId to fetch from the knowledgebase, this field takes priority over question. |
question |
string |
User question to query against the knowledge base. |
rankerType |
string |
Optional field. Set to 'QuestionOnly' for using a question only Ranker. |
scoreThreshold |
number |
Minimum threshold score for answers. |
strictFilters |
Find QnAs that are associated with the given list of metadata. |
|
strictFiltersCompoundOperationType |
Optional field. Set to 'OR' for using OR operation for strict filters. |
|
top |
integer |
Max number of answers to be returned for the question. |
userId |
string |
Unique identifier for the user. |
Responses
Name | Type | Description |
---|---|---|
200 OK |
GenerateAnswer call response. |
|
Other Status Codes |
Error response. |
Security
Ocp-Apim-Subscription-Key
Type:
apiKey
In:
header
Examples
Successful query
Sample request
POST {Endpoint}/qnamaker/v5.0-preview.2/knowledgebases/9d091697-fb8c-4ed5-9ac0-35bf8273bfff/generateAnswer
{
"question": "How much time it takes to complete quickstart guide?",
"top": 6,
"isTest": true,
"context": {
"previousQnaId": 9,
"previousUserQuery": "Where are QnA Maker quickstarts?"
},
"scoreThreshold": 20,
"strictFilters": [
{
"name": "category",
"value": "api"
}
],
"answerSpanRequest": {
"enable": true,
"scoreThreshold": 25,
"topAnswersWithSpan": 1
},
"userId": "sd53lsY="
}
Sample response
{
"answers": [
{
"questions": [
"Complete a quickstart"
],
"answer": "We offer quickstarts in most popular programming languages, each designed to teach you basic design patterns, and have you running code in less than 10 minutes. See the following list for the quickstart for each feature.\n\n* [Get started with the LUIS client library](https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/quickstarts/quickstart-sdk)\n\n* [Get started with the LUIS portal](https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/quickstarts/create-publish-knowledge-base)\n\n* [Get started with the LUIS REST APis](https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/quickstarts/quickstart-rest-curl)",
"score": 46.11,
"id": 9,
"source": "Editorial",
"metadata": [],
"context": {
"isContextOnly": false,
"prompts": []
},
"answerSpan": {
"text": "less than 10 minutes",
"score": 54.92,
"startIndex": 139,
"endIndex": 159
}
}
]
}
Definitions
Name | Description |
---|---|
Answer |
Answer span object of QnA with respect to user's question. |
Answer |
To configure Answer span prediction feature. |
Context |
Context associated with Qna to be updated. |
Error |
The error object. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. |
Error |
One of a server-defined set of error codes. |
Error |
Error response. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. |
Inner |
An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. |
MetadataDTO |
Name - value pair of metadata. |
PromptDTO |
Prompt for an answer. |
Qna |
QnADTO - Either QnaId or QnADTO needs to be present in a PromptDTO object |
Qn |
Represents Search Result. |
Qn |
Represents List of Question Answers. |
QueryDTO |
POST body schema to query the knowledgebase. |
Strict |
Optional field. Set to 'OR' for using OR operation for strict filters. |
AnswerSpan
Answer span object of QnA with respect to user's question.
Name | Type | Description |
---|---|---|
endIndex |
integer |
End index of answer span in answer. |
score |
number |
Predicted score of answer span. |
startIndex |
integer |
Start index of answer span in answer. |
text |
string |
Predicted text of answer span. |
AnswerSpanRequest
To configure Answer span prediction feature.
Name | Type | Description |
---|---|---|
enable |
boolean |
Enable or Disable Answer Span prediction. |
scoreThreshold |
number |
Minimum threshold score required to include an answer span. |
topAnswersWithSpan |
integer |
Number of Top answers to be considered for span prediction. |
Context
Context associated with Qna to be updated.
Name | Type | Description |
---|---|---|
isContextOnly |
boolean |
To mark if a prompt is relevant only with a previous question or not. true - Do not include this QnA as search result for queries without context false - ignores context and includes this QnA in search result |
promptsToAdd |
List of prompts to be added to the qna. |
|
promptsToDelete |
integer[] |
List of prompts associated with qna to be deleted |
Error
The error object. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.
Name | Type | Description |
---|---|---|
code |
One of a server-defined set of error codes. |
|
details |
Error[] |
An array of details about specific errors that led to this reported error. |
innerError |
An object containing more specific information than the current object about the error. |
|
message |
string |
A human-readable representation of the error. |
target |
string |
The target of the error. |
ErrorCodeType
One of a server-defined set of error codes.
Name | Type | Description |
---|---|---|
BadArgument |
string |
|
EndpointKeysError |
string |
|
ExtractionFailure |
string |
|
Forbidden |
string |
|
KbNotFound |
string |
|
NotFound |
string |
|
OperationNotFound |
string |
|
QnaRuntimeError |
string |
|
QuotaExceeded |
string |
|
SKULimitExceeded |
string |
|
ServiceError |
string |
|
Unauthorized |
string |
|
Unspecified |
string |
|
ValidationFailure |
string |
ErrorResponse
Error response. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.
Name | Type | Description |
---|---|---|
error |
The error object. |
InnerErrorModel
An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.
Name | Type | Description |
---|---|---|
code |
string |
A more specific error code than was provided by the containing error. |
innerError |
An object containing more specific information than the current object about the error. |
MetadataDTO
Name - value pair of metadata.
Name | Type | Description |
---|---|---|
name |
string |
Metadata name. |
value |
string |
Metadata value. |
PromptDTO
Prompt for an answer.
Name | Type | Description |
---|---|---|
displayOrder |
integer |
Index of the prompt - used in ordering of the prompts |
displayText |
string |
Text displayed to represent a follow up question prompt |
qna |
QnADTO - Either QnaId or QnADTO needs to be present in a PromptDTO object |
|
qnaId |
integer |
Qna id corresponding to the prompt - if QnaId is present, QnADTO object is ignored. |
Qna
QnADTO - Either QnaId or QnADTO needs to be present in a PromptDTO object
Name | Type | Description |
---|---|---|
answer |
string |
Answer text |
context |
Context of a QnA |
|
id |
integer |
Unique id for the Q-A. |
lastUpdatedTimestamp |
string |
Timestamp when the QnA was last updated. |
metadata |
List of metadata associated with the answer. |
|
questions |
string[] |
List of questions associated with the answer. |
source |
string |
Source from which Q-A was indexed. eg. https://docs.microsoft.com/en-us/azure/cognitive-services/QnAMaker/FAQs |
QnASearchResult
Represents Search Result.
Name | Type | Description |
---|---|---|
answer |
string |
Answer. |
answerSpan |
Answer span object of QnA with respect to user's question. |
|
context |
Context object of the QnA |
|
id |
integer |
Id of the QnA result. |
metadata |
List of metadata. |
|
questions |
string[] |
List of questions. |
score |
number |
Search result score. |
source |
string |
Source of QnA result. |
QnASearchResultList
Represents List of Question Answers.
Name | Type | Description |
---|---|---|
answers |
Represents Search Result list. |
QueryDTO
POST body schema to query the knowledgebase.
Name | Type | Description |
---|---|---|
answerSpanRequest |
To configure Answer span prediction feature. |
|
context |
Context object with previous QnA's information. |
|
includeUnstructuredSources |
boolean |
Optional Flag to enable Query over Unstructured Sources. |
isTest |
boolean |
Query against the test index. |
qnaId |
string |
Exact qnaId to fetch from the knowledgebase, this field takes priority over question. |
question |
string |
User question to query against the knowledge base. |
rankerType |
string |
Optional field. Set to 'QuestionOnly' for using a question only Ranker. |
scoreThreshold |
number |
Minimum threshold score for answers. |
strictFilters |
Find QnAs that are associated with the given list of metadata. |
|
strictFiltersCompoundOperationType |
Optional field. Set to 'OR' for using OR operation for strict filters. |
|
top |
integer |
Max number of answers to be returned for the question. |
userId |
string |
Unique identifier for the user. |
StrictFiltersCompoundOperationType
Optional field. Set to 'OR' for using OR operation for strict filters.
Name | Type | Description |
---|---|---|
AND |
string |
|
OR |
string |