camel.storages.key_value_storages package#
Submodules#
camel.storages.key_value_storages.base module#
- class camel.storages.key_value_storages.base.BaseKeyValueStorage[source]#
Bases:
ABC
An abstract base class for key-value storage systems. Provides a consistent interface for saving, loading, and clearing data records without any loss of information.
An abstract base class designed to serve as a foundation for various key-value storage systems. The class primarily interacts through Python dictionaries.
This class is meant to be inherited by multiple types of key-value storage implementations, including, but not limited to, JSON file storage, NoSQL databases like MongoDB and Redis, as well as in-memory Python dictionaries.
camel.storages.key_value_storages.in_memory module#
- class camel.storages.key_value_storages.in_memory.InMemoryKeyValueStorage[source]#
Bases:
BaseKeyValueStorage
A concrete implementation of the
BaseKeyValueStorage
using in-memory list. Ideal for temporary storage purposes, as data will be lost when the program ends.
camel.storages.key_value_storages.json module#
- class camel.storages.key_value_storages.json.CamelJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#
Bases:
JSONEncoder
A custom JSON encoder for serializing specifically enumerated types. Ensures enumerated types can be stored in and retrieved from JSON format.
- CAMEL_ENUMS: ClassVar[Dict[str, EnumMeta]] = {'ModelType': <enum 'ModelType'>, 'OpenAIBackendRole': <enum 'OpenAIBackendRole'>, 'RoleType': <enum 'RoleType'>, 'TaskType': <enum 'TaskType'>}#
- default(obj) Any [source]#
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- class camel.storages.key_value_storages.json.JsonStorage(path: Path | None = None)[source]#
Bases:
BaseKeyValueStorage
A concrete implementation of the
BaseKeyValueStorage
using JSON files. Allows for persistent storage of records in a human-readable format.- Parameters:
path (Path, optional) β Path to the desired JSON file. If None, a default path ./chat_history.json will be used. (default:
None
)
camel.storages.key_value_storages.redis module#
- class camel.storages.key_value_storages.redis.RedisStorage(sid: str, url: str = 'redis://localhost:6379', loop: AbstractEventLoop | None = None, **kwargs)[source]#
Bases:
BaseKeyValueStorage
A concrete implementation of the
BaseCacheStorage
using Redis as the backend. This is suitable for distributed cache systems that require persistence and high availability.- property client: Redis | None#
Returns the Redis client instance.
- Returns:
The Redis client instance.
- Return type:
redis.asyncio.Redis
Module contents#
- class camel.storages.key_value_storages.BaseKeyValueStorage[source]#
Bases:
ABC
An abstract base class for key-value storage systems. Provides a consistent interface for saving, loading, and clearing data records without any loss of information.
An abstract base class designed to serve as a foundation for various key-value storage systems. The class primarily interacts through Python dictionaries.
This class is meant to be inherited by multiple types of key-value storage implementations, including, but not limited to, JSON file storage, NoSQL databases like MongoDB and Redis, as well as in-memory Python dictionaries.
- class camel.storages.key_value_storages.CamelJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#
Bases:
JSONEncoder
A custom JSON encoder for serializing specifically enumerated types. Ensures enumerated types can be stored in and retrieved from JSON format.
- CAMEL_ENUMS: ClassVar[Dict[str, EnumMeta]] = {'ModelType': <enum 'ModelType'>, 'OpenAIBackendRole': <enum 'OpenAIBackendRole'>, 'RoleType': <enum 'RoleType'>, 'TaskType': <enum 'TaskType'>}#
- default(obj) Any [source]#
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- class camel.storages.key_value_storages.InMemoryKeyValueStorage[source]#
Bases:
BaseKeyValueStorage
A concrete implementation of the
BaseKeyValueStorage
using in-memory list. Ideal for temporary storage purposes, as data will be lost when the program ends.
- class camel.storages.key_value_storages.JsonStorage(path: Path | None = None)[source]#
Bases:
BaseKeyValueStorage
A concrete implementation of the
BaseKeyValueStorage
using JSON files. Allows for persistent storage of records in a human-readable format.- Parameters:
path (Path, optional) β Path to the desired JSON file. If None, a default path ./chat_history.json will be used. (default:
None
)
- class camel.storages.key_value_storages.Mem0Storage(agent_id: str, api_key: str | None = None, user_id: str | None = None, metadata: Dict[str, Any] | None = None)[source]#
Bases:
BaseKeyValueStorage
A concrete implementation of the
BaseKeyValueStorage
using Mem0 as the backend. This storage system uses Mem0βs text capabilities to store, search, and manage text with context.- Parameters:
agent_id (str) β Default agent ID to associate memories with.
api_key (str, optional) β The API key for authentication. If not provided, will try to get from environment variable MEM0_API_KEY (default:
None
).user_id (str, optional) β Default user ID to associate memories with (default:
None
).metadata (Dict[str, Any], optional) β Default metadata to include with all memories (default:
None
).
References
- class camel.storages.key_value_storages.RedisStorage(sid: str, url: str = 'redis://localhost:6379', loop: AbstractEventLoop | None = None, **kwargs)[source]#
Bases:
BaseKeyValueStorage
A concrete implementation of the
BaseCacheStorage
using Redis as the backend. This is suitable for distributed cache systems that require persistence and high availability.- property client: Redis | None#
Returns the Redis client instance.
- Returns:
The Redis client instance.
- Return type:
redis.asyncio.Redis