{"record":{"id":"c054cd4acde7b2a0","repo":"mem0ai/mem0","slug":"the-ollama-library-is-required-please-install-i","errorCode":null,"errorMessage":"The 'ollama' library is required. Please install it using 'pip install ollama'.","messagePattern":"The 'ollama' library is required\\. Please install it using 'pip install ollama'\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"mem0/embeddings/ollama.py","lineNumber":9,"sourceCode":"from typing import Literal, Optional\n\nfrom mem0.configs.embeddings.base import BaseEmbedderConfig\nfrom mem0.embeddings.base import EmbeddingBase\n\ntry:\n    from ollama import Client\nexcept ImportError:\n    raise ImportError(\"The 'ollama' library is required. Please install it using 'pip install ollama'.\")\n\n\nclass OllamaEmbedding(EmbeddingBase):\n    def __init__(self, config: Optional[BaseEmbedderConfig] = None):\n        super().__init__(config)\n\n        self.config.model = self.config.model or \"nomic-embed-text\"\n        self.config.embedding_dims = self.config.embedding_dims or 512\n\n        self.client = Client(host=self.config.ollama_base_url)\n        self._ensure_model_exists()\n\n    @staticmethod\n    def _normalize_model_name(name: str) -> str:\n        return name if \":\" in name else f\"{name}:latest\"\n\n    def _ensure_model_exists(self):\n        \"\"\"","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/embeddings/ollama.py#L1-L27","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nMemory.from_config({\"embedder\": {\"provider\": \"ollama\"}})  # ImportError\n\n# after\n# pip install ollama\nMemory.from_config({\"embedder\": {\"provider\": \"ollama\", \"config\": {\"model\": \"nomic-embed-text\"}}})","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif importlib.util.find_spec(\"ollama\") is None:\n    raise SystemExit(\"Missing dependency: pip install ollama\")\n\nMemory.from_config({\"embedder\": {\"provider\": \"ollama\", \"config\": {\"model\": \"nomic-embed-text\"}}})","typeGuard":null,"tryCatchPattern":"try:\n    from mem0.embeddings.ollama import OllamaEmbedding\nexcept ImportError as e:\n    print(f\"Dependency missing: {e}. Install with: pip install ollama\")\n    raise SystemExit(1) from e","preventionTips":["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"],"tags":["python","ollama","import-error","dependencies","mem0"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}