Storage Adapters

Storage adapters provide an interface that allows ChatterBot to connect to different storage backends.

The storage adapter that your bot uses can be specified by setting the storage_adapter parameter to the import path of the storage adapter you want to use.

chatbot = ChatBot(
    "My ChatterBot",
    storage_adapter="chatterbot.storage.SQLStorageAdapter"
)

SQL Alchemy Storage Adapter

class chatterbot.storage.SQLStorageAdapter(**kwargs)[source]

SQLStorageAdapter allows ChatterBot to store conversation data semi-structutered T-SQL database, virtually, any database that SQL Alchemy supports.

Notes:
Tables may change (and will), so, save your training data. There is no data migration (yet). Performance test not done yet. Tests using others databases not finished.

All parameters are optional, by default a sqlite database is used.

It will check if tables is present, if not, it will attempt to create required tables. :keyword database: Used for sqlite database. Ignored if database_uri especified. :type database: str

Parameters:
  • database_uri (str) – eg: sqlite:///database_test.db”, # use database_uri or database, database_uri can be especified to choose database driver (database parameter will be igored).
  • read_only (bool) – False by default, makes all operations read only, has priority over all DB operations so, create, update, delete will NOT be executed
count()[source]

Return the number of entries in the database.

create()[source]

Populate the database with the tables.

drop()[source]

Drop the database attached to a given adapter.

filter(**kwargs)[source]

Returns a list of objects from the database. The kwargs parameter can contain any number of attributes. Only objects which contain all listed attributes and in which all values match for all listed attributes will be returned.

find(statement_text)[source]

Returns a statement if it exists otherwise None

get_random()[source]

Returns a random statement from the database

remove(statement_text)[source]

Removes the statement that matches the input text. Removes any responses from statements where the response text matches the input text.

update(statement)[source]

Modifies an entry in the database. Creates an entry if one does not exist.

MongoDB Storage Adapter

class chatterbot.storage.MongoDatabaseAdapter(**kwargs)[source]

The MongoDatabaseAdapter is an interface that allows ChatterBot to store statements in a MongoDB database.

Parameters:database (str) – The name of the database you wish to connect to.
database='chatterbot-database'
Parameters:database_uri (str) – The URI of a remote instance of MongoDB.
database_uri='mongodb://example.com:8100/'
deserialize_responses(response_list)[source]

Takes the list of response items and returns the list converted to Response objects.

drop()[source]

Remove the database.

filter(**kwargs)[source]

Returns a list of statements in the database that match the parameters specified.

get_random()[source]

Returns a random statement from the database

get_response_statements()[source]

Return only statements that are in response to another statement. A statement must exist which lists the closest matching statement in the in_response_to field. Otherwise, the logic adapter may find a closest matching statement that does not have a known response.

mongo_to_object(statement_data)[source]

Return Statement object when given data returned from Mongo DB.

remove(statement_text)[source]

Removes the statement that matches the input text. Removes any responses from statements if the response text matches the input text.