Storage Adapters¶
Storage adapters provide an interface that allows ChatterBot to connect to different storage technologies.
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"
)
Built-in Storage Adapters¶
Common storage adapter attributes¶
Each storage adapter inherits the following attributes and methods.
- class chatterbot.storage.StorageAdapter(*args, **kwargs)[source]¶
This is an abstract class that represents the interface that all storage adapters should implement.
- exception AdapterMethodNotImplementedError[source]¶
An exception to be raised when a storage adapter method has not been implemented. Typically this indicates that the method should be implement in a subclass.
- create(**kwargs)[source]¶
Creates a new statement matching the keyword arguments specified. Returns the created statement.
- 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.
- Parameters:
page_size – The maximum number of records to load into memory at once when returning results. Defaults to 1000
order_by – The field name that should be used to determine the order that results are returned in. Defaults to None
tags – A list of tags. When specified, the results will only include statements that have a tag in the provided list. Defaults to [] (empty list)
exclude_text – If the
text
of a statement is an exact match for the value of this parameter the statement will not be included in the result set. Defaults to Noneexclude_text_words – If the
text
of a statement contains a word from this list then the statement will not be included in the result set. Defaults to [] (empty list)persona_not_startswith – If the
persona
field of a statement starts with the value specified by this parameter, then the statement will not be returned in the result set. Defaults to Nonesearch_text_contains – If the
search_text
field of a statement contains a word that is in the string provided to this parameter, then the statement will be included in the result set. Defaults to Nonesearch_in_response_to – If the
search_in_response_to
field of a statement contains a word that is in the string provided to this parameter, then the statement will be included in the result set. Defaults to None
- get_model(model_name)[source]¶
Return the model class for a given model name.
model_name is case insensitive.
- get_object(object_name)[source]¶
Return the class for a given object name.
object_name is case insensitive.
Database Migrations¶
Various frameworks such as Django and SQL Alchemy support functionality that allows revisions to be made to databases programmatically. This makes it possible for updates and revisions to structures in the database to be be applied in consecutive version releases.
The following explains the included migration process for each of the databases that ChatterBot comes with support for.
Django: Full schema migrations and data migrations will be included with each release.
SQL Alchemy: No migrations are currently provided in releases. If you require migrations between versions Alembic is the recommended solution for generating them.
MongoDB: No migrations are provided.
Redis: No migrations are provided.