def _validate_image_size(
    message: Message, max_size_bytes: int = 5 * 1024 * 1024
) -> None:
    """
    Validates that images in a message don't exceed the maximum allowed size.

    Args:
        message: Message object to validate
        max_size_bytes: Maximum allowed size for base64-encoded images (default: 5MB)

    Raises:
        R2RException: If image is too large
    """
    if (
        hasattr(message, "image_data")
        and message.image_data
        and "data" in message.image_data
    ):
        base64_data = message.image_data["data"]

        # Calculate approximate decoded size (base64 increases size by ~33%)
        # The formula is: decoded_size = encoded_size * 3/4
        estimated_size_bytes = len(base64_data) * 0.75

        if estimated_size_bytes > max_size_bytes:
            raise R2RException(
                status_code=413,  # Payload Too Large
                message=f"Image too large: {estimated_size_bytes / 1024 / 1024:.2f}MB exceeds the maximum allowed size of {max_size_bytes / 1024 / 1024:.2f}MB",
            )

    Validates that images in a message don't exceed the maximum allowed size.

    Args:
        message: Message object to validate
        max_size_bytes: Maximum allowed size for base64-encoded images (default: 5MB)

    Raises:
        R2RException: If image is too large
    
py/core/providers/database/conversations.py