Intent matching¶
Your project can have many intents. When the user says anything, Alan AI matches the user’s utterance to the most appropriate intent in the dialog script. To do this, Alan AI evaluates every intent separately and assigns different weights, or match scores, to intents.
Match score values range from 1.0 — the most accurate match, to 0.0 — no match. Once all intents are scored, Alan AI selects the highest scoring intent as the best match. If all intents are scored 0, no intent is matched and Alan AI plays an error message.
In the example below, if the user asks: What is the weather?
, the first intent will be selected as the best match. The second intent will not be matched since it contains more words than the user’s utterance. And vice versa, if the user asks: What is the weather today?
, the second intent will have a higher score since it is the most accurate match.
intent('What is the weather?', p => {
p.play('The weather is the day-to-day state of the atmosphere');
});
intent('What is the weather today?', p => {
p.play('The weather today is great!')
});
To see match scores, open Alan AI Studio logs, make sure the Input filter is on and check the score next to the user’s input in the list.

Using p.score¶
The score assigned to the matched intent is stored in the p.score
predefined object. You can use p.score
in the dialog script to adjust the accuracy of Alan AI’s answers.
Note
The value stored in p.score
is a float data type. Due to floating point numbers nature, they may sometimes lose precision. When using p.score
, pick a sensible tolerance so that your dialog script can operate as expected.
Consider the following example:
intent('What is the weather today?', p => {
p.play('The weather today is great!')
});
By default, if the user asks: What is today's weather
, Alan AI will interpret this question as a weather request and give an answer, although this phrase does not exactly match the phrase in the pattern of the intent. Let’s assume you want the AI assistant to reply only if the user’s utterance matches the phrase in the pattern precisely. You can use p.score
to get the match score and provide different responses depending on the score value:
let minScore = 0.99;
intent('What is the weather today?', p => {
console.log(p.score);
if (p.score >= minScore) {
p.play('The weather today is great!');
} else {
p.play('Sorry, I cannot help you with that');
}
});
Here, if the user asks: What is the weather today?
, Alan AI will reply: The weather today is great!
. However, if the user changes the question to: What is today's weather?
, the match score will be less than the minimal score set in the dialog script, and Alan AI will get back with: Sorry, I cannot help you with that
.
See also