您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

教程:在 QnA Maker 门户中创建知识库Tutorial: From the QnA Maker portal, create a knowledge base

通过基于 Web 的公共 FAQ 创建包含问答的新知识库。Create a new knowledge base with questions and answers from a public web-based FAQ. 保存、训练和发布知识库。Save, train, and publish the knowledge base. 发布知识库后,使用 cURL 命令发送问题并接收解答。After the knowledge base is published, send a question and receive an answer with a cURL command. 然后创建机器人,并使用相同的问题测试机器人。Then create a bot, and test the bot with the same question.

本教程介绍如何执行下列操作:In this tutorial, you learn how to:

  • 在 QnA Maker 门户中创建知识库。Create a knowledge base in the QnA Maker portal.
  • 查看、保存和训练知识库。Review, save, and train the knowledge base.
  • 发布知识库。Publish the knowledge base.
  • 使用 cURL 查询知识库。Use cURL to query the knowledge base.
  • 创建机器人。Create a bot.

备注

“Azure-Samples/cognitive-services-qnamaker-csharp”GitHub 存储库中提供本教程的编程版本和完整的解决方案 。The programmatic version of this tutorial is available with a complete solution from the Azure-Samples/cognitive-services-qnamaker-csharp GitHub repository.

先决条件Prerequisites

本教程需要现有的 QnA Maker 服务This tutorial requires an existing QnA Maker service.

创建知识库Create a knowledge base

  1. 登录 QnA Maker 门户。Sign in to the QnA Maker portal.

  2. 从顶部菜单中选择“创建知识库”。 Select Create a knowledge base from the top menu.

    QnA Maker 门户的屏幕截图

  3. 请跳过第一步,因为你将使用现有的 QnA Maker 服务。Skip the first step, because you will use your existing QnA Maker service.

  4. 选择现有设置:Select your existing settings:

    设置Setting 目的Purpose
    Microsoft Azure Directory IDMicrosoft Azure Directory ID 此 ID 与用于登录 Azure 门户和 QnA Maker 门户的帐户相关联。This ID is associated with the account you use to sign into the Azure portal and the QnA Maker portal.
    Azure 订阅名称Azure Subscription name 在其中创建了 QnA Maker 资源的计费帐户。The billing account in which you created the QnA Maker resource.
    Azure QnA 服务Azure QnA Service 现有的 QnA Maker 资源。Your existing QnA Maker resource.

    QnA Maker 门户的屏幕截图

  5. 输入知识库名称 My Tutorial kbEnter your knowledge base name, My Tutorial kb.

    QnA Maker 门户的屏幕截图

  6. 为知识库填充以下设置:Populate your knowledge base with the following settings:

    设置名称Setting name 设置值Setting value 目的Purpose
    代码URL https://docs.microsoft.com/azure/cognitive-services/qnamaker/faqs 该 URL 中常见问题解答内容的格式为一个问题接一个答案。The contents of the FAQ at that URL are formatted with a question followed by an answer. QnA Maker 可以通过解释此格式来提取问题和相关联的答案。QnA Maker can interpret this format to extract questions and the associated answers.
    文件File 不在本教程中使用not used in this tutorial 此项上传用于问题和答案的文件。This uploads files for questions and answers.
    聊天个性化内容Chit-chat personality 友好Friendly 此项为常见问题和解答提供友好且随和的 个性 化内容。This gives a friendly and casual personality to common questions and answers. 可以稍后编辑这些问题和解答。You can edit these questions and answers later.

    QnA Maker 门户的屏幕截图

  7. 选择“创建 KB”,完成创建过程。 Select Create your KB to finish the creation process.

    QnA Maker 门户的屏幕截图

查看、保存和训练知识库Review, save, and train the knowledge base

  1. 查看问题和解答。Review the questions and answers. 第一页是 URL 中的问题和解答。The first page is questions and answers from the URL.

    QnA Maker 门户的屏幕截图

  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 View options icon, and then select Show metadata. 此时会显示每个问题和解答的元数据标记。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.

    QnA Maker 门户的屏幕截图

  4. 在顶部菜单栏中选择“保存并训练” 。Select Save and train in the top menu bar.

通过发布获取知识库终结点Publish to get knowledge base endpoints

从顶部菜单中选择“发布”按钮。 Select the Publish button from the top menu. 在发布页上选择“发布” 。On the publish page, select Publish.

QnA Maker 门户的屏幕截图

发布知识库以后,会显示终结点。After the knowledge base is published, the endpoint is displayed.

终结点设置的屏幕截图

请勿关闭此“发布”页。 Don't close this Publish page. 稍后在本教程中需要用它来创建机器人。You need it later in the tutorial, to create a bot.

使用 cURL 查询 FAQ 解答Use cURL to query for an FAQ answer

  1. 选择“Curl”选项卡。 Select the Curl tab.

    “cURL”选项卡的屏幕截图

  2. 复制“cURL”选项卡的文本,在支持 cURL 的终端或命令行中运行它。 Copy the text of the Curl tab, and run it in a cURL-enabled terminal or command-line. 授权标头的值包含文本 Endpoint 和一个尾随空格以及密钥。The authorization header's value includes the text Endpoint, with a trailing space and then the key.

  3. <Your question> 替换为 How large can my KB be?Replace <Your question> with How large can my KB be?. 这与问题 How large a knowledge base can I create? 接近,但并不完全相同。This is close to the question, How large a knowledge base can I create?, but not exactly the same. QnA Maker 会应用自然语言处理来确定两个问题是否相同。QnA Maker applies natural language processing to determine that the two questions are the same.

  4. 运行 cURL 命令,然后接收包含评分和解答的 JSON 响应。Run the cURL command and receive the JSON response, including the score and answer.

      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100   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": []
        }
      ]
    }
    
    

    分数为 42.81%,表明 QnA Maker 不怎么确信其答案。QnA Maker is somewhat confident with the score of 42.81%.

使用 cURL 查询聊天式解答Use cURL to query for a Chit-chat answer

  1. 在支持 cURL 的终端中,将 How large can my KB be? 替换为用户进行的机器人聊天的结束语句,例如 Thank youIn the cURL-enabled terminal, replace How large can my KB be? with a bot conversation-ending statement from the user, such as Thank you.

  2. 运行 cURL 命令,然后接收包含评分和解答的 JSON 响应。Run the cURL command and receive the JSON response, including the score and answer.

      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100   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"
            }
          ]
        }
      ]
    }
    
    

    由于问题 Thank you 与聊天问题完全匹配,因此分数为 100,表明 QnA Maker 完全确信其答案。Because the question of Thank you exactly matched a Chit-chat question, QnA Maker is completely confident with the score of 100. QnA Maker 还返回了包含聊天元数据标记信息的所有相关问题和元数据属性。QnA Maker also returned all the related questions, as well as the metadata property containing the Chit-chat metadata tag information.

使用 cURL 查询默认解答Use cURL to query for the default answer

QnA Maker 没有把握的问题会收到默认答案。Any question that QnA Maker is not confident about receives the default answer. 该答案在 Azure 门户中配置。This answer is configured in the Azure portal.

  1. 在支持 cURL 的终端中,将 Thank you 替换为 xIn the cURL-enabled terminal, replace Thank you with x.

  2. 运行 cURL 命令,然后接收包含评分和解答的 JSON 响应。Run the cURL command and receive the JSON response, including the score and answer.

      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100   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 返回的评分为 0,表示没有置信度。QnA Maker returned a score of 0, which means no confidence. 它同时返回了默认解答。It also returned the default answer.

创建知识库机器人Create a knowledge base bot

有关详细信息,请参阅使用此知识库创建聊天机器人For more information, see Create a chat bot with this knowledge base.

清理资源Clean up resources

处理完知识库机器人后,请删除资源组 my-tutorial-rg,以删除处理机器人过程中创建的所有 Azure 资源。When you are done with the knowledge base bot, remove the resource group, my-tutorial-rg, to remove all the Azure resources created in the bot process.

使用完知识库后,请在 QnA Maker 门户中选择“我的知识库”。 When you are done with the knowledge base, in the QnA Maker portal, select My knowledge bases. 接着选择知识库“我的教程知识库”,然后选择该行最右侧的删除图标。 Then select the knowledge base, My Tutorial kb, and select the delete icon at the far right in that row.

后续步骤Next steps

有关支持文件格式的详细信息,请参阅支持的数据源See Data sources supported for more information about support file formats.

详细了解聊天个性化内容Learn more about Chit-chat personalities.

有关默认答案的详细信息,请参阅找不到匹配项For more information about the default answer, see No match found.