mem0ai/mem0 · error · ImportError
The 'ollama' library is required. Please install it using 'p
Error message
The 'ollama' library is required. Please install it using 'pip install ollama'.
What it means
Module-level ImportError raised when mem0/embeddings/ollama.py is imported and the `ollama` Python package is not installed. Because it fires at import time, the failure occurs when mem0 lazily loads the OllamaEmbedding class (provider: 'ollama'), not at first embed call.
Source
Thrown at mem0/embeddings/ollama.py:9
from typing import Literal, Optional
from mem0.configs.embeddings.base import BaseEmbedderConfig
from mem0.embeddings.base import EmbeddingBase
try:
from ollama import Client
except ImportError:
raise ImportError("The 'ollama' library is required. Please install it using 'pip install ollama'.")
class OllamaEmbedding(EmbeddingBase):
def __init__(self, config: Optional[BaseEmbedderConfig] = None):
super().__init__(config)
self.config.model = self.config.model or "nomic-embed-text"
self.config.embedding_dims = self.config.embedding_dims or 512
self.client = Client(host=self.config.ollama_base_url)
self._ensure_model_exists()
@staticmethod
def _normalize_model_name(name: str) -> str:
return name if ":" in name else f"{name}:latest"
def _ensure_model_exists(self):
"""View on GitHub (pinned to 001c235229)
Solutions
- pip install ollama (or add it to your project dependencies)
- If you use uv/poetry/pipenv, add ollama to the lockfile and reinstall
- Verify with python -c "import ollama" that the package resolves in the same interpreter/venv mem0 runs in
Example fix
// before
Memory.from_config({"embedder": {"provider": "ollama"}}) # ImportError
# after
# pip install ollama
Memory.from_config({"embedder": {"provider": "ollama", "config": {"model": "nomic-embed-text"}}}) Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
if importlib.util.find_spec("ollama") is None:
raise SystemExit("Missing dependency: pip install ollama")
Memory.from_config({"embedder": {"provider": "ollama", "config": {"model": "nomic-embed-text"}}}) Try / catch
try:
from mem0.embeddings.ollama import OllamaEmbedding
except ImportError as e:
print(f"Dependency missing: {e}. Install with: pip install ollama")
raise SystemExit(1) from e Prevention
- Declare ollama in requirements.txt alongside the mem0 config that uses it
- Add a startup dependency check for optional providers
- Use one lockfile per deployment environment
When it happens
Trigger: Configuring provider: ollama in the embedder config without pip-installing ollama; using mem0ai without the [graph] extras in an env where only core deps exist; a fresh virtualenv where ollama was never added to requirements.txt.
Common situations: New Ollama users who installed the Ollama desktop app but not the Python client; CI environments missing the dependency; dependency resolution dropping ollama after a lockfile regeneration.
Related errors
- The 'anthropic' library is required. Please install it using
- The 'boto3' library is required. Please install it using 'pi
- Ollama embed() returned no embeddings for model '{self.confi
- Ollama embed() returned {len(embeddings)} embeddings for {le
- The 'upstash_vector' library is required. Please install it
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/c054cd4acde7b2a0.
Report an issue: GitHub.