DialogFlow Knowledge Connectors: Using an FAQ Knowledge Document to make an FAQ Bot
One of the most important parts of designing and developing a conversational experience is to ensure your bot can recognize user utterances. When a user types in a request, the chatbot needs to be able to understand what to do next. If it doesn’t, the bot will return something irrelevant or even a fallback/error message.
DialogFlow offers several ways to set up your intents. One way is to manually set up each intent with all the utterances that trigger a certain response. This can be quite difficult, though. Let’s say we are asking when a store will be open. A user could type any of the following to ask about the open hours/days.
What days are you open?
Are you open on {day}?
Are you open on weekends?
Can I come on {day}?
Is your store open on {day}?
Can I come in the {time}?
Will you be open at {time}?
Will you be open on {day} {time}?
Tuesdays open?
Open times?
Even with the shorthand for day and time, there are different ways to write these. Would the user write a general time range like “morning” or a specific time like 11:42 AM? Would the user write “Monday” or “Mon”? Even with a simple request like this, there is still a lot of complexity to consider when setting up the intent.
We could manually list all the utterances connected with an intent. This offers great precision, but it can be complex and time-consuming. To help with this process, DialogFlow offers knowledge connectors. Knowledge connectors read knowledge documents to find responses automatically. Knowledge documents can come from CSVs, web pages, or cloud files. For web-based sources, DialogFlow can even automatically update a knowledge document with new content as source material changes.
There are two types of knowledge connectors – FAQ and Extractive Question Answering. In this article, we’ll focus on setting up and testing an FAQ knowledge connector. We’ll get better acquainted with the FAQ knowledge connector by building a simple FAQ bot for a bakery.
Knowledge connectors live in the Knowledge tab. However, Knowledge connectors are beta features, so we have to enable them before using them. Click on the gear icon to open the settings.
Under BETA FEATURES, toggle on Enable beta features and APIs. Then, click SAVE.
Now click on Knowledge from the side menu.
Now we need to set up a knowledge base. Our chatbot could use several knowledge bases, each specializing in one particular domain. This could be especially useful for keeping track of a bot with many domains and overlapping types of information. For example, a transport hub like an airport might have to tell separate information about planes, airport buses, taxis, and even trains/subways. Having all of that in one knowledge base could become hard to manage pretty quickly. Our bakery bot, though, is pretty simple, so we’ll just make one knowledge base.
Click Create the first one, give your knowledge base a name (e.g. bakeryFAQ), and click SAVE.
Now, we’ll need to add a knowledge document. Just like with knowledge bases, you can set up multiple knowledge documents within each knowledge base. For example, we could have a knowledge document about pricing, one about custom orders and deliveries, and another about upcoming events and classes. Splitting up knowledge documents can help you keep your information organized and also allows you to use the best settings for each document’s contents. For our purposes, though, we’ll stick with one knowledge document.
For an FAQ knowledge document, we outline a set of questions and answers to those questions. We will use a CSV because the DialogFlow documentation recommends using CSVs whenever possible. Column A will be for questions. Column B will be for answers. Each row will contain one question and answer pair. You cannot write more than one question, nor can you provide more than one answer per row. Download the CSV file to get started. You may want to add your own question/answer pairs. You could add things like the bakery’s address or whether they make custom cakes.
Click and download: Bakery Bot Question and Answer CSV
After you’ve finished with the CSV, click on Create the first one, and then use the following settings.
Document Name: bakeryFAQ
Knowledge Type: FAQ
Mime Type: text/csv
Data Source: Upload file from your computer
Click CREATE. You may have to wait a bit for Dialogflow to set up the knowledge document.
Once it finishes, we still need to do one more thing. The knowledge connector only parses the documents to find a question/answer pair that matches the user’s utterance. We need to tell DialogFlow to use the response the knowledge connector generates to provide the user with an answer. Sounds tough, right? To do so, just click ADD RESPONSE.
That’s it! Now, when a user asks a question, the bakery bot will see if it finds a matching question-answer pair. Then it will provide that to the user. You can test this now.
The FAQ knowledge connector does not just respond to the exact question you provided. It can generalize to similar questions, as well. In our CSV file, we put in “What days are you open,” “What time are you open,” and “When are you open?” DialogFlow responds to these just fine.
Try out the following, though.
Are you open on Tuesday?
Is your store open on Thursday?
Can I come on Wednesday?
Can I come in the afternoon?
Will you be open on Thursday afternoon?
I’d like to visit on Friday.
How about Tuesdays?
Can I drop by Tuesday morning?
If you got similar results as me, Questions 1 and 2 got back “We’re open Monday to Friday.” Question 3-5 got “We’re open Monday to Friday from 10:00 AM to 5:00 PM. The last three, Questions 6-8, all failed to get a match. It’s a bit unusual that Questions 2 and 3 got different responses. But, for the most part, the responses are accurate.
If you’d like to see what’s going on a bit better, change the response from $Knowledge.Answer[1] to $Knowledge.Question[1]. Now, when you test out your bot, you will see which question the user utterance matched. If you try typing “How much are cupcakes?,” you will probably get “What kinds of cupcakes do you sell?”
This is a problem because our user wanted to know the price, not the types, of cupcakes. We could update our knowledge base to better ask this question. However, it’s giving a lot of information. It’d be hard to write a question in our CSV that captures all of the variations this question might be asked. In this case, it might be better to turn this question into an intent.
Click on View Detail next to our bakeryFAQ knowledge document.
At the bottom of the question-answer pairs, click the checkbox next to “How much do things cost?” Then, click CONVERT TO INTENTS. Click CONFIRM to finish the process.
Dialogflow will disable the question. Even though the knowledge document is still active, Dialogflow will use the intent to read this question, not the knowledge document. This means that we need to write more possible utterances manually.
Click on Intents, and you should see the new intent from the knowledge document.
If you open it, you will see the original question that we wrote as well as the response.
Now, we need to add more utterances (i.e. training phrases). Think of all the different ways a user could request the prices. Of course, they could ask about prices in general, such as “How much do things cost?” They could ask about each item’s price, as well. Can you think of any other ways to ask about the price?
How much does {item} cost?
What's the price of {item}?
What are your prices?
How much is {amount} {item}?
What does {amount} {item} cost?
Could you tell much how much for {item}?
When we write all of these out, our list of training phrases will be quite long.
Now, when we ask our bot about the price of cupcakes, we will get… the same response. What’s going on?
Knowledge connectors are great because they just seem to work. We upload some questions and answers, and Dialogflow handles a lot on its own. However, when we start mixing knowledge connectors and intents, we need to let Dialogflow know which source of information to prioritize.
We need to adjust this setting in the Knowledge tab. By default, Dialogflow sets this preference as 0.0. This setting applies to all knowledge bases equally, so you will need to do a lot of testing to make sure your knowledge bases and intents work together. To do so, it’s a good idea to have a bank of questions you want to test in which you know what source you want the answer to come from. Some should come from knowledge bases; others should come from intents. All of them should give the best answer to your user.
In our case, I adjusted the slider down one notch to the left to -0.1. This means I wanted our bakery bot to have a slightly weaker preference for knowledge results and a slightly higher preference for intents. The bot now returns the right answer.
Knowledge connectors offer a powerful way to answer simple questions without much setup. In particular, you might find them very useful for getting started with a bot and doing initial testing for simple queries. Despite the ease of using them, though, it’s important to keep in mind that they are meant to work together with intents. The first sentence of Dialogflow’s documentation on knowledge connectors says “Knowledge connectors complement defined intents.”
However, as you might remember, there’s another knowledge connector – Extractive Question Answering. In the next part of this series of articles, we will look at how to use the Extractive Question Answering knowledge connector to work with longer text sources.