Navigation

  • index
  • modules |
  • next |
  • previous |
  • ChatterBot 1.2.7 documentation »
  • Storage Adapters »
  • Text Search
  • Edit on GitHub |

Text Search¶

ChatterBot’s storage adapters support text search functionality.

Text Search Example¶

    def test_search_text_results_after_training(self):
        """
        ChatterBot should return close matches to an input
        string when filtering using the search_text parameter.
        """
        self._create_many_with_search_text([
            Statement('Example A for search.'),
            Statement('Another example.'),
            Statement('Example B for search.'),
            Statement(text='Another statement.'),
        ])

        results = list(self.chatbot.storage.filter(
            search_text=self.chatbot.tagger.get_text_index_string(
                'Example A for search.'
            )
        ))

        self.assertEqual(len(results), 1)
        self.assertEqual('Example A for search.', results[0].text)

Bigram Text Index¶

Bigram pairs are used for text search

In addition, the generation of the pairs ensures that there is a smaller number of possible matches based on the probability of finding two neighboring words in an existing string that match the search parameter.

For searches in larger data sets, the bigrams also reduce the number of OR comparisons that need to occur on a database level. This will always be a reduction of n - 1 where n is the number of search words.

ChatterBot bigram generation process
Stack Overflow
Ask a question under the
chatterbot tag
GitHub
Report an issue on
GitHub
Subscribe to updates via
@chatterbot.us on Bluesky

Logo of ChatterBot

Quick search

Table of Contents

  • About
  • Installation
  • Quick Start Guide
  • ChatterBot Tutorial
  • Examples
  • Training
  • Preprocessors
  • Logic Adapters
  • Storage Adapters
    • Built-in Storage Adapters
    • Common storage adapter attributes
    • Database Migrations
    • Further Reading
      • Text Search
        • Text Search Example
        • Bigram Text Index
      • Creating a new storage adapter
  • Large Language Models
  • Filters
  • ChatterBot
  • Conversations
  • Comparisons
  • Utility Methods
  • ChatterBot Corpus
  • Django Integration
  • Frequently Asked Questions
  • Command line tools
  • Development
  • Glossary

Navigation

  • index
  • modules |
  • next |
  • previous |
  • ChatterBot 1.2.7 documentation »
  • Storage Adapters »
  • Text Search
  • Edit on GitHub |
© Copyright 2025, Gunther Cox.