Microsoft Question Answering
The Azure Question Answering Connector allows Teneo and Microsoft developers to connect a Custom Question Answering knowledge base on Azure Language Studio, which is part of the Azure Cognitive Services, with a Teneo solution. This service is the successor to QnA Maker. Teneo developers will benefit from Microsoft’s state-of-the-art toolkit, which will allow them to develop a Question Answering knowledge base based on existing data in just minutes, and connect to Teneo solution via REST APIs.
In this page, we will explain how to get started in Custom Question Answering service and seamlessly use a trained Question Answering project within Teneo Studio. If you want to read more about the different FAQ Building approaches in Teneo, you can find a dedicated article here.
Migrate your QnA Maker project to Azure Language Studio
Microsoft QnA Maker is now deprecated. Users are recommended to migrate their projects to Custom Question Answering service. From 1st October 2022, creation of new QnA Maker resources have been restricted and the existing resources will be inaccessible from March 2025. For this reason, our new Question Answering connector only supports the new Custom Question Answering on Language Studio. The old QnA Maker connector is still working, but we strongly suggest you migrate your QnA Maker project to Custom Question Answering as soon as possible even it is working perfectly at this moment.
The migration process is very simple and intuitive. After opening the QnA Maker portal, you will find the migration option easily. Click on the Start migration button, follow the essential information and the migration will be done in a few minutes.
Custom Question Answering Knowledge Base
Create a new Custom Question Answering project
If you are new to Microsoft Custom Question Answering, you need to create a project from scratch in Azure Language Studio. Click on Create new and choose Custom question answering from the drop-down list. Then follow step-by-step guide to create a new project.
Fill in question-answer pairs
After creating a new project, you need to add question-answer pairs to the knowledge base. Custom Question Answering service allows you use either structured or unstructured data of various common formats such as .pdf, .docx, .xlsx, .tsv, etc. to train a custom Question Answering model. You can either add URLs if your data is stored in the Cloud or upload local files. You can also add pre-built Chitchat pairs in certain languages.
Check the possible content types of documents you can add to the knowledge base from here. We also provide you a .tsv file as an example which can be imported into the knowledge base in the download section.
You can also manually add new question-answer pairs or edit the existing ones by choosing Edit knowledge base from the side bar on the left.
Deploy your knowledge base
Now choose Deploy knowledge base and click on Deploy to deploy the knowledge base. Please be aware that you do not need to create a bot , since Question Answering will be connected to your Teneo bot.
After deploying the knowledge base, you need to click the Get prediction URL button and copy the Prediction URL together with the value of Ocp-Apim-Subscription-Key. You do not need to copy the whole sample request.
Working on the Solution in Teneo
Now it is time to work on the solution inside Teneo in order to connect it to your Custom Question Answering knowledge base.
Import Groovy file to Resources
Download AzureQAHelper.groovy from the Download section. Import it to Resources > File and set the Published Location as /script_lib
. If you do now know how to do this, please check this document.
Set up Question Answering connector instance as Global variable
Now add a global variable as an instance of the Question Answering connector. In this article it is named azureQuestionAnswering, but in your use case you can give it any name you find suitable for your solution. The value should be new AzureQAHelper("your_endpoint","your_key")
, replacing your_endpoint with the Prediction URL and your_key with the value of Ocp-Apim-Subscription-Key you copied from Azure Language Studio. Here is an example:
Connect to the Question Answering knowledge base to get the answer
Now you are ready to connect to your Question Answering knowledge base in your solution. To extract the answer, you need the following method (replacing the variable name azureQuestionAnswering if needed): azureQuestionAnswering.getAnswer(question)
with an argument question which stands for the question to be sent to the knowledge base. You can add it in different places in your solution where Groovy code is required, such as Script node, Listener, Integration, and Global scripts.
The value returned by this method will be a list with two elements: the answer text which is the answer for your question, and the confidence score which helps you filter out those answers which may not fit your question. Here is an example of the Groovy code to get the answer only when the confidence score is greater than 0.5.
groovy
1def question = _.getUserInputText() // Get the question from user input
2def result = azureQuestionAnswering.getAnswer(question) // Replace variable name azureQuestionAnswering if needed
3// Variable “confidence” and “answer” below stands for the confidence score and the answer text. They should be defined in advance as flow variable or global variable with a more specific name like azureQaConfidence if needed.
4confidence = result[1]
5if(confidence>0.5){
6 answer = result[0]
7} else {
8 answer = "No answer"
9}
10