Mongo#

The Mongo module provides a MongoDB-based version of the DBContextStorage class. This class is used to store and retrieve context data in a MongoDB. It allows Chatsky to easily store and retrieve context data in a format that is highly scalable and easy to work with.

MongoDB is a widely-used, open-source NoSQL database that is known for its scalability and performance. It stores data in a format similar to JSON, making it easy to work with the data in a variety of programming languages and environments. Additionally, MongoDB is highly scalable and can handle large amounts of data and high levels of read and write traffic.

class MongoContextStorage(path, rewrite_existing=False, partial_read_config=None, collection_prefix='chatsky_collection', transactions_enabled=False)[source]#

Bases: DBContextStorage

Implements DBContextStorage with mongodb as the database backend.

CONTEXTS table is stored as COLLECTION_PREFIX_contexts collection. LOGS table is stored as COLLECTION_PREFIX_logs collection.

Parameters:
  • path (str) – Database URI. Example: mongodb://user:password@host:port/dbname.

  • rewrite_existing (bool) – Whether TURNS modified locally should be updated in database or not.

  • partial_read_config (Optional[Dict[Literal['labels', 'requests', 'responses'], Union[Literal['__all__'], int, Set[int]]]]) – Dictionary of subscripts for all possible turn items.

  • collection_prefix (str) – “namespace” prefix for the two collections created for context storing.

_UNIQUE_KEYS = 'unique_keys'#
_ID_FIELD = '_id'#
is_concurrent: bool = True#
async _connect()[source]#
async _load_main_info(ctx_id)[source]#
Return type:

Optional[ContextMainInfo]

async _inner_update_context(ctx_id, ctx_info_dump, field_info, session)[source]#
Return type:

None

async _update_context(ctx_id, ctx_info, field_info)[source]#
Return type:

None

async _delete_context(ctx_id)[source]#
Return type:

None

async _load_field_latest(ctx_id, field_name)[source]#
Return type:

List[Tuple[int, bytes]]

async _load_field_keys(ctx_id, field_name)[source]#
Return type:

List[int]

async _load_field_items(ctx_id, field_name, keys)[source]#
Return type:

List[Tuple[int, bytes]]

async _clear_all()[source]#
Return type:

None