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.JsonFileStorageAdapter"
)

Json File Storage Adapter

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

This adapter allows ChatterBot to store conversation data in a file in JSON format.

Parameters:
  • database (str) – The path to the json file you wish to store data in.
  • silence_performance_warning (bool) – If set to True, the UnsuitableForProductionWarning will not be displayed.
exception UnsuitableForProductionWarning[source]

The json file storage adapter will display an UnsuitableForProductionWarning when it is initialized because it is not intended for use in large scale production applications. You can silence this warning by setting silence_performance_warning=True when initializing the adapter.

JsonFileStorageAdapter.deserialize_responses(response_list)[source]

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

JsonFileStorageAdapter.drop()[source]

Remove the json file database completely.

JsonFileStorageAdapter.filter(**kwargs)[source]

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

JsonFileStorageAdapter.json_to_object(statement_data)[source]

Converts a dictionary-like object to a Statement object.

JsonFileStorageAdapter.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.

JsonFileStorageAdapter.update(statement)[source]

Update a statement in the database.

Mongo Database 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.