Compartir a través de


Prebuilt - Generate Answer

GenerateAnswer call to query text in documents.

POST {Endpoint}/qnamaker/v5.0-preview.2/generateAnswer
POST {Endpoint}/qnamaker/v5.0-preview.2/generateAnswer?stringIndexType={stringIndexType}

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).

stringIndexType
query

string

(Optional) Specifies the method used to interpret string offsets. Defaults to Text Elements (Graphemes) according to Unicode v8.0.0.

Request Header

Name Required Type Description
Ocp-Apim-Subscription-Key True

string

Request Body

Name Required Type Description
documents True

TextInput[]

Documents to be searched for given question.

question True

string

User question to query against the given documents.

language

string

(Optional) Language of the documents. This is ISO 639-1 representation of a language. For example, use "en" for English; "es" for Spanish etc. If not set, use "en" for English as default.

Responses

Name Type Description
200 OK

GenerateAnswerBatchResultItem[]

Prebuilt GenerateAnswer call response.

Other Status Codes

ErrorResponse

Error response.

Security

Ocp-Apim-Subscription-Key

Type: apiKey
In: header

Examples

Successful query

Sample request

POST {Endpoint}/qnamaker/v5.0-preview.2/generateAnswer


{
  "question": "qna maker and luis",
  "documents": [
    {
      "text": "Graphics  Surprise, surprise -- our 4K Envy 13 came with a discrete graphics card. While the Nvidia GeForce MX250 GPU isn't meant for demanding gaming",
      "id": "1"
    },
    {
      "text": "Graphics  Surprise, surprise -- our 4K Envy 13 came with a discrete graphics card. While the Nvidia GeForce MX250 GPU isn't meant for demanding gaming",
      "id": "2"
    }
  ],
  "language": "en"
}

Sample response

{
  "answers": [
    {
      "answer": "Graphics  Surprise, surprise -- our 4K Envy 13 came with a discrete graphics card. While the Nvidia GeForce MX250 GPU isn't meant for demanding gaming, it is a step up from integrated graphics as proven by comparing it to the UHD 620 GPU in the FHD model.",
      "answerSpan": {
        "endIndex": 82,
        "startIndex": 60,
        "text": "discrete graphics card",
        "score": 0
      },
      "answerEndIndex": 655,
      "answerStartIndex": 0,
      "id": 1,
      "score": 100
    }
  ]
}

Definitions

Name Description
AnswerSpan

Answer span object of QnA with respect to user's question.

Error

The error object. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.

ErrorCodeType

One of a server-defined set of error codes.

ErrorResponse

Error response. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.

GenerateAnswerBatchResultItem

Represents Prebuilt Answer Result.

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.

PrebuiltQuery

POST body schema to query the documents via Prebuilt Question Answering.

TextInput

List of documents to be queried over.

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.

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

ErrorCodeType

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

InnerErrorModel

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

Error

The error object.

GenerateAnswerBatchResultItem

Represents Prebuilt Answer Result.

Name Type Description
answer

string

Answer.

answerEndIndex

integer

End index of answer in document text.

answerSpan

AnswerSpan

Answer span object with respect to user's question.

answerStartIndex

integer

Start index of answer in document text.

id

string

Document Id.

score

number

Search result score.

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

InnerErrorModel

An object containing more specific information than the current object about the error.

PrebuiltQuery

POST body schema to query the documents via Prebuilt Question Answering.

Name Type Description
documents

TextInput[]

Documents to be searched for given question.

language

string

(Optional) Language of the documents. This is ISO 639-1 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 documents.

TextInput

List of documents to be queried over.

Name Type Description
id

string

Unique identifier for the document.

text

string

Text contents of the document