AI Zone Admin Forum Add your forum

NEWS: survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

How to extend Rivescript’s bot’s knowledge


I like the macro extension syntax. If I am writing a bot that answers questions I see how I can drill down to a specific question or answer and then delegate processing off to an external method call.

If I had information in some sort of db, what is the approach I could use to build new rules using that information? Say for example, asking ‘What is the capital city of…?

I could hand write rivescript for all the cases to answer this. What if I had a database table that contained a list of capital cities that I could access from the host language. How would I incorporate these external data sources into rivescript rules?

My goal would be to extend Rivescript with more and more domain information from a knowledge base to make it more and more capable of carrying on a discussion around certain topic areas.



  [ # 1 ]

One way would be to delegate the external code to handle all the replies:

what is the capital of *
- <
call>capital <star></call

And then your macro would look up the answer. If the user said something completely invalid (“what is the capital of Mars?”), it could just return a whole response like “I don’t think that has a capital.”

Depending on how large the data set is, this would probably be the best way to do it so far. You could write a program to generate RiveScript code for you from a database, but the more triggers your RiveScript code has the slower the bot will be able to give a reply, as it has to scan through all the triggers until it finds a match. The speed difference is negligible for most bots, but becomes pretty apparent when you try to run a large bot like Alice in RiveScript ( ).

For example, I was playing with adding emoji support to one of my RiveScript bots, so I wanted to generate a substitution file in RiveScript to replace emoji unicode symbols with friendlier names (source). It was auto-generating the RiveScript file from a “database” of sorts (a large JSON file), but there was just so much data that it would slow down reply fetching by a good amount (several seconds). I ended up pruning the list of supported emojis down to just those that I think are more commonly used (emoticons and common symbols).

Soon I’ll start playing with some ideas to optimize RiveScript so it can handle larger sets of data without slowing down.

For auto-generating RiveScript source code, though, some implementations support methods to help with that. The JavaScript and Perl versions has functions like `deparse()` and `write()/stringify()`—if you give a data structure to `write()` that looks like the sort of data you got from `deparse()`, it can do all the heavy lifting of writing it as RiveScript code.


  login or register to react