- A common pattern for "intelligent" applications is to enable users to ask questions using NL, and receive appropriate answers.
- In effect, this kind of solution brings conversational intelligence to a traditional FAQ publication.
- The Azure AI Language service includes a question answering capability, which enables you to define a knowledge base of question and answer pairs that can be queried using natural language input. The knowledge base can be published to a REST endpoint and consumed by client applications, commonly bots.
- The knowledge base can be created from existing sources, including:
- Web sites containing FAQ documentation.
- Files containing structured text, such as brochures or user guides.
- Built-in chit chat question and answer pairs that encapsulate common conversational exchanges.
- Note: The question answering capability of the Azure AI Language service is a newer version of the QnA Service, which still exists as a standalone service.
- A question answering knowledge base is a form of language model, which raises the question of when to use question answering, and when to use the conversational language understanding capabilities of the Azure AI Language service.
- The two features are similar in that they both enable you to define a language model that can be queried using natural language expressions. However, there are some differences in the use cases that they are designed to address, as shown in the following table:
Question answering | Language understanding | |
---|---|---|
Usage pattern | User submits a question, expecting an answer | User submits an utterance, expecting an appropriate response or action |
Query processing | Service uses NL understanding to match the question to an answer in the knowledge base | Service uses NL understanding to interpret the utterance, match it to an intent, and identify entities |
Response | Response is a static answer to a known question | Response indicates the most likely intent and referenced entities |
Client logic | Client application typically presents the answer to the user | Client application is responsible for performing appropriate action based on the detected intent |
- The two services are in fact complementary. You can build comprehensive NL solutions that combine conversational language understanding models and question answering knowledge bases.
- To create a question answering solution, you can use the REST API or SDK to write code that defines, trains, and publishes the knowledge base.
- However, it is more common to use the Azure AI Language Studio web interface to define and manage a knowledge base.
- To create a knowledge base:
- Create an Azure AI Language resource in your Azure subscription.
- Enable the question answering feature.
- Create or select an Azure Cognitive Search resource to host the knowledge base index.
- In Azure AI Language Studio, select the Language resource and create a Custom question answering project.
- Name the knowledge base.
- Add one or more data sources to populate the knowledge base:
- URLs for web pages containing FAQs.
- Files containing structured text from which questions and answers can be derived.
- Pre-defined chit-chat datasets that include common conversational questions and responses in a specified style.
- Create the knowledge base and edit question and answer pairs in the portal.
- Although you can often create an effective knowledge base that consists of individual question and answer pairs, sometimes you might need to ask follow-up questions to elicit more information from a user before presenting a definitive answer. This kind of interaction is referred to as a multi-turn conversation.
- You can enable multi-turn responses when importing questions and answers from an existing web page or document based on its structure, or you can explicitly define follow-up prompts and responses for existing question and answer pairs.
- For example, suppose an initial question for a travel booking knowledge base is "How can I cancel a reservation?". A reservation might refer to a hotel or a flight, so a follow-up prompt is required to clarify this detail. The answer might consist of text such as "Cancellation policies depend on the type of reservation" and include follow-up prompts with links to answers about canceling flights and canceling hotels.
- When you define a follow-up prompt for multi-turn conversation, you can link to an existing answer in the knowledge base or define a new answer specifically for the follow-up. You can also restrict the linked answer so that it is only ever displayed in the context of the multi-turn conversation initiated by the original question.
- After you have defined a knowledge base, you can train its natural language model, and test it before publishing it for use in an application or bot.
- Testing a knowledge base
- Deploying a knowledge base
- When you are happy with the performance of your knowledge base, you can deploy it to a REST endpoint that client applications can use to submit questions and receive answers.
- To consume the published knowledge base, you can use the REST interface.
- The minimal request body for the function contains a question, like this:
{
"question": "What do I need to do to cancel a reservation?"
}
- The response includes the closest question match that was found in the knowledge base, along with the associated answer, the confidence score, and other metadata about the question and answer pair.
{
"answers": [
{
"questions": [
"How can I cancel a reservation?"
],
"answer": "Call us on 555 123 4567 to cancel a reservation.",
"confidenceScore": 1.0,
"id": 6,
"source": "https://margies-travel.com/faq",
"metadata": {},
"dialog": {
"isContextOnly": false,
"prompts": []
}
}
]
}
-
Use active learning
- Active learning can help you make continuous improvements so that it gets better at answering user questions correctly over time.
- Active learning helps improve the knowledge base in two ways:
- Implicit feedback: As incoming requests are processed, the service identifies user-provided questions that have multiple, similarly scored matches in the knowledge base. These are automatically clustered as alternate phrase suggestions for the possible answers that you can accept or reject in the Suggestions page for your knowledge base in Azure AI Language Studio.
- Explicit feedback. When developing a client application you can control the number of possible question matches returned for the user's input by specifying the top parameter, as shown here:
Copy { "question": "I want to book a hotel.", "top": 3 }
- The response from the service includes a question object for each possible match, up to the top value specified in the request:
{ "answers":[ {"questions":[ "How do I book a hotel?" ], "answer":"Call 555-123-4567 to book.", "score":76.55, "id":2, ... }, {"questions":[ "Can I book multiple hotel rooms?" ], "answer":"Yes, you can reserve up to 3 rooms.", "score":76.15, "id":6, ... }, {"questions":[ "Is there a booking fee?" ], "answer":"No, we do not charge a booking fee.", "score":75.99, "id":11, ... } ] }
- You can implement logic in your client app to compare the score property values for the questions, and potentially present the questions to the user so they can positively identify the question closest to what they intended to ask.
- With the correct question identified, your app can use the REST API to send feedback containing suggested alternative phrasing based on the user's original input:
{ "records": [ { "userId": "1234", "userQuestion": "I want to book a hotel.", "qnaId": 2 } ] }
- The qnaId in the feedback corresponds to the id of the question the user identified as the correct match. The userId parameter is an identifier for the user and can be any value you choose, such as an email address or numeric identifier.
- The feedback will be presented in the active learning Suggestions page for your knowledge base in Azure AI Language Studio for you to accept or reject.
-
Define synonyms
- Synonyms are useful when question submitted by users might include multiple different words to mean the same thing.
- Example, a travel agency customer might refer to a "reservation" or a "booking". By defining these as synonyms, the question answering service can find an appropriate answer regardless of which term an individual customer uses.
- To define synonyms, you must use the REST API to submit synonyms in the following JSON format:
{ "synonyms": [ { "alterations": [ "reservation", "booking",, ] } ] }
- While you can use a question answering knowledge store in any sort of application, they are commonly used to support bots.
- A bot is a conversational application that enables users to interact using natural language through one or more channels, such as email, web chat, voice messaging, or social media platform such as Microsoft Teams.
- Question answering is often the starting point for bot development - particularly for conversational dialogs that involve answering user questions. For this reason, Azure AI Language Studio provides the option to easily create a bot that runs in the Azure Bot Service based on your knowledge base.
- To create a bot from your knowledge base, use Azure AI Language Studio to deploy the bot and then use the Create Bot button to create a bot in your Azure subscription. You can then edit and customize your bot in the Azure portal.
- Providing support through a knowledge base of frequently asked questions (FAQs).
- [!NOTE] The question answering capability in Azure AI Language is a newer version of the QnA Maker service - which is still available as a separate service, but to be retired in the near future.
- Create a Azure AI Language Service resource
- [!NOTE] Custom Question Answering uses Azure Search to index and query the knowledge base of questions and answers.
- Create a question answering project
- Language Studio portal (language.cognitive.azure.com) -> Create new menu -> select Custom question answering.
- if no Azure Search, then create new Azure Search
- Choose language setting page -> select the option to Set the language for all projects in this resource -> English -> Next.
- Enter basic information page -> Name (LearnFAQ), Default answer when no answer is returned (Sorry, I don’t understand the question) -> Next -> Create
- Add a source to the knowledge base
- create a knowledge base from scratch, but it’s common to start by importing qns and ans from an existing FAQ page or document. In this case, you’ll import data from an existing FAQ web page for Microsoft learn, and you’ll also import some pre-defined “chit chat” questions and answers to support common conversational exchanges.
- Manage sources page -> Add source list -> Add URLs -> Name: Learn FAQ Page, URL: https://docs.microsoft.com/en-us/learn/support/faq
- Manage sources -> Add source list -> Chitchat -> select Friendly -> Add
- Edit the knowledge base
- Your knowledge base has been populated with question and answer pairs from the Microsoft Learn FAQ, supplemented with a set of conversational chit-chat question and answer pairs. You can extend the knowledge base by adding additional question and answer pairs.
- LearnFAQ project -> Edit knowledge base page -> Question answer pairs tab -> select + -> create a new question answer pair with the following settings:
- Source: https://docs.microsoft.com/en-us/learn/support/faq
- Question: What is Microsoft certification?
- Answer: The Microsoft Certified Professional program enables you to validate and prove your skills with Microsoft technologies.
- Select Done.
- In the page for the What is Microsoft certification? question that is created, expand Alternate questions. -> Add the alternate question How can I demonstrate my Microsoft technology skills?.
- In some cases, it makes sense to enable the user to follow up on an answer by creating a multi-turn conversation that enables the user to iteratively refine the question to get to the answer they need.
- Under the answer you entered for the certification question, expand Follow-up prompts and add the following follow-up prompt:
- Text displayed in the prompt to the user: Learn more about certification.
- Select the Create link to new pair tab, and enter -> You can learn more about certification on the Microsoft certification page.
- Select Show in contextual flow only. This option ensures that the answer is only ever returned in the context of a follow-up question from the original certification question.
- Select Add prompt - > Save
- Train and test the knowledge base
- select the Test button -> deselect Include short answer response (if not already unselected).
- Then at the bottom enter the message Hello. A suitable response should be returned.
- Message: What is Microsoft Learn?. An appropriate response from the FAQ should be returned.
- Message: Thanks! An appropriate chit-chat response should be returned.
- Message: Tell me about Microsoft certification. The answer you created should be returned along with a follow-up prompt link -> Select Link
- Deploy and test the knowledge base -> Get prediction URL, Ocp-Apim-Subscription-Key -> Run azure-ai-eng/12-qna OR Postman
- Create a bot for the knowledge base
- Deploy page -> Create Bot -> Creation type: Create new User-assigned managed identity -> Create a new app service plan -> Language Resource Key: Ocp-Apim) -> Create.
- Go to resource group -> Select the Azure Bot resource -> select the Test in Web Chat page -> Test char What is Microsoft certification?.
- You want to create a knowledge base from an existing FAQ document. What should you do? 1. [ ] Create an empty knowledge base and manually enter the FAQ questions and answers. 1. [x] Create a new knowledge base, importing the existing FAQ document. 1. [ ] Create a new knowledge base, selecting only the Professional chit-chat source.
- How can you add a multi-turn context for a question in an existing knowledge base? 1. [ ] Add synonyms to the knowledge base. 1. [ ] Add alternative phrasing to the question. 1. [x] Add a follow-up prompt to the question.
- How can you enable users to use your knowledge base through email? 1. [ ] Add Friendly Chit-chat to the knowledge base. 1. [ ] Enable Active Learning for the knowledge base and include the user's email address as the userId parameter in responses. 1. [x] Create a bot based on your knowledge base and configure an email channel.