mem0ai/mem0 · error · ValueError

Either cloud_id or host must be provided

Error message

Either cloud_id or host must be provided

What it means

Raised by the Elasticsearch vector store config's auth validator when neither cloud_id nor host is supplied. Mem0's ES client needs either an Elastic Cloud deployment id or a direct host to connect to; without either there is no endpoint, so validation aborts before any network activity.

Source

Thrown at mem0/configs/vector_stores/elasticsearch.py:30

    password: Optional[str] = Field(None, description="Password for authentication")
    cloud_id: Optional[str] = Field(None, description="Cloud ID for Elastic Cloud")
    api_key: Optional[str] = Field(None, description="API key for authentication")
    embedding_model_dims: int = Field(1536, description="Dimension of the embedding vector")
    verify_certs: bool = Field(True, description="Verify SSL certificates")
    ca_certs: Optional[str] = Field(None, description="Path to CA bundle for SSL certificate verification")
    use_ssl: bool = Field(True, description="Use SSL for connection")
    auto_create_index: bool = Field(True, description="Automatically create index during initialization")
    custom_search_query: Optional[Callable[[List[float], int, Optional[Dict]], Dict]] = Field(
        None, description="Custom search query function. Parameters: (query, top_k, filters) -> Dict"
    )
    headers: Optional[Dict[str, str]] = Field(None, description="Custom headers to include in requests")

    @model_validator(mode="before")
    @classmethod
    def validate_auth(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        # Check if either cloud_id or host/port is provided
        if not values.get("cloud_id") and not values.get("host"):
            raise ValueError("Either cloud_id or host must be provided")

        # Check if authentication is provided
        if not any([values.get("api_key"), (values.get("user") and values.get("password"))]):
            raise ValueError("Either api_key or user/password must be provided")

        return values

    @model_validator(mode="before")
    @classmethod
    def validate_headers(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        """Validate headers format and content"""
        headers = values.get("headers")
        if headers is not None:
            # Check if headers is a dictionary
            if not isinstance(headers, dict):
                raise ValueError("headers must be a dictionary")
            
            # Check if all keys and values are strings

View on GitHub (pinned to 001c235229)

Solutions

  1. Set 'cloud_id' to your Elastic Cloud deployment's cloud id
  2. Or set 'host' (e.g. 'http://localhost:9200' or 'https://cluster.example.com:9200')
  3. Verify the env/file source that populates the endpoint actually loads before config construction
  4. Check key spelling against the model fields if you believe the endpoint is set

Example fix

# before
ElasticsearchConfig(api_key="k")

# after
ElasticsearchConfig(host="http://localhost:9200", api_key="k")
Defensive patterns

Strategy: validation

Validate before calling

def validate_es_endpoint(cfg: dict) -> None:
    if not cfg.get("cloud_id") and not cfg.get("host"):
        raise RuntimeError("Elasticsearch config needs 'cloud_id' or 'host'")

Type guard

def has_es_endpoint(cfg: dict) -> bool:
    return bool(cfg.get("cloud_id") or cfg.get("host"))

Try / catch

from pydantic import ValidationError
try:
    ElasticsearchConfig(**cfg)
except ValidationError as e:
    if "cloud_id or host" in str(e):
        # set the endpoint from env/deployment metadata, then retry
        ...

Prevention

When it happens

Trigger: Creating ElasticsearchConfig with neither 'cloud_id' nor 'host' key (or both None/empty). Note the check is purely on cloud_id and host — port, user, password, api_key alone will not satisfy it.

Common situations: Expecting ELASTICSEARCH_URL env pickup (not implemented); cloud_id living in a .env file that was not loaded; host key typo'd as 'hostname' or 'url'; config built conditionally where the endpoint branch never executes.

Related errors


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