Blog
June 12, 2018Using QnA Maker Service and Azure Bot Service to Create an FAQ Bot in Minutes
- Topics
- Cloud
Bots have become an increasingly popular and incredibly powerful tool for companies to provide customers with a rich conversational interface from which they can easily extract useful information. Microsoft's QnA Maker and Bot Services have made it extremely easy to build an intelligent FAQ bot in a serverless environment. This ensures automatic scaling of services based on demand, so you only pay for the resources you need.
At Microsoft's annual MSBuild Conference in Seattle, CEO Satya Nadella emphasized the company's vision to empower and encourage everyone to leverage the rapid progress that artificial intelligence and machine learning have made in the past few years. QnA Maker is a simple yet powerful example that reiterates Microsoft's commitment to make this generally intimidating computing power accessible to everyone.
Microsoft announced general availability for QnA Maker at /build/ 2018 on May 7, 2018 with a few highlights:
- Data and runtime components of QnA Maker are now hosted through the user's Azure portal. Find more about the new architecture here.
- Users are billed for services hosted rather than number of transactions. Here's pricing information.
- A new portal experience to create and manage your QnA Maker and knowledge base. The portal can be found here.
- Ability to scale different parts of your stack as needed. More about upgrading your service here.
Getting Started
We'll be running through an example of how to build, train, and deploy a question-and-answer bot based on FAQs. You will be using Microsoft's Cognitive Services and Web App Bot Service, both of which can be found in the Azure portal here. This example assumes you already have an Azure account set up, which can be created for free using an existing Microsoft account.
Creating a QnA Service
QnA Maker allows you to quickly create a knowledge base to which you can link existing data sources to be used as a data repository for your bot. Before you can create a knowledge base, however, you have to create a QnA Service.
Navigate here, sign in with you Azure credentials, then select Create a QnA Service
In the QnA Maker, fill out the required fields:
- Fill in the Name with a unique name to identify this service. I will be using the name
TestQNAService
- Select Free Trial as the Subscription
- Select F0 (3 calls per second) as the Management Pricing Tier
- Create a new Resource Group
- Choose the Free tier for the Search pricing tier option. If this option is greyed out, it means you already have a Free Azure Search tier deployed and you will need to use the Basic Azure Search Tier.
- Select East US as the Search Location. This is where your Azure Search data will be deployed.
- Choose an App Name for your service
- Choose East US for both the Website Location and App Insights Location. (Note: the search location can be different from the website location.)
Once all the fields are filled out and validated, click on Create to start deploying these services.
You will see your new QnA Service show up in your list of subscriptions once the deployment is complete (this usually takes a few minutes).
Creating a QnA Maker Knowledge Base
Now that your QnA Service has been created, return here and scroll down to Step 2: Connect your QnA Service to your KB
- Select the same tenant as your Microsoft Azure account for the Microsoft Azure Directory ID
- Choose the Free Tier option for the Azure Subscription Name
- Finally, select the name of the QnA Service you created in the previous step from the Azure QnA Service dropdown, which should now be available
In Step 3, name your KB for your reference (you can change it anytime). I have named my KB Test QnA KB.
In Step 4, choose a source to populate your KB. Microsoft's QnA Maker supports formats including .pdf
, .doc
, .docx
, .xlsx
, and others. For this demo, enter
https://azure.microsoft.com/en-us/support/faq/
into the URL field. This is the FAQ page for Microsoft Azure. When complete, your bot will be able to answer all the questions listed in this FAQ page.
Finally, select Create your KB in step 5. This will go through the link you provided and create a knowledge base for your service. When the KB is created, it opens the Knowledge Base page from which you can edit the contents of your KB.
Click on Add QnA Pair to add a new row to the KB and enter the following.
Select Save and train to save your changes and train the QnA Maker model.
You can test your KB by choosing Test from the top bar. If you enter "Hi", the KB should respond with the answer you just entered.
You also have the option of Inspecting this response by selecting the Inspect link. From here, you can add different phrasings for the same question and also view the Confidence Score the service assigned to the answer it returned. Remember to select Save and train to save your changes.
You can now select Publish from the top bar. This will deploy your service to an endpoint that, once published successfully, can be used to feed your QnA Bot! You can always select Edit Service to return to your KB and make changes.
In just a few minutes, you have easily created a QnA Maker Service using Microsoft's Cognitive Services without writing a single line of code!
Creating a QnA Bot with Azure Bot Service
Now that you've successfully created a QnA Maker Service, you can create a bot that uses the KB you created to respond to questions via the QnAMakerDialog.
From the Azure Portal, select Create a Resource, then search for Web App Bot and hit Create.
Fill in the following information to create and deploy the bot service using QnAMakerDialog
to Azure
- Set Bot Name to your bot's desired name. I will be using
TestQNABot_1
for mine. - Choose Free Trial for the Subscription
- Select Create new for Resource Group
- Choose East US for Location
- Choose F0 (10K Premium Messages) for the Pricing Tier
- Select Question and Answer C# for the Bot template and hit Select
- Choose Create New for Azure Storage
- Choose East US for App Insights Location
- Select Create
The deployment will take a few minutes. Once the notification displays Deployment Succeeded, select Go To Resource on that notification.
Testing the Bot - First Pass
Once the bot's resource window is open, click Test in Web Chat and type "hi" into the chat box.
The bot should respond with "Please set QnAKnowledgebaseId
and QnASubscriptionKey
in App Settings. Get them at https://qnamker.ai. This is letting you know that your bot is not yet linked to the KB you created earlier. Let's do that next.
Connecting your QnA KB to your QnA Bot
Navigate back to the QnA Maker page and select the "My Knowledge Bases" tab.
Select View Code from the row that lists the KB you created earlier to locate the appropriate values.
Now navigate back to the Azure portal and select the Web App bot you just created. Select the Application Settings tab under App Service Settings and edit the QnAKnowledgebaseId
, QnAAuthKey
, and the QnAEndpointHostName
fields to add the values of the QnA KB that you previously created.
Testing the Bot - Second Pass
Once again in the Azure Portal, select the QnA Bot you created and hit Test in Web Chat and type "hi" into the chat box. The bot should respond with "Hello, ask me about Microsoft Azure!" as expected.
This bot is now fully connected to your knowledge base! You can continue asking questions normally found in the FAQ directly through this bot.
Next Steps
We've shown how you can take an existing FAQ page and turn it into a rich, interactive bot experience in a just few minutes. However, there are a few ways to continue to enhance this app to make it more logically sound for developers and resourcefully meaningful for users.
For more complicated knowledge bases, it can quickly turn inefficient to maintain a single, massive set of data. In such instances, it is better to create multiple KBs to split your data into logical, manageable pieces. Microsoft allows you to manage these multiple KBs effectively using LUIS, the Language Understanding Intelligent Service that uses machine learning to build natural language into apps and bots.
As for /build/ 2018, LUIS has been designed to find intents and entities from user conversations effectively without requiring manual input from developers. This makes it extremely straightforward to create a continuously learning and improving model for a more sophisticated bot experience.
As illustrated in the architecture diagram below, a user's question will be processed by LUIS to identify the intent; after which, it can route the question to the appropriate QnA Maker KB. This allows for you to build large, complex bots with multiple KBs and a logical architecture.
Conclusion
You've seen how simple and straightforward it is to get up and running with an intelligent bot service with minimal effort through Microsoft's QnA Maker and Azure Bot Services. These features provide developers powerful tools to use AI and machine learning capabilities, a trend Microsoft will look to continue cultivating in the future.
Full details and documentation on Microsoft's QnA Maker can be found here.