mem0ai/mem0 · critical · ImportError

Elasticsearch requires extra dependencies. Install with `pip

Error message

Elasticsearch requires extra dependencies. Install with `pip install elasticsearch`

What it means

ImportError raised at module import time when the 'elasticsearch' Python package (or its helpers module) is missing. elasticsearch.py wraps both imports in one try/except and re-raises with `from None`, so the underlying ModuleNotFoundError is suppressed and only this message shows. The ElasticsearchDB class cannot be imported without the package.

Source

Thrown at mem0/vector_stores/elasticsearch.py:9

import logging
import re
from typing import Any, Dict, List, Optional

try:
    from elasticsearch import Elasticsearch
    from elasticsearch.helpers import bulk
except ImportError:
    raise ImportError("Elasticsearch requires extra dependencies. Install with `pip install elasticsearch`") from None

from pydantic import BaseModel

from mem0.configs.vector_stores.elasticsearch import ElasticsearchConfig
from mem0.vector_stores.base import VectorStoreBase

logger = logging.getLogger(__name__)


class OutputData(BaseModel):
    id: str
    score: float
    payload: Dict


_SAFE_FILTER_KEY = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*$")

View on GitHub (pinned to 001c235229)

Solutions

  1. Install the client: pip install elasticsearch.
  2. If it is already installed, verify the version is compatible and reinstall to fix a broken install (pip install --force-reinstall elasticsearch).
  3. Add a preflight import check to CI/deploy scripts.

Example fix

# before
from mem0.vector_stores.elasticsearch import ElasticsearchDB  # ImportError

# after
# pip install elasticsearch
from mem0.vector_stores.elasticsearch import ElasticsearchDB
Defensive patterns

Strategy: validation

Validate before calling

try:
    import elasticsearch  # noqa: F401
    ES_OK = True
except ImportError:
    ES_OK = False

if provider == "elasticsearch" and not ES_OK:
    raise SystemExit("elasticsearch client missing: pip install elasticsearch")

Prevention

When it happens

Trigger: Importing mem0.vector_stores.elasticsearch or using VectorStoreConfig(provider='elasticsearch') without pip install elasticsearch. Fires at import, before client creation via cloud_id or hosts.

Common situations: Switching from Chroma/Qdrant to Elasticsearch without adding the dependency; slim deployment images; the helpers.bulk import failing because of a major-version mismatch in a partially upgraded environment.

Related errors


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