Siwi (/ˈsɪwi/) is a PoC of Dialog System With Graph Database Backed Knowledge Graph.
For now, it’s a demo for task-driven(not general purpose) dialog bots with KG(Knowledge Graph) leveraging Nebula Graph with the minimal/sample dataset from Nebula Graph Manual/ NG中文手册.
Tips: Now you can play with the graph online without installing yourself!
What is the relationship between Yao Ming and Lakers?
How does Yao Ming and Lakers connected?
serving:
Which team had Yao Ming served?
friendship:
Whom does Tim Duncan follow?
Who are Yao Ming’s friends?
1 Deploy and Try
TBD (leveraging docker and nebula-up)
2 How does it work?
This is one of the most naive pipeline for a specific domain/ single purpose chat bot built on a Knowledge Graph.
2.1 Backend
The Backend(Siwi API) is a Flask based API server:
Flask API server takes questions in HTTP POST, and calls the bot API.
In bot API part there are classfier(Symentic Parsing, Intent Matching, Slot Filling), and question actors(Call corresponding actions to query Knowledge Graph with intents and slots).
Knowledge Graph is built on an Open-Source Graph Database: Nebula Graph
2.2 Frontend
The Frontend is a VueJS Single Page Applicaiton(SPA):
I reused a Vue Bot UI to showcase a chat window in this human-agent interaction, typing is supported.
In addtion, leverating Chrome’s Web Speech API, a button to listen to human voice is introduced
$ curl --header "Content-Type: application/json"\
--request POST \
--data '{"question": "What is the relationship between Yao Ming and Lakers?"}'\
http://192.168.8.128:5000/query | jq
{"answer": "There are at least 23 relations between Yao Ming and Lakers, one relation path is: Yao Ming follows Shaquille O'Neal serves Lakers."}
Call Bot Python API:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fromnebula2.gclient.netimportConnectionPoolfromnebula2.ConfigimportConfig# define a configconfig=Config()config.max_connection_pool_size=10# init connection poolconnection_pool=ConnectionPool()# if the given servers are ok, return true, else return falseok=connection_pool.init([('127.0.0.1',9669)],config)# import siwi botfromsiwi.botimportbot# instantiate a botb=bot.SiwiBot(connection_pool)# make the question queryb.query("Which team had Jonathon Simmons served?")
Then a response will be like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
In[4]:b.query("Which team had Jonathon Simmons serv...:ed?")[DEBUG]ServeActionintent:{'entities':{'Jonathon Simmons':'player'},'intents':('serve',)}[DEBUG]queryforRelationshipAction:USEbasketballplayer;MATCHp=(v)-[e:serve*1]->(v1)WHEREid(v)=="player112"RETURNpLIMIT100;[2021-07-0202:59:36,392]:Getconnectionto('127.0.0.1',9669)Out[4]:'Jonathon Simmons had served 3 teams. Spurs from 2015 to 2015; 76ers from 2019 to 2019; Magic from 2017 to 2017; '