Question Answering - Get Answers From Text
Answers the specified question using the provided text in the body.
POST {Endpoint}/language/:query-text?api-version=2023-04-01
URI Parameters
Name | In | Required | Type | Description |
---|---|---|---|---|
Endpoint
|
path | True |
string (uri) |
Supported Cognitive Services endpoint (e.g., https://<resource-name>.api.cognitiveservices.azure.com). |
api-version
|
query | True |
string minLength: 1 |
The API version to use for this operation. |
Request Body
Name | Required | Type | Description |
---|---|---|---|
question | True |
string |
User question to query against the given text records. |
records | True |
Text records to be searched for given question. |
|
language |
string |
Language of the text records. This is BCP-47 representation of a language. For example, use "en" for English; "es" for Spanish etc. If not set, use "en" for English as default. |
|
stringIndexType |
Specifies the method used to interpret string offsets. Defaults to Text Elements (Graphemes) according to Unicode v8.0.0. For additional information see https://aka.ms/text-analytics-offsets. |
Responses
Name | Type | Description |
---|---|---|
200 OK |
The request has succeeded. |
|
Other Status Codes |
An unexpected error response. Headers x-ms-error-code: string |
Security
Ocp-Apim-Subscription-Key
Type:
apiKey
In:
header
OAuth2Auth
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
Name | Description |
---|---|
https://cognitiveservices.azure.com/.default |
Examples
Successful query
Sample request
POST {Endpoint}/language/:query-text?api-version=2023-04-01
{
"question": "how long it takes to charge surface?",
"records": [
{
"id": "1",
"text": "Power and charging. It 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."
},
{
"id": "2",
"text": "You 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."
}
],
"language": "en"
}
Sample response
{
"answers": [
{
"answer": "Power and charging. It 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.",
"answerSpan": {
"confidenceScore": 0,
"length": 45,
"offset": 28,
"text": "two to four hours"
},
"confidenceScore": 0.93,
"id": "1",
"length": 224,
"offset": 0
},
{
"answer": "It 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.",
"answerSpan": {
"confidenceScore": 0,
"length": 25,
"offset": 8,
"text": "two to four hours"
},
"confidenceScore": 0.92,
"id": "1",
"length": 224,
"offset": 20
},
{
"answer": "It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.",
"answerSpan": null,
"confidenceScore": 0.05,
"id": "1",
"length": 244,
"offset": 110
}
]
}
Definitions
Name | Description |
---|---|
Answers |
The question and text record parameters to answer. |
Answers |
Represents the answer results. |
Answer |
Answer span object of QnA. |
Error |
The error response object returned when the service encounters some errors during processing the request. |
Error |
Human-readable error code. |
Error |
Error response. |
Inner |
Human-readable error code. |
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. |
String |
Specifies the method used to interpret string offsets. Defaults to Text Elements (Graphemes) according to Unicode v8.0.0. For additional information see https://aka.ms/text-analytics-offsets. |
Text |
Represents answer result. |
Text |
Represent input text record to be queried. |
AnswersFromTextOptions
The question and text record parameters to answer.
Name | Type | Default value | Description |
---|---|---|---|
language |
string |
Language of the text records. This is BCP-47 representation of a language. For example, use "en" for English; "es" for Spanish etc. If not set, use "en" for English as default. |
|
question |
string |
User question to query against the given text records. |
|
records |
Text records to be searched for given question. |
||
stringIndexType | TextElements_v8 |
Specifies the method used to interpret string offsets. Defaults to Text Elements (Graphemes) according to Unicode v8.0.0. For additional information see https://aka.ms/text-analytics-offsets. |
AnswersFromTextResult
Represents the answer results.
Name | Type | Description |
---|---|---|
answers |
Represents the answer results. |
AnswerSpan
Answer span object of QnA.
Name | Type | Description |
---|---|---|
confidenceScore |
number (double) minimum: 0maximum: 1 |
Predicted score of answer span, value ranges from 0 to 1. |
length |
integer (int32) |
The length of the answer span. |
offset |
integer (int32) |
The answer span offset from the start of answer. |
text |
string |
Predicted text of answer span. |
Error
The error response object returned when the service encounters some errors during processing the request.
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. |
ErrorCode
Human-readable error code.
Value | Description |
---|---|
InvalidRequest |
Invalid request error |
InvalidArgument |
Invalid argument error |
Unauthorized |
Unauthorized access error |
Forbidden |
Forbidden access error |
NotFound |
Not found error |
ProjectNotFound |
Project not found error |
OperationNotFound |
Operation not found error |
AzureCognitiveSearchNotFound |
Azure Cognitive Search not found error |
AzureCognitiveSearchIndexNotFound |
Azure Cognitive Search index not found error |
TooManyRequests |
Too many requests error |
AzureCognitiveSearchThrottling |
Azure Cognitive Search throttling error |
AzureCognitiveSearchIndexLimitReached |
Azure Cognitive Search index limit reached error |
InternalServerError |
Internal server error |
ServiceUnavailable |
Service unavailable error |
Timeout |
Timeout error |
QuotaExceeded |
Quota exceeded error |
Conflict |
Conflict error |
Warning |
Warning error |
ErrorResponse
Error response.
Name | Type | Description |
---|---|---|
error |
The error object. |
InnerErrorCode
Human-readable error code.
Value | Description |
---|---|
InvalidRequest |
Invalid request error |
InvalidParameterValue |
Invalid parameter value error |
KnowledgeBaseNotFound |
Knowledge base not found error |
AzureCognitiveSearchNotFound |
Azure Cognitive Search not found error |
AzureCognitiveSearchThrottling |
Azure Cognitive Search throttling error |
ExtractionFailure |
Extraction failure error |
InvalidRequestBodyFormat |
Invalid request body format error |
EmptyRequest |
Empty request error |
MissingInputDocuments |
Missing input documents error |
InvalidDocument |
Invalid document error |
ModelVersionIncorrect |
Model version incorrect error |
InvalidDocumentBatch |
Invalid document batch error |
UnsupportedLanguageCode |
Unsupported language code error |
InvalidCountryHint |
Invalid country hint error |
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 |
One of a server-defined set of error codes. |
|
details |
object |
Error details. |
innererror |
An object containing more specific information than the current object about the error. |
|
message |
string |
Error message. |
target |
string |
Error target. |
StringIndexType
Specifies the method used to interpret string offsets. Defaults to Text Elements (Graphemes) according to Unicode v8.0.0. For additional information see https://aka.ms/text-analytics-offsets.
Value | Description |
---|---|
TextElements_v8 |
Returned offset and length values will correspond to TextElements (Graphemes and Grapheme clusters) confirming to the Unicode 8.0.0 standard. Use this option if your application is written in .Net Framework or .Net Core and you will be using StringInfo. |
UnicodeCodePoint |
Returned offset and length values will correspond to Unicode code points. Use this option if your application is written in a language that support Unicode, for example Python. |
Utf16CodeUnit |
Returned offset and length values will correspond to UTF-16 code units. Use this option if your application is written in a language that support Unicode, for example Java, JavaScript. |
TextAnswer
Represents answer result.
Name | Type | Description |
---|---|---|
answer |
string |
Answer. |
answerSpan |
Answer span object with respect to user's question. |
|
confidenceScore |
number (double) minimum: 0maximum: 1 |
answer confidence score, value ranges from 0 to 1. |
id |
string |
record ID. |
length |
integer (int32) |
The length of the sentence. |
offset |
integer (int32) |
The sentence offset from the start of the document. |
TextDocument
Represent input text record to be queried.
Name | Type | Description |
---|---|---|
id |
string |
Unique identifier for the text record. |
text |
string |
Text contents of the record. |