{"record":{"id":"c98f7580a5526e3a","repo":"mem0ai/mem0","slug":"ollama-embed-returned-no-embeddings-for-model-c98f75","errorCode":null,"errorMessage":"Ollama embed() returned no embeddings for model '{self.config.model}'","messagePattern":"Ollama embed\\(\\) returned no embeddings for model '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/embeddings/ollama.py","lineNumber":52,"sourceCode":"            or self._normalize_model_name(model.get(\"model\", \"\")) == target\n            for model in local_models\n        ):\n            self.client.pull(self.config.model)\n\n    def embed(self, text, memory_action: Optional[Literal[\"add\", \"search\", \"update\"]] = None):\n        \"\"\"\n        Get the embedding for the given text using Ollama.\n\n        Args:\n            text (str): The text to embed.\n            memory_action (optional): The type of embedding to use. Must be one of \"add\", \"search\", or \"update\". Defaults to None.\n        Returns:\n            list: The embedding vector.\n        \"\"\"\n        response = self.client.embed(model=self.config.model, input=text)\n        embeddings = response.get(\"embeddings\") or []\n        if not embeddings:\n            raise ValueError(f\"Ollama embed() returned no embeddings for model '{self.config.model}'\")\n        return embeddings[0]\n\n    def embed_batch(self, texts, memory_action=\"add\"):\n        \"\"\"Embed multiple texts in a single Ollama API call.\"\"\"\n        if not texts:\n            return []\n        response = self.client.embed(model=self.config.model, input=texts)\n        embeddings = response.get(\"embeddings\") or []\n        if len(embeddings) != len(texts):\n            raise ValueError(f\"Ollama embed() returned {len(embeddings)} embeddings for {len(texts)} texts using model '{self.config.model}'\")\n        return embeddings\n","sourceCodeStart":34,"sourceCodeEnd":64,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/embeddings/ollama.py#L34-L64","documentation":"Raised by OllamaEmbedding.embed when the Ollama client's embed() response contains an empty or missing 'embeddings' list. This happens when the local Ollama server returns a 200-style response with no vectors — typically because the named model is not a text-embedding model (e.g. a chat model like llama3) or the response shape changed.","triggerScenarios":"Setting config.model to a generative model (e.g. 'llama3', 'mistral') instead of an embedding model ('nomic-embed-text', 'mxbai-embed-large'); the model file is corrupted on disk; an Ollama server version whose embed endpoint returns {} for unsupported models.","commonSituations":"Reusing the LLM model name for the embedder config; model pulled partially (ollama pull interrupted); older Ollama server predating the /api/embed endpoint.","solutions":["Set the embedder model to a real embedding model: nomic-embed-text or mxbai-embed-large, and ollama pull it","Update the Ollama server to a recent version (the embed API is newer than the legacy embeddings endpoint)","Re-pull the model to rule out corruption: ollama rm <model> && ollama pull <model>","Test outside mem0: curl http://localhost:11434/api/embed -d '{\"model\":\"nomic-embed-text\",\"input\":\"hi\"}' should return embeddings"],"exampleFix":"// before\nMemory.from_config({\"embedder\": {\"provider\": \"ollama\", \"config\": {\"model\": \"llama3\"}}})  # ValueError: no embeddings\n\n# after\nMemory.from_config({\"embedder\": {\"provider\": \"ollama\", \"config\": {\"model\": \"nomic-embed-text\"}}})","handlingStrategy":"validation","validationCode":"import ollama\n\nresp = ollama.Client(host=\"http://localhost:11434\").embed(\n    model=\"nomic-embed-text\", input=\"healthcheck\")\nassert resp.get(\"embeddings\"), \"chosen model produces no embeddings — use an embedding model\"","typeGuard":"EMBEDDING_MODELS = {\"nomic-embed-text\", \"mxbai-embed-large\", \"snowflake-arctic-embed\", \"all-minilm\"}\n\ndef is_embedding_model(model: str) -> bool:\n    return model in EMBEDDING_MODELS or \"embed\" in model","tryCatchPattern":"try:\n    vec = embedder.embed(text)\nexcept ValueError as e:\n    if \"returned no embeddings\" in str(e):\n        # model is wrong or server misbehaving — surface clearly\n        raise RuntimeError(f\"Ollama model '{embedder.config.model}' is not usable for embedding\") from e\n    raise","preventionTips":["Use a dedicated embedding model for the embedder config, never the chat model","Health-check embed() once at startup before processing real traffic","Keep the Ollama server updated and models fully pulled"],"tags":["python","ollama","embeddings","model-config","local-server","mem0"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}