Create a QnA Maker knowledge base | Microsoft qna maker tutorial

In this tutorial, you learn how to:

  • Create a knowledge base in the QnA Maker portal
  • Review, save, and train the knowledge base
  • Publish the knowledge base
  • Use Curl to query the knowledge base

Prerequisites

This tutorial requires an existing QnA Maker service.

Create a knowledge base

  1. Sign in to the QnA Maker portal.
  2. Select Create a knowledge base from the top menu.
  3. Skip the first step because you will use your existing QnA Maker service.Step 1 of KB Creation process
  4. In the next step, select your existing settings:
    SettingPurpose
    Microsoft Azure Directory IdYour Microsoft Azure Directory Id is associated with the account you use to sign into the Azure portal and the QnA Maker portal.
    Azure Subscription nameYour billing account you created the QnA Maker resource in.
    Azure QnA ServiceYour existing QnA Maker resource.

    Step 2 of KB Creation process

  5. In the next step, Enter your knowledge base name, My Tutorial kb.

    Step 3 of KB Creation process

  6. In the next step, populate your kb with the following settings:
    Setting nameSetting valuePurpose
    URLhttps://docs.microsoft.com/

    azure/cognitive-services/

    qnamaker/faqs

    The contents of the FAQ at that URL are formatted with a question followed by an answer. QnA Maker can interpret this format to extract questions and the associated answers.
    Filenot used in this tutorialThis uploads files for questions and answers.
    Chit-chat personalityThe friendThis gives a friendly and casual personality to common questions and answers. You can edit these questions and answers later.

    Step 4 of KB Creation process

  7. Select Create your KB to finish the creation process.

    Step 5 of KB Creation process

Review KB, save, and train

  1. Review the questions and answers. The first page is questions and answers from the URL.

    Save and train

  2. Select the last page of questions and answers from the bottom of the table. The page shows questions and answers from the Chit-chat personality.
  3. From the toolbar above the list of questions and answers, select the metadata icon. This shows the metadata tags for each question and answer. The Chit-chat questions have the editorial: chit-chat metadata already set. This metadata is returned to the client application along with the selected answer. The client application, such as a chat bot, can use this filtered metadata to determine additional processing or interactions with the user.

    View Metadata tags

  4. Select Save and train in the top menu bar.

Publish to get KB endpoints

Select the Publish button from the top menu. Once you are on the publish page, select Publish, next to the Cancel button.

Publish

After the KB is published, the endpoint is displayed

Publish page's endpoint settings

Use curl to query for an FAQ answer

  1. Select the Curl tab.

    Curl command

  2. Copy the text of the Curl tab and execute in a Curl-enabled terminal or command-line. The authorization header’s value includes the text Endpoint with a trailing space then the key.
  3. Replace  with How large can my KB be?. This is close to the question, How large a knowledge base can I create?, but not exactly the same. QnA Maker applies natural language processing to determine that the two questions are the same.
  4. Execute the CURL command and receive the JSON response including the score and answer.

    TXT

      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100   581  100   543  100    38    418     29  0:00:01  0:00:01 --:--:--   447{  "answers": [    {      "questions": [        "How large a knowledge base can I create?"      ],      "answer": "The size of the knowledge base depends on the SKU of Azure search you choose when creating the QnA Maker service. Read [here](https://docs.microsoft.com/azure/cognitive-services/qnamaker/tutorials/choosing-capacity-qnamaker-deployment)for more details.",      "score": 42.81,      "id": 2,      "source": "https://docs.microsoft.com/azure/cognitive-services/qnamaker/faqs",      "metadata": []    }  ]}

    QnA Maker is somewhat confident with the score of 42.81%.

Use curl to query for a Chit-chat answer

  1. In the Curl-enabled terminal, replace How large can my KB be? with an bot conversation-ending statement from the user, such as Thank you.
  2. Execute the CURL command and receive the JSON response including the score and answer.

    TXT

      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100   525  100   501  100    24    525     25 --:--:-- --:--:-- --:--:--   550{  "answers": [    {      "questions": [        "Thank you",        "Thanks",        "Thnx",        "Kthx",        "I appreciate it",        "Thank you so much",        "I thank you",        "My sincere thank"      ],      "answer": "You're very welcome.",      "score": 100.0,      "id": 109,      "source": "qna_chitchat_the_friend.tsv",      "metadata": [        {          "name": "editorial",          "value": "chitchat"        }      ]    }  ]}

    Because the question of Thank you exactly matched a Chit-chat question, QnA Maker is completely confident with the score of 100. QnA Maker also returned all the related questions as well as the metadata property containing the Chit-chat metadata tag information.

Use curl to query for the default answer

Any question that QnA Maker is not confident in an answer receives the default answer. This answer is configured in the Azure portal.

  1. In the Curl-enabled terminal, replace Thank you with x.
  2. Execute the CURL command and receive the JSON response including the score and answer.

    TXT

      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100   186  100   170  100    16    272     25 --:--:-- --:--:-- --:--:--   297{  "answers": [    {      "questions": [],      "answer": "No good match found in KB.",      "score": 0.0,      "id": -1,      "metadata": []    }  ]}

    QnA Maker returned a score of 0 which means no confidence but it also returned the default answer.

Next Part: Create a QnA Bot