Microsoft QnA Maker–Creating a Bot for answering frequently asked questions


 

Microsoft QnA Maker Overview

One of the basic requirements in writing your own Bot service is to seed it with questions and answers. In many cases, the questions and answers already exist in content like FAQ URLs/documents, etc.

Microsoft QnA Maker is a free, easy-to-use, REST API and web-based service that trains AI to respond to user’s questions in a more natural, conversational way. Compatible across development platforms, hosting services, and channels, QnA Maker is the only question and answer service with a graphical user interface—meaning you don’t need to be a developer to train, manage, and use it for a wide range of solutions.

With optimized machine learning logic and the ability to integrate industry-leading language processing with ease, QnA Maker distills masses of information into distinct, helpful answers.

alt text

 

 

The QnA Maker cognitive service has fast become the backbone for many customer service bot scenarios.  Once you have created your QnA service and published it, it’s time to incorporate it into your bot framework bot.  To date, there are a couple of ways to implement it from C#.

Watch the following short intro to developing using the QnAMaker

 

The following tips have been provided by Garry Pretty  and documented by Jaime Dalton in the UK Conversations as a Platform team

Getting Started Option 1 – use the Microsoft.Bot.Builder.CognitiveServices nuget package

https://www.nuget.org/packages/Microsoft.Bot.Builder.CognitiveServices

You’ll then need to create a class that uses the QnAMakerDialog eg:

[Serializable]
 public class FAQDialog : QnAMakerDialog
 {
 public FAQDialog() : base(new QnAMakerService
 (new QnAMakerAttribute(ConfigurationManager.AppSettings["QnASubscriptionKey"], 
 ConfigurationManager.AppSettings["QnAKnowledgebaseId"], 
 "Sorry I don't understand, please rephrase your question.", 
 0.5)))
 { }

 }

Then ensure you’ve set the following keys within your web.config:

<add key="QnASubscriptionKey" value="QnASubscriptionKey" /> 
<add key="QnAKnowledgebaseId" value="QnAKnowledgebaseId" />

Full sample here: https://github.com/Microsoft/BotBuilder-CognitiveServices/tree/master/CSharp/Samples/QnAMaker

Option 2 – use the QnAMakerDialog nuget package by Gary Pretty (MVP)

https://www.nuget.org/packages/QnAMakerDialog/

This has a couple of nice features, such as being able to attribute methods with the QnA confidence score and being able to add attachments to responses.  More of which can be discovered here:

[Serializable] 
[QnAMakerService("QnASubscriptionKey", "QnAKnowledgebaseId")] 
public class FAQDialogGP: QnAMakerDialog<object> 
{ 
public override async Task NoMatchHandler(IDialogContext context, string originalQueryText) 
{ 
await context.PostAsync($"Sorry, I couldn't find an answer for '{originalQueryText}'."); 
context.Wait(MessageReceived); 
} 
}

Full sample here: https://github.com/garypretty/botframework/tree/master/QnAMakerDialog/QnAMakerDialog.Sample

Interested in learning more about Microsoft Bot Framework

see http://dev.botframework.com

See Jaime Dalton blog who will be updating the method above as the Bot Framework Matures. https://blogs.msdn.microsoft.com/jamiedalton/2017/03/28/building-a-faq-bot-with-the-qna-maker-cognitive-service/

Learn More

Hands on Labs for Building a Microsoft Bot https://github.com/MSFTImagine/computerscience/blob/master/Workshop/15.%20Bots/Microsoft%20Bot%20Framework%20HOL.md

Comments (2)

  1. Patrick says:

    Are you able to add this to an existing bot application to increase the knowledge? Thanks in advanced.

    1. Lee Stott says:

      Using the QnA Maker, simply creates “Cut and Paste” embed code for a BOT, This is a Microsoft backed tool, and can be used for rapid deployment scenarios where FAQ’s may already exist. You can link it to multiple FAQ pages, to generate a large number of possible responses so depending on your BOT You could build QNA into it an existing customer service bot to act as an interactive FAQ or support tool.

Skip to main content