mem0ai/mem0 · error · ValueError

Cannot specify both cloud configuration and local configurat

Error message

Cannot specify both cloud configuration and local configuration. Choose one.

What it means

Raised by ChromaDbConfig when the same config enables both Chroma Cloud and a local/server connection. Cloud is detected as api_key+tenant both present; local as path or host+port. The client cannot be constructed for two backends at once, so the validator forces an explicit choice.

Source

Thrown at mem0/configs/vector_stores/chroma.py:42

        host, port, path = values.get("host"), values.get("port"), values.get("path")
        api_key, tenant = values.get("api_key"), values.get("tenant")
        
        # Check if cloud configuration is provided
        cloud_config = bool(api_key and tenant)
        
        # If cloud configuration is provided, remove any default path that might have been added
        if cloud_config and path == "/tmp/chroma":
            values.pop("path", None)
            return values
        
        # Check if local/server configuration is provided
        local_config = bool(path) or bool(host and port)
        
        if not cloud_config and not local_config:
            raise ValueError("Either ChromaDB Cloud configuration (api_key, tenant) or local configuration (path or host/port) must be provided.")
        
        if cloud_config and local_config:
            raise ValueError("Cannot specify both cloud configuration and local configuration. Choose one.")
            
        return values

    @model_validator(mode="before")
    @classmethod
    def validate_extra_fields(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        allowed_fields = set(cls.model_fields.keys())
        input_fields = set(values.keys())
        extra_fields = input_fields - allowed_fields
        if extra_fields:
            raise ValueError(
                f"Extra fields not allowed: {', '.join(extra_fields)}. Please input only the following fields: {', '.join(allowed_fields)}"
            )
        return values

    model_config = ConfigDict(arbitrary_types_allowed=True)

View on GitHub (pinned to 001c235229)

Solutions

  1. Delete path/host/port from the config and keep api_key+tenant for cloud-only
  2. Or delete api_key/tenant and keep path (or host+port) for local-only
  3. Audit merged/composed config dicts for stale local keys before adding cloud credentials
  4. Use separate named configs per environment instead of mutating one shared dict

Example fix

# before
ChromaDbConfig(api_key="ck_...", tenant="t", path="./chroma_db")

# after
ChromaDbConfig(api_key="ck_...", tenant="t")
Defensive patterns

Strategy: validation

Validate before calling

def validate_chroma_single_mode(cfg: dict) -> None:
    cloud = bool(cfg.get("api_key") and cfg.get("tenant"))
    local = bool(cfg.get("path")) or bool(cfg.get("host") and cfg.get("port"))
    if cloud and local:
        raise RuntimeError("Choose ONE: Chroma cloud (api_key+tenant) or local (path / host+port)")

Type guard

def chroma_single_mode(cfg: dict) -> bool:
    cloud = bool(cfg.get("api_key") and cfg.get("tenant"))
    local = bool(cfg.get("path")) or bool(cfg.get("host") and cfg.get("port"))
    return cloud != local

Try / catch

from pydantic import ValidationError
try:
    ChromaDbConfig(**cfg)
except ValidationError as e:
    if "Cannot specify both" in str(e):
        # drop local keys (cloud wins) or drop cloud keys, then retry
        ...

Prevention

When it happens

Trigger: Passing api_key and tenant alongside path, or alongside host and port. Subtle case: a default path ('/tmp/chroma') is auto-removed when cloud config exists, but any other path value still triggers the conflict.

Common situations: Migrating from local Chroma to cloud by adding api_key/tenant while leaving the old path in the config; a shared base config dict (with path) merged with cloud credentials; environment-specific overrides layering both modes.

Related errors


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