Building a Next Level Intelligent RASA Chatbot with TigerGraph
Did you know how easy it is to create a conversational assistant? With machine learning/Artificial intelligence.
Building a powerful chatbot Assistant has always been a motivation for all kinds of Businesses, with such tool we can:
Automate Sales Inquiry and boost conversion
Automate Tech Support and create Happy customers
Answer Knowledge Base questions (KB’s) Internally
Today we will be dealing with linking the most famous open-source conversational AI framework (Rasa) with a TigerGraph database.
Having such a Connector/Pipe will allow us to create :
A Knowledge Graph that keeps on growing and maturing
An assistant that gets trained each time on “Auto-growing” datasets
An assistant able to query data in real Time from TigerGraph Database
An assistant Rules/Actions Triggered is a multi-turn conversation Assistant
The previous key features allow us to create a Scalable, Intelligent auto-learning assistant that dynamically adapts to the needs of your business!
What is Rasa?
Rasa is a conversational assistant framework brought up by startups and backed up by a fast-growing community.
The framework has these modules :
Rasa NLU : Handles the Natural Language Processing
RASA Core : Handles data storing , piping , API , and basically the Assistant
Many AI assistants don’t use as much machine learning as you might think. While it’s common practice to apply machine learning to NLU, when it comes to dialogue management, many developers still fall back to rules and state machines.
Instead of adding more and more rules over time. with Rasa using machine learning to select the assistant’s response presents a flexible and scalable alternative. The reason for this is one of the core concepts of machine learning: generalization.
In the above illustration (flowchart) we can clearly see how Rasa components interacts in order to drive a successful conversation with the user:
NLU module: captures and analyses User Intent
Core module: deals with the Next Step
And the next step could be :
Fetching data from a database
Interacting with an API ( Ex: restaurant booking system )
Answering the user with a text
Offering the user different options to drive the conversation flow
Creating your first Rasa Assistant
To create a RASA chatbot you don’t have to be a Machine Learning expert, yet with very minimal programming knowledge you can develop an interactive Conversational Assistant.
Let’s see the step by step how to create a simple healthcare chatbot.
$ python3 -m virtualenv -p python3 .
$ source bin/activate
$ pip install rasa
$ rasa init
Getting Rasa to train data from TigerGraph
Rasa Framework trains data stored in NLU, domain, actions, rules and stories files in order to make the assistant operational.
The limitation here is that the Rasa takes these data from Markdown (Md for Rasa < 1.9) or YAML (yml for Rasa > 2.0) formatted files, which limits the scalability and evolution of intents and dialogues scenarios.
In order to make our assistant learn and evolve in a dynamic way, we will create a connector to pipe data from TigerGraph directly into the Rasa Framework to be trained.
These data are stored in vertices in the Graph and have a certain structure to deliver the expected YML/MD file.
In other words, we made a Script that gets training data from a TigerGraph database and feed them to Rasa framework for training, and for the sake of compatibility, we made the script able to generate YML files (Rasa >= 2.0) and md files (Rasa < 2.0).
Recovering data from TigerGraph in real Time
Querying the data from TigerGraph (or any other API) is made simple using a simple step:
Define the action in the domain.yml
Write the class function responsible for analyzing that message context
Call the TigerGraph query or run GSQL command
The intent is extracted from the message using the RegexClassifier and passed to the Action using the Rules set in the screenshot below:
TigerGraph credentials in actions.py:
TigerGraph Connection Initialization in actions.py:
Class ActionSearchPatients used by rule:
Rasa Flask/Web Sample chat Widget
To implement our little chatbot in action will install Flask and run a sample flask website using our chatbot.
We need to create a virtual environment for flask:
$ python3 –m virtualenv –p python3 .
Activate the virtual environment
$ source bin/activate
And then we install Flask using pip
$ pip install Flask
Create the template
We create a file called app.py as follows
And we create a directory called templates and in that folder, we create our index.html as follow
Run the chatbot and the actions server
To run the rasa server locally and the endpoint of the action we need to run this:
$ rasa run — endpoints endpoints.yml — connector socketio — credentials credentials.yml — port 5005 — cors “*” — enable-api
$ rasa run actions
Run the flask Server
To run our small web demo, we activate our virtual environment and we launch the webapp as follows:
$ source bin/activate
$ python3 app.py
The Bot in Action
Below the links to the GitHub repository to download:
Dr. Jay Yu is the VP of Product and Innovation at TigerGraph, responsible for driving product strategy and roadmap, as well as fostering innovation in graph database engine and graph solutions. He is a proven hands-on full-stack innovator, strategic thinker, leader, and evangelist for new technology and product, with 25+ years of industry experience ranging from highly scalable distributed database engine company (Teradata), B2B e-commerce services startup, to consumer-facing financial applications company (Intuit). He received his PhD from the University of Wisconsin - Madison, where he specialized in large scale parallel database systems
Todd Blaschka |COO
Todd Blaschka is a veteran in the enterprise software industry. He is passionate about creating entirely new segments in data, analytics and AI, with the distinction of establishing graph analytics as a Gartner Top 10 Data & Analytics trend two years in a row. By fervently focusing on critical industry and customer challenges, the companies under Todd's leadership have delivered significant quantifiable results to the largest brands in the world through channel and solution sales approach. Prior to TigerGraph, Todd led go to market and customer experience functions at Clustrix (acquired by MariaDB), Dataguise and IBM.