Q&A Agent with Knowledge Base
In this tutorial, we will use the HelperAI platform to create a question-answering agent. We will store the answers to common questions in a knowledge base, allowing the agent to respond to user queries using the knowledge base. For this purpose, we will use Netflix's Top 10 rankings webpage as the data source for our question-answering agent, enabling it to answer common questions about popular Netflix movies.
Prerequisites
- You have a HelperAI account. If not, please register here.
- You have an OpenAI API key which is able to access GPT4 model. If not, please follow the instructions here to get one.
Create New Project
- Start by logging in to the HelperAI Workspace.
- Click on the
+
button next toProject
in the left sidebar. - A dialogue window will appear:
- Enter the project name in the
Project Name
field: "My FAQ Project" - Enter your OpenAI API Key in the
OpenAI API Key
field.
- Enter the project name in the
- Click the
Create New Project
button. - You will be redirected to the project page, where you will see a project named "My FAQ Project"
Create a Knowledge Base
- On the project page, click the
+ New Knowledge Base
button. - In the popup dialog box, select the Loader for your knowledge base. Here, we will choose the
url
Loader as a demonstration. - Click the
Next Step
button. - Enter the relevant settings for the knowledge base:
- Knowledge Base Prompt Name: "netflix-top10"
- Comment: "Netflix Trending Website"
- Knowledge Base Prompt Description: "Query this knowledge base when you need to know Netflix trending."
- Interval Minutes: "60"
- Chunk Size: 3000 (Unit: tokens)
- Overlap Size: 100 (Unit: tokens)
- In the Properties section, enter the following settings to configure the Loader options:
- urls:
https://www.netflix.com/tudum/top10/
- urls:
- Click the
Add Knowledge Base
button. You will now see a new knowledge base named "netflix-top10" created under the project.
Create New Agent Under the Project
- On the project page, click on the
+ New Agent
button. - A dialogue window will appear:
- Enter the agent name in the
Agent Name
field: "Netflix Q&A Agent" - Click the "Create New Agent" button.
- Enter the agent name in the
- You will be redirected to the agent page, where you will see an agent named "Netflix Q&A Agent"
The
url
Loader is a lightweight knowledge base Loader that can load the contents of a knowledge base from one or more URLs. In the future, we will also provide more knowledge base Loaders. If there is no suitable knowledge base Loader for you, you can also develop your own knowledge base Loader and integrate it into HelperAI.
Set Goals for the Agent
-
On the agent page, click on the
Overview
tab. -
Click on the pencil icon (✏️) next to
Goals
to edit the goals. A dialogue window should pop up. -
Click the
+ Add Blank Goal
button to add a new blank goal entry, and enter the following goal description:-
Answer common questions from customers about popular Netflix movies
-
-
Click the
Save Changes
button to save your goal settings.
Set Constraints for the Agent
-
On the agent page, click on the
Overview
tab. -
Click on the pencil icon (✏️) next to
Constraints
to edit the constraints. A dialogue window should pop up. -
Click the
+ Add Blank Constraint
button to sequentially add the following constraints:Only respond to questions about popular Netflix movies.
The responses provided to the customer must be brief and professional.
-
Click the
Save Changes
button to save your constraint settings.
Bind Knowledge Base to the Agent
- On the agent page, click on the
Knowledge
tab. - Click on the
+
button. A dialogue window should pop up. - From the dropdown menu under
Knowledge Base
, select the previously created "netflix-top10" knowledge base. - After selecting the "netflix-top10" knowledge base, you will see the content of the "Knowledge Base Prompt" automatically filled in. We do not need to modify this content.
- In the
Score Threshold
field, enter "0.7". - In the
Top K
field, enter "2". - Click on
Next Step
. You may see some additional suggestions for setting goals and constraints for this knowledge base. We do not need to modify this content. - Click on the
Add Knowledge
button. You will now see that the knowledge base has been linked to the agent.
The
Score Threshold
represents the threshold value used by HelperAI when querying the knowledge base. When HelperAI queries the knowledge base, it compares the data in the knowledge base with the keywords being searched and calculates a score. When the score exceeds the "Score Threshold", HelperAI considers the data to be relevant and adds it to the list of candidate answers. Here, we have set the "Score Threshold" to0.7
, meaning that only when HelperAI determines the similarity between the data and the user's input is above 70%, the data will be used as the background information for the agent's response.The
Top K
represents the number of responses HelperAI will return when querying the knowledge base. Here, we have set theTop K
to5
, meaning that HelperAI will only return the top 5 most similar data when querying the knowledge base. It is important to note that currently, the "Top K" value does not have any practical effect since we only set one URL earlier, so querying the knowledge base may return at most one data entry.
Test the Agent
-
On the agent page, click on the button with a chat bubble icon (💬) in the top left corner. This will open a testing dialogue window.
-
Now you can start a conversation with your first agent. For example, you can ask the agent:
What is the most popular movie on Netflix?
orWhat is the most popular TV show on Netflix?
You should notice that your agent responds with the answer to your question based on the content of the url you provided earlier.
Updated about 1 year ago