AI Chatbot demo with Drupal and RAG
At DrupalCon Barcelona, we were amazed to see all the powerful and functional Drupal AI integrations in action. I have been following the development closely, and after the recent release announcement of the AI (Artificial Intelligence) module, we decided to recreate one of its use cases: a RAG chatbot enabling semantic search.
Try the RAG chatbot
Visit the live demo site and test the chatbot at the bottom right corner.
Examples:
- I'm looking for diary free meals.
Notice the typo: the word "diary" doesn't exist on this site, yet, the chatbot is able to find and offer a dairy-free recipe. - I have potatoes and cheese at home. Any ideas on what I could cook from them?
Notice that there are no recipes for this on this site. The AI will use its own knowledge. - Can you offer something fully vegan?
Hint: ask for alternative ingredient options. - Where can I find the recipes on this site?
- Offer me a vegetarian pasta.
How this works
This is a RAG (retrieval-augmented generation) AI system. This means that the selected website content is indexed in a vector database and used as the primary resource for an LLM to power your chatbot or AI augmented semantic search.
Feeding the content to the RAG database is identical to search indexing, then configuring the assistant comes with some new options, then it is prompt engineering.
The tone of voice and the behavior of the assistant can be altered. For example we asked the Assistant to "include what percentage of your answer comes from the RAG and from your knowledge". Adding this sentence to the Assistant configuration was enough, and now you can find this information in all answers.
This concept can be reused also for private data safely.
You can choose the provider you trust, and the entire system can be built using open-source software, enabling full self-hosting for maximum privacy and data security.
Tech stack
Vector Database
Vector Database
Milvus.
Think about it as a search index for your chatbot. In this case we use Milvus, an open-source and high-performance vector database. It is available as a cloud service at Zilliz.com.
LLM
LLM
OpenAI.
The Large Language Model is the engine of the chatbot responsible for processing natural language queries and generating the answers based on the context coming from the vector database and its own knowledge. In this case we use OpenAI, but any other providers or even self-hosted open-source LLMs are supported.
Drupal modules used
- AI Core, AI Search (uses the Search API), AI Chatbot from the AI (Artificial Intelligence) module
- OpenAI provider
- Milvus VDB Provider
We followed this video demonstration of the Drupal AI module (thanks FreelyGive!) and figured out what needs to be done differently for the latest release: mostly that providers are now separate contributed modules.