{"record":{"id":"bcc2bde471033dd2","repo":"mem0ai/mem0","slug":"huggingface-embed-returned-no-embeddings-for-mod","errorCode":null,"errorMessage":"HuggingFace embed() returned no embeddings for model '${this.model}'","messagePattern":"HuggingFace embed\\(\\) returned no embeddings for model '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/embeddings/huggingface.ts","lineNumber":52,"sourceCode":"          \"http://localhost:8080/v1).\",\n      );\n    }\n\n    this.openai = new OpenAI({\n      apiKey: config.apiKey || process.env.HUGGINGFACE_API_KEY || \"hf\",\n      baseURL,\n    });\n    // TEI ignores the model field; default mirrors the Python provider.\n    this.model = config.model || \"tei\";\n  }\n\n  async embed(text: string): Promise<number[]> {\n    const response = await this.openai.embeddings.create({\n      model: this.model,\n      input: text,\n    });\n    if (!response.data || response.data.length === 0) {\n      throw new Error(\n        `HuggingFace embed() returned no embeddings for model '${this.model}'`,\n      );\n    }\n    return response.data[0].embedding;\n  }\n\n  async embedBatch(texts: string[]): Promise<number[][]> {\n    if (texts.length === 0) {\n      return [];\n    }\n    const response = await this.openai.embeddings.create({\n      model: this.model,\n      input: texts,\n    });\n    const embeddings = response.data\n      .sort((a, b) => a.index - b.index)\n      .map((item) => item.embedding);\n    if (embeddings.length !== texts.length) {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/embeddings/huggingface.ts#L34-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"Using https://api-inference.huggingface.co without the OpenAI-compatible path; reverse proxy stripping the response; TEI started without a loaded model.","solutions":["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","Check the TEI container logs — a 200 with empty data usually means the model failed to load","Verify apiKey is accepted; some gated setups return non-embedding JSON on auth failure"],"exampleFix":"// before\nconfig: { huggingfaceBaseUrl: 'http://localhost:8080' } // missing /v1\n\n// after\nconfig: { huggingfaceBaseUrl: 'http://localhost:8080/v1' }","handlingStrategy":"try-catch","validationCode":"// Pre-flight the endpoint shape before wiring memory\nconst res = await fetch(`${base}/embeddings`, {\n  method: 'POST',\n  headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey ?? 'hf'}` },\n  body: JSON.stringify({ model: 'tei', input: 'ping' }),\n});\nconst body = await res.json();\nif (!Array.isArray(body.data) || body.data.length === 0) throw new Error('Endpoint is not a TEI/OpenAI-compatible embeddings server');","typeGuard":null,"tryCatchPattern":"try {\n  vec = await embedder.embed(text);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('returned no embeddings for model')) {\n    // endpoint shape/auth problem: verify /v1 path and server logs; not transient\n    throw new Error('TEI endpoint returned no embedding rows — check base URL path and model load');\n  }\n  throw e;\n}","preventionTips":["End the base URL with /v1 (OpenAI-compatible mount) — the bare server root will not work","Health-check the TEI server at startup with a one-off curl to /models and /embeddings","Check TEI container logs when this fires: a 200 with empty data usually means the model never loaded"],"tags":["huggingface","tei","embeddings","runtime","self-hosted"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}