#1794·ChatterBot

Bug in class BestMatch(LogicAdapter)

Author: petasisCreated Aug 13, 2019Updated Oct 25, 2025
Labelspossible bug

I cannot understand why best match adapter works this way:

  1. It uses the "bigram" search to match entries from the database to the input statement.
  2. Then it uses Levenshtein distance, to get the closest match to the input statement.

So far, so good, we get something from the db with a confidence. If nothing is found in the db, we get the input statement.

And then: 3) A response is searched for the best match. The field 'search_in_response_to' is used.

But why? We have an exact "text" from the database with a confidence. Going back to bigrams throws away all job done by Levenshtein distance, and re-collects everything that Levenshtein distance filtered!

As a result, you get back irrelevant answers, especially for short questions.

  1. And then, the input statement is searched as an alternative. Right now, this will never be executed.

What I propose is before trying steps 3 & 4, to just do an exact search on 'in_response_to'.

And to split the "process" method in submethods, so subclassing should be easier :-)