Adding RAG to Chatbot
Step 1: Add RAG
First, enter the following prompt in the Prompt window of the Chatbot Assistant application:
You are a helpful assistant.
Use the following context as your learned knowledge, inside <context></context> XML tags.
<context>
</context>
When answer to user:
- If you don't know, just say that you don't know.
- If you don't know when you are not sure, ask for clarification.
Avoid mentioning that you obtained the information from the context.
And answer according to the language of the user's question.
After leaving the mouse, a pop-up window will appear to add a variable. Click "Add."
In the "Context" section, click "Add" and select the knowledge base we created in the previous experiment.
After adding, you can see the added knowledge base in the context section.
According to actual needs, we can add multiple knowledge bases.
Step 2: Verify the Effect
Based on our questions, the chatbot assistant will first retrieve highly similar segments from the knowledge base, and then embed them as context into the System Prompt for the large model to answer the question.
Please complete the testing of chatbot+RAG yourself. If the retrieval effect is not good, go back to the "Knowledge Base" module, click the leftmost "Retrieval Test" icon to test the retrieval effect.
Click the "Knowledge Base Settings" icon to modify the embedding model and retrieval settings to improve the hit rate.
After saving, return to the Chatbot Assistant application and re-test whether the answer effect is satisfactory.
Lab 1 ends here. Congratulations! You have learned and mastered how to build a knowledge retrieval-based chatbot in Dify.