Rule Intents


Rule intents gives you the capability to use advanced rules to understand what a user wants. You can often get by with only using our ML Intents that use various Machine Learning techniques to understand what your users are saying, but sometimes you need more power than this. Example use cases of this are if you use the Generic Language, if you want to match an intent on a specific data input, or if you want to make sure that you have a specific entry in the context before triggering the intent.


Each Rule Intent consists of

Intent NameUnique name of the Intent
RulesA set of rules for this Intent


Each Intent can have any number of rules attached to it. The rules are written as Direct CognigyScript, meaning that you don't need the CognigyScript tags. You can therefore write your rules using our input object or context object (e.g. ci.text === "Hello") and use free form JavaScript.

You can create as many rules as you want, and if any one of them is matched, the intent will be returned with a score of 1. Rule Intents take precedence over ML Intents, meaning that if the user says a sentence that would trigger a Rule Intent AND an ML Intent, then the Rule Intent will win.


Rule Intent Example

The intent is orderFood. Rules could include.

  • ci.text === "I want to order pizza"
  •[0].keyphrase === "pizza" && === 1
  • ci.text === `${ci.slots.male_firstname[0].keyphrase} wants cake`
  • ci.text.split(" ")[0] === "Add" && ci.text.match("to favorites")


Rule intents will always have a score of 1 if they match.

What is a good use case for Rule Intents?

Let's say we want to inform the user on a general level about a very specific topic. A good example would be information about a certain disease, e.g. "diabetes". The disease name is very unlikely to show up in example sentences for other intents and should show up in the vast majority of user input for that intent.
Additionally, it is very unlikely that "diabetes" will be mentioned when the user wants information about other diseases.


Good Rule Example

For this case the following rule should sufficiently cover a great variety of user input:


With this rule any user input that includes the character sequence "diabetes" will trigger the intent - even within word combinations that are not separated by " " !


Bad Rule Example

The following rule will be worse than a ML intent with only one example sentence!

ci.text === "I want information about diabetes"

This will only work for this exact sentence, even a " " (double space) instead of a " " (single space) or an exclamation mark at the end will prevent the intent from being triggered.

What is a bad use case for Rule Intents?

Let's say we have multiple intents that are closely related and can be uttered with a wide variety of vocabulary. A fitting example would be reporting symptoms to a doc chatbot.
It makes a huge difference whether you say "my chest hurts" or "it hurts when I am breathing" or "I have difficulties breathing".
In this case using ML intents is superior to trying to create a fitting rule intent.