mem0ai/mem0 · error · Error

Ollama embed() returned no embeddings for model '${this.mode

Error message

Ollama embed() returned no embeddings for model '${this.model}'

What it means

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.

Source

Thrown at mem0-ts/src/oss/src/embeddings/ollama.ts:48

    );
    this.ollama = new sdk.Ollama({ host: this.host });
  }

  async embed(text: string): Promise<number[]> {
    await this.ensureClient();
    try {
      await this.ensureModelExists();
    } catch (err) {
      logger.error(`Error ensuring model exists: ${err}`);
    }
    // Coerce defensively since callers may pass values parsed from untrusted LLM JSON output.
    const input = typeof text === "string" ? text : JSON.stringify(text);
    const response = await this.ollama.embed({
      model: this.model,
      input,
    });
    if (!response.embeddings || response.embeddings.length === 0) {
      throw new Error(
        `Ollama embed() returned no embeddings for model '${this.model}'`,
      );
    }
    return response.embeddings[0];
  }

  async embedBatch(texts: string[]): Promise<number[][]> {
    const response = await Promise.all(texts.map((text) => this.embed(text)));
    return response;
  }

  private static normalizeModelName(name: string): string {
    return name.includes(":") ? name : `${name}:latest`;
  }

  private async ensureModelExists(): Promise<boolean> {
    if (this.initialized) {
      return true;

View on GitHub (pinned to 001c235229)

Solutions

  1. Pull and use a real embedding model: ollama pull nomic-embed-text, then set config.model = 'nomic-embed-text'
  2. 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
  3. Upgrade Ollama to a recent version if the manual call returns empty for a valid embedding model
  4. Re-pull the model if it is corrupted (ollama rm <model> && ollama pull <model>)

Example fix

// before
const embedder = new OllamaEmbedder({ model: "llama3" }); // chat model -> empty embeddings

// after
const embedder = new OllamaEmbedder({ model: "nomic-embed-text" });
Defensive patterns

Strategy: validation

Validate before calling

const EMBEDDING_MODELS = new Set(["nomic-embed-text", "mxbai-embed-large", "snowflake-arctic-embed", "all-minilm", "bge-m3"]);
if (!EMBEDDING_MODELS.has(modelName)) {
  throw new Error(`'${modelName}' is not a known Ollama embedding model`);
}

Type guard

function isNoEmbeddingsError(err: unknown): boolean {
  return err instanceof Error && err.message.includes("returned no embeddings");
}

Try / catch

try {
  return await embedder.embed(text);
} catch (err) {
  if (err instanceof Error && err.message.includes("Ollama embed() returned no embeddings")) {
    throw new Error(`Model '${modelName}' produced no embeddings - use an embedding model like nomic-embed-text`);
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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