Knowledgebase - Create

Asynchronous operation to create a new knowledgebase.

POST {Endpoint}/qnamaker/v4.0/knowledgebases/create

URI Parameters

Name In Required Type Description
Endpoint
path True
  • string

Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus.api.cognitive.microsoft.com).

Request Body

Name Required Type Description
defaultAnswerUsedForExtraction
  • string

Text string to be used as the answer in any Q-A which has no extracted answer from the document but has a hierarchy. Required when EnableHierarchicalExtraction field is set to True.

enableHierarchicalExtraction
  • boolean

Enable hierarchical extraction of Q-A from files and urls. Value to be considered False if this field is not present.

files

List of files from which to Extract Q-A.

language
  • string

Language of the knowledgebase.

name True
  • string

Friendly name for the knowledgebase.

qnaList

List of Q-A (QnADTO) to be added to the knowledgebase. Q-A Ids are assigned by the service and should be omitted.

urls
  • string[]

List of URLs to be used for extracting Q-A.

Responses

Name Type Description
202 Accepted

Details of the asynchronous operation.

Other Status Codes

Error response.

Security

Ocp-Apim-Subscription-Key

Type: apiKey
In: header

Examples

Successful query

Sample Request

POST {Endpoint}/qnamaker/v4.0/knowledgebases/create
{
  "name": "QnA Maker FAQ",
  "qnaList": [
    {
      "id": 0,
      "answer": "You can change the default message if you use the QnAMakerDialog. See this for details: https://docs.botframework.com/en-us/azure-bot-service/templates/qnamaker/#navtitle",
      "source": "Custom Editorial",
      "questions": [
        "How can I change the default message from QnA Maker?"
      ],
      "metadata": []
    },
    {
      "id": 0,
      "answer": "You can use our REST apis to create a KB. See here for details: https://docs.microsoft.com/en-us/rest/api/cognitiveservices/qnamaker/knowledgebase/create",
      "source": "Custom Editorial",
      "questions": [
        "How do I programmatically create a KB?"
      ],
      "metadata": [
        {
          "name": "category",
          "value": "api"
        }
      ],
      "context": {
        "isContextOnly": false,
        "prompts": [
          {
            "displayOrder": 1,
            "displayText": "Update KB",
            "qna": {
              "answer": "You can use our REST apis to update your KB. See here for details: https://docs.microsoft.com/en-us/rest/api/cognitiveservices/qnamaker/knowledgebase/update",
              "questions": [
                "How do I programmatically update my KB?"
              ],
              "metadata": [
                {
                  "name": "category",
                  "value": "api"
                }
              ],
              "context": {
                "isContextOnly": false,
                "prompts": [
                  {
                    "displayOrder": 1,
                    "displayText": "Refresh Endpoint Keys",
                    "qna": {
                      "answer": "You can use our REST apis to refresh endpoint keys. See here for details: https://docs.microsoft.com/en-us/rest/api/cognitiveservices/qnamaker/endpointkeys/refreshkeys",
                      "questions": [
                        "How do I programmatically refresh endpoint keys?"
                      ]
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    }
  ],
  "urls": [
    "https://docs.microsoft.com/en-in/azure/cognitive-services/qnamaker/faqs",
    "https://docs.microsoft.com/en-us/bot-framework/resources-bot-framework-faq"
  ],
  "files": [
    {
      "fileName": "SurfaceManual.pdf",
      "fileUri": "https://download.microsoft.com/download/2/9/B/29B20383-302C-4517-A006-B0186F04BE28/surface-pro-4-user-guide-EN.pdf"
    }
  ]
}

Sample Response

{
  "operationState": "NotStarted",
  "createdTimestamp": "2018-03-19T07:38:46Z",
  "lastActionTimestamp": "2018-03-19T07:39:29Z",
  "userId": "86bb8390-56c0-42c2-9f81-3de161981191",
  "operationId": "03a4f4ce-30a6-4ec6-b436-02bcdf6153e1"
}

Definitions

Context

Context of a QnA

CreateKbDTO

Post body schema for CreateKb operation.

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.

FileDTO

DTO to hold details of uploaded files.

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.

MetadataDTO

Name - value pair of metadata.

Operation

Record to track long running operation.

OperationStateType

Operation state.

PromptDTO

Prompt for an answer.

Qna

QnADTO - Either QnaId or QnADTO needs to be present in a PromptDTO object

QnADTO

Q-A object.

Context

Context of a QnA

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

prompts

List of prompts associated with the answer.

CreateKbDTO

Post body schema for CreateKb operation.

Name Type Description
defaultAnswerUsedForExtraction
  • string

Text string to be used as the answer in any Q-A which has no extracted answer from the document but has a hierarchy. Required when EnableHierarchicalExtraction field is set to True.

enableHierarchicalExtraction
  • boolean

Enable hierarchical extraction of Q-A from files and urls. Value to be considered False if this field is not present.

files

List of files from which to Extract Q-A.

language
  • string

Language of the knowledgebase.

name
  • string

Friendly name for the knowledgebase.

qnaList

List of Q-A (QnADTO) to be added to the knowledgebase. Q-A Ids are assigned by the service and should be omitted.

urls
  • string[]

List of URLs to be used for extracting Q-A.

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

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.

FileDTO

DTO to hold details of uploaded files.

Name Type Description
fileName
  • string

File name. Supported file types are ".tsv", ".pdf", ".txt", ".docx", ".xlsx".

fileUri
  • string

Public URI of the file.

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.

Operation

Record to track long running operation.

Name Type Description
createdTimestamp
  • string

Timestamp when the operation was created.

errorResponse

Error details in case of failures.

lastActionTimestamp
  • string

Timestamp when the current state was entered.

operationId
  • string

Operation Id.

operationState

Operation state.

resourceLocation
  • string

Relative URI to the target resource location for completed resources.

userId
  • string

User Id

OperationStateType

Operation state.

Name Type Description
Failed
  • string
NotStarted
  • string
Running
  • string
Succeeded
  • string

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

QnADTO

Q-A object.

Name Type Description
answer
  • string

Answer text

context

Context of a QnA

id
  • integer

Unique id for the Q-A.

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