mem0ai/mem0 · error · ImportError

zeroentropy package is required for ZeroEntropyReranker. Ins

Error message

zeroentropy package is required for ZeroEntropyReranker. Install with: pip install zeroentropy

What it means

ZeroEntropyReranker raises ImportError when the zeroentropy SDK is absent (guarded by ZERO_ENTROPY_AVAILABLE). ZeroEntropy is a commercial reranking service ('zerank-1'), and its client is an optional dependency not installed with core mem0. The failure occurs at construction, before any API key check or network call.

Source

Thrown at mem0/reranker/zero_entropy_reranker.py:27

    ZERO_ENTROPY_AVAILABLE = True
except ImportError:
    ZERO_ENTROPY_AVAILABLE = False

logger = logging.getLogger(__name__)


class ZeroEntropyReranker(BaseReranker):
    """Zero Entropy-based reranker implementation."""
    
    def __init__(self, config):
        """
        Initialize Zero Entropy reranker.
        
        Args:
            config: ZeroEntropyRerankerConfig object with configuration parameters
        """
        if not ZERO_ENTROPY_AVAILABLE:
            raise ImportError("zeroentropy package is required for ZeroEntropyReranker. Install with: pip install zeroentropy")
        
        self.config = config
        self.api_key = config.api_key or os.getenv("ZERO_ENTROPY_API_KEY")
        if not self.api_key:
            raise ValueError("Zero Entropy API key is required. Set ZERO_ENTROPY_API_KEY environment variable or pass api_key in config.")
            
        self.model = config.model or "zerank-1"
        
        # Initialize Zero Entropy client
        if self.api_key:
            self.client = ZeroEntropy(api_key=self.api_key)
        else:
            self.client = ZeroEntropy()  # Will use ZERO_ENTROPY_API_KEY from environment
        
    def rerank(self, query: str, documents: List[Dict[str, Any]], top_k: int = None) -> List[Dict[str, Any]]:
        """
        Rerank documents using Zero Entropy's rerank API.
        

View on GitHub (pinned to 001c235229)

Solutions

  1. pip install zeroentropy in the mem0 runtime environment
  2. Add it to your requirements/pyproject alongside mem0 so installs stay reproducible
  3. If unneeded, remove the reranker block or switch to a provider whose deps you already carry

Example fix

# before
config = {"reranker": {"provider": "zeroentropy", "config": {"model": "zerank-1"}}}
# ImportError

# after
# pip install zeroentropy
config = {"reranker": {"provider": "zeroentropy", "config": {"model": "zerank-1", "api_key": os.environ["ZERO_ENTROPY_API_KEY"]}}}
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util
if importlib.util.find_spec("zeroentropy") is None:
    raise RuntimeError("install zeroentropy SDK before enabling the zeroentropy reranker")

Try / catch

try:
    reranker = ZeroEntropyReranker(cfg)
except ImportError:
    reranker = None  # or fall back to another provider

Prevention

When it happens

Trigger: Configuring reranker={'provider':'zeroentropy', ...} without `pip install zeroentropy`; copying a config from ZeroEntropy's docs into an env that lacks their SDK; adding the provider typo-free but forgetting the install step.

Common situations: Evaluating commercial rerankers for quality; deploying configs authored on another machine; CI environments built from minimal requirements files that never listed zeroentropy.

Related errors


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