mem0ai/mem0 · critical · ImportError

Azure Identity is required for Azure credential authenticati

Error message

Azure Identity is required for Azure credential authentication. Please install it using 'pip install azure-identity'

What it means

Raised by AzureMySQL.__init__ when use_azure_credential=True but the optional 'azure-identity' package is not installed. The module probes for it at import time (mem0/vector_stores/azure_mysql.py:19-23) and sets AZURE_IDENTITY_AVAILABLE=False on ImportError; the constructor then refuses to proceed because _setup_azure_auth() needs DefaultAzureCredential to fetch a token for Azure Database for MySQL.

Source

Thrown at mem0/vector_stores/azure_mysql.py:101

            maxconn (int): Maximum number of connections in the pool
            connection_pool (Any, optional): Pre-configured connection pool
        """
        self.host = host
        self.port = port
        self.user = user
        self.password = password
        self.database = database
        self.collection_name = _validate_identifier(collection_name, "collection_name")
        self.embedding_model_dims = embedding_model_dims
        self.use_azure_credential = use_azure_credential
        self.ssl_ca = ssl_ca
        self.ssl_disabled = ssl_disabled
        self.connection_pool = connection_pool

        # Handle Azure authentication
        if use_azure_credential:
            if not AZURE_IDENTITY_AVAILABLE:
                raise ImportError(
                    "Azure Identity is required for Azure credential authentication. "
                    "Please install it using 'pip install azure-identity'"
                )
            self._setup_azure_auth()

        # Setup connection pool
        if self.connection_pool is None:
            self._setup_connection_pool(minconn, maxconn)

        # Create collection if it doesn't exist
        collections = self.list_cols()
        if collection_name not in collections:
            self.create_col(name=collection_name, vector_size=embedding_model_dims, distance="cosine")

    def _setup_azure_auth(self):
        """Setup Azure authentication using DefaultAzureCredential."""
        try:
            credential = DefaultAzureCredential()

View on GitHub (pinned to 001c235229)

Solutions

  1. Install the package: pip install azure-identity (or add it to your requirements.txt / image).
  2. If you do not want Azure AD auth, set use_azure_credential back to False and authenticate with the password argument instead.
  3. Add an environment check to your Dockerfile/CI: python -c "import azure.identity" to fail builds early rather than at runtime.

Example fix

# before
AzureMySQL(host=..., use_azure_credential=True)  # ImportError

# after (option 1)
# pip install azure-identity
AzureMySQL(host=..., use_azure_credential=True)

# after (option 2)
AzureMySQL(host=..., password=os.environ['MYSQL_PWD'], use_azure_credential=False)
Defensive patterns

Strategy: validation

Validate before calling

def can_use_azure_credential() -> bool:
    try:
        import azure.identity  # noqa: F401
        return True
    except ImportError:
        return False

assert can_use_azure_credential(), "pip install azure-identity before enabling use_azure_credential"

Prevention

When it happens

Trigger: Instantiating AzureMySQL (directly or via VectorStoreConfig with provider 'azure_mysql') with use_azure_credential=True in an environment where 'pip install azure-identity' was never run. PyMySQL/DBUtils are installed (they are hard imports at the top of the file), so the failure only appears at construction time, not import time.

Common situations: Deploying to a container or CI image built from core mem0ai extras without the Azure extras; copying a config that worked on a dev machine with azure-identity already present; switching from password auth to managed-identity auth on Azure App Service/Container Apps where the library was not bundled.

Understand the failure class

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/7c2e3fca346ef593. Report an issue: GitHub.