babylon.utils
Utility modules for Babylon/Babylon.
These are the tools of production - the means by which the engine transforms inputs into outputs.
- exception babylon.utils.BabylonError(message, error_code=None, details=None)[source]
Bases:
ExceptionBase exception for all Babylon/Babylon errors.
All exceptions in the system inherit from this class, allowing for unified error handling at the boundary.
- Parameters:
- Return type:
None
- message
Human-readable error description
- error_code
Machine-readable error identifier
- details
Additional context for debugging
- log(logger, level=logging.ERROR, exc_info=True)[source]
Log this exception with full structured context.
Convenience method for logging exceptions with their structured data included in the log record’s extra fields.
- Parameters:
- Return type:
Example
- try:
risky_operation()
- except BabylonError as e:
e.log(logger) # Logs with ERROR level and full context
- exception babylon.utils.ConfigurationError(message, error_code=None, details=None)[source]
Bases:
ValidationErrorRaised when configuration is invalid or missing.
The material conditions for operation have not been established.
- Parameters:
- Return type:
None
- exception babylon.utils.DatabaseError(message, error_code=None, details=None)[source]
Bases:
InfrastructureErrorRaised when database operations fail.
The Ledger cannot record the material reality.
- Parameters:
- Return type:
None
- exception babylon.utils.EmbeddingError(message, error_code=None, details=None)[source]
Bases:
BabylonErrorDEPRECATED: Use RagError instead.
Raised when embedding operations fail. The Archive cannot encode semantic meaning.
- Parameters:
- Return type:
None
- exception babylon.utils.ValidationError(message, error_code=None, details=None)[source]
Bases:
BabylonErrorRaised when data validation fails.
The input does not conform to the schema of material reality.
- Parameters:
- Return type:
None
- babylon.utils.retry_on_exception(max_retries=3, delay=1.0, backoff=2.0, exceptions=Exception, logger=None)[source]
Decorator that retries a function on specified exceptions.
Uses exponential backoff to avoid hammering failing resources. This is a materialist approach: we respect the physical constraints of the systems we depend on.
- Parameters:
- Return type:
Callable[[TypeVar(F, bound=Callable[...,Any])],TypeVar(F, bound=Callable[...,Any])]- Returns:
Decorated function with retry logic
Example
@retry_on_exception(max_retries=3, delay=1.0, exceptions=(ConnectionError,)) def fetch_data():
return requests.get(”https://api.example.com”)
- babylon.utils.backup_chroma(backup_dir=None, backup_name=None)[source]
Create a backup of the ChromaDB data directory.
- Parameters:
- Return type:
- Returns:
Path to the created backup directory
- Raises:
FileNotFoundError – If ChromaDB directory doesn’t exist
PermissionError – If backup directory isn’t writable
- babylon.utils.restore_chroma(backup_path, force=False)[source]
Restore ChromaDB from a backup.
- Parameters:
- Raises:
FileNotFoundError – If backup doesn’t exist
FileExistsError – If ChromaDB exists and force=False
- Return type:
Modules
Backup and restore utilities for the Archive (ChromaDB). |
|
Exception hierarchy for Babylon/Babylon. |
|
Custom logging utilities for Babylon. |
|
Retry decorator for transient failure handling. |