{"record":{"id":"e9f88d6912e09936","repo":"mem0ai/mem0","slug":"ollama-embed-returned-no-embeddings-for-model","errorCode":null,"errorMessage":"Ollama embed() returned no embeddings for model '${this.model}'","messagePattern":"Ollama embed\\(\\) returned no embeddings for model '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/embeddings/ollama.ts","lineNumber":48,"sourceCode":"    );\n    this.ollama = new sdk.Ollama({ host: this.host });\n  }\n\n  async embed(text: string): Promise<number[]> {\n    await this.ensureClient();\n    try {\n      await this.ensureModelExists();\n    } catch (err) {\n      logger.error(`Error ensuring model exists: ${err}`);\n    }\n    // Coerce defensively since callers may pass values parsed from untrusted LLM JSON output.\n    const input = typeof text === \"string\" ? text : JSON.stringify(text);\n    const response = await this.ollama.embed({\n      model: this.model,\n      input,\n    });\n    if (!response.embeddings || response.embeddings.length === 0) {\n      throw new Error(\n        `Ollama embed() returned no embeddings for model '${this.model}'`,\n      );\n    }\n    return response.embeddings[0];\n  }\n\n  async embedBatch(texts: string[]): Promise<number[][]> {\n    const response = await Promise.all(texts.map((text) => this.embed(text)));\n    return response;\n  }\n\n  private static normalizeModelName(name: string): string {\n    return name.includes(\":\") ? name : `${name}:latest`;\n  }\n\n  private async ensureModelExists(): Promise<boolean> {\n    if (this.initialized) {\n      return true;","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/embeddings/ollama.ts#L30-L66","documentation":"The OllamaEmbedder calls ollama.embed() and requires a non-empty embeddings array in the response. Ollama can return 200 with an empty embeddings list (typically when the pulled model is not an embedding model or is incompatible with the embed endpoint), which the SDK treats as a hard failure rather than returning garbage.","triggerScenarios":"Calling embed()/embedBatch() with this.model set to a generative/chat model (e.g. llama3, mistral) instead of an embedding model (e.g. nomic-embed-text, mxbai-embed-large, snowflake-arctic-embed); an outdated Ollama version whose embed API shape differs; a corrupted model pull that returns empty vectors.","commonSituations":"Reusing the same model name for LLM and embedder in Memory config; defaulting to a chat model because OLLAMA_MODEL is set; after upgrading Ollama the embed endpoint behavior changed; partially downloaded model.","solutions":["Pull and use a real embedding model: ollama pull nomic-embed-text, then set config.model = 'nomic-embed-text'","Verify outside the SDK: curl http://localhost:11434/api/embed -d '{\"model\":\"nomic-embed-text\",\"input\":\"hi\"}' and check the embeddings array is non-empty","Upgrade Ollama to a recent version if the manual call returns empty for a valid embedding model","Re-pull the model if it is corrupted (ollama rm <model> && ollama pull <model>)"],"exampleFix":"// before\nconst embedder = new OllamaEmbedder({ model: \"llama3\" }); // chat model -> empty embeddings\n\n// after\nconst embedder = new OllamaEmbedder({ model: \"nomic-embed-text\" });","handlingStrategy":"validation","validationCode":"const EMBEDDING_MODELS = new Set([\"nomic-embed-text\", \"mxbai-embed-large\", \"snowflake-arctic-embed\", \"all-minilm\", \"bge-m3\"]);\nif (!EMBEDDING_MODELS.has(modelName)) {\n  throw new Error(`'${modelName}' is not a known Ollama embedding model`);\n}","typeGuard":"function isNoEmbeddingsError(err: unknown): boolean {\n  return err instanceof Error && err.message.includes(\"returned no embeddings\");\n}","tryCatchPattern":"try {\n  return await embedder.embed(text);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"Ollama embed() returned no embeddings\")) {\n    throw new Error(`Model '${modelName}' produced no embeddings - use an embedding model like nomic-embed-text`);\n  }\n  throw err;\n}","preventionTips":["Use a dedicated embedding model in OllamaEmbedder config; never reuse the chat model name","Smoke-test with curl to /api/embed after pulling a model","Keep an allowlist of embedding models validated at startup"],"tags":["ollama","embeddings","local-server","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}