mem0ai/mem0 · error · Error

HuggingFace embed() returned no embeddings for model '${this

Error message

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

What it means

Thrown by HuggingFaceEmbedder.embed() when the TEI/OpenAI-compatible response contains no data array or an empty one for the single input text. The request itself succeeded (no HTTP error), but the body lacked usable embedding rows — typically a wrong baseURL pointing at a non-TEI server, an auth-gated route returning an unexpected JSON shape, or a model/endpoint mismatch. The message includes the configured model name.

Source

Thrown at mem0-ts/src/oss/src/embeddings/huggingface.ts:52

          "http://localhost:8080/v1).",
      );
    }

    this.openai = new OpenAI({
      apiKey: config.apiKey || process.env.HUGGINGFACE_API_KEY || "hf",
      baseURL,
    });
    // TEI ignores the model field; default mirrors the Python provider.
    this.model = config.model || "tei";
  }

  async embed(text: string): Promise<number[]> {
    const response = await this.openai.embeddings.create({
      model: this.model,
      input: text,
    });
    if (!response.data || response.data.length === 0) {
      throw new Error(
        `HuggingFace embed() returned no embeddings for model '${this.model}'`,
      );
    }
    return response.data[0].embedding;
  }

  async embedBatch(texts: string[]): Promise<number[][]> {
    if (texts.length === 0) {
      return [];
    }
    const response = await this.openai.embeddings.create({
      model: this.model,
      input: texts,
    });
    const embeddings = response.data
      .sort((a, b) => a.index - b.index)
      .map((item) => item.embedding);
    if (embeddings.length !== texts.length) {

View on GitHub (pinned to 001c235229)

Solutions

  1. Confirm the URL ends with the OpenAI-compatible base (typically http://host:8080/v1) and test directly: curl -H 'Content-Type: application/json' -d '{"model":"tei","input":"hi"}' $BASE/embeddings
  2. Check the TEI container logs — a 200 with empty data usually means the model failed to load
  3. Verify apiKey is accepted; some gated setups return non-embedding JSON on auth failure

Example fix

// before
config: { huggingfaceBaseUrl: 'http://localhost:8080' } // missing /v1

// after
config: { huggingfaceBaseUrl: 'http://localhost:8080/v1' }
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight the endpoint shape before wiring memory
const res = await fetch(`${base}/embeddings`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey ?? 'hf'}` },
  body: JSON.stringify({ model: 'tei', input: 'ping' }),
});
const body = await res.json();
if (!Array.isArray(body.data) || body.data.length === 0) throw new Error('Endpoint is not a TEI/OpenAI-compatible embeddings server');

Try / catch

try {
  vec = await embedder.embed(text);
} catch (e) {
  if (e instanceof Error && e.message.includes('returned no embeddings for model')) {
    // endpoint shape/auth problem: verify /v1 path and server logs; not transient
    throw new Error('TEI endpoint returned no embedding rows — check base URL path and model load');
  }
  throw e;
}

Prevention

When it happens

Trigger: baseURL pointing at the HuggingFace Hub page or a plain JSON API instead of the TEI OpenAI-compatible endpoint; a gateway that returns 200 with an error payload (so no exception) whose body has no 'data'; server-side model not loaded so the embeddings route returns an empty result.

Common situations: Using https://api-inference.huggingface.co without the OpenAI-compatible path; reverse proxy stripping the response; TEI started without a loaded model.

Related errors


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