{"record":{"id":"26fe9c0c352eead1","repo":"mem0ai/mem0","slug":"fastembed-embed-returned-no-embeddings","errorCode":null,"errorMessage":"FastEmbed embed() returned no embeddings","messagePattern":"FastEmbed embed\\(\\) returned no embeddings","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/embeddings/fastembed.ts","lineNumber":82,"sourceCode":"    return sdk.FlagEmbedding.init({ model: this.modelName });\n  }\n\n  private normalizeInput(text: string): string {\n    return text.replace(/\\n/g, \" \");\n  }\n\n  async embed(text: string): Promise<number[]> {\n    const normalizedText = this.normalizeInput(text);\n    const model = await this.getEmbeddingModel();\n\n    for await (const batch of model.embed([normalizedText])) {\n      const embedding = batch[0];\n      if (embedding !== undefined) {\n        return embedding;\n      }\n    }\n\n    throw new Error(\"FastEmbed embed() returned no embeddings\");\n  }\n\n  async embedBatch(texts: string[]): Promise<number[][]> {\n    const normalizedTexts = texts.map((text) => this.normalizeInput(text));\n    const model = await this.getEmbeddingModel();\n    const embeddings: number[][] = [];\n\n    for await (const batch of model.embed(normalizedTexts)) {\n      embeddings.push(...batch);\n    }\n\n    return embeddings;\n  }\n}\n","sourceCodeStart":64,"sourceCodeEnd":97,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/embeddings/fastembed.ts#L64-L97","documentation":"Thrown by FastEmbedEmbedder.embed() when iterating the fastembed output stream yields no defined first embedding for the single input text. FastEmbed returns results as async batches; if the stream completes without ever producing batch[0], the SDK cannot return a vector and raises rather than returning undefined. It indicates an anomalous library/model interaction, not bad input text.","triggerScenarios":"A fastembed version whose embed() yields empty arrays for some inputs; model files corrupted after a partial download so inference returns nothing; an edge case where normalized input (e.g. whitespace-only text) produces no output row.","commonSituations":"After upgrading the optional fastembed peer dependency to an incompatible version; interrupted first-run model download leaving broken artifacts in the cache directory.","solutions":["Pin/align the fastembed version with what this mem0-ts release was tested against, then clear the fastembed model cache and let it re-download","Verify with a trivial input: await embedder.embed('hello') — if that also throws, the model artifacts are bad, not your text","Pre-trim inputs and avoid feeding whitespace-only strings"],"exampleFix":"// before\nconst vec = await embedder.embed(userText); // throws on empty stream\n\n// after\nconst text = userText.trim();\nif (!text) throw new Error('refusing to embed empty text');\nconst vec = await embedder.embed(text);","handlingStrategy":"try-catch","validationCode":"const text = raw.trim();\nif (!text) throw new Error('refusing to embed empty text');\nawait embedder.embed(text);","typeGuard":null,"tryCatchPattern":"try {\n  vec = await embedder.embed(text);\n} catch (e) {\n  if (e instanceof Error && e.message === 'FastEmbed embed() returned no embeddings') {\n    // library/model artifact problem: clear the fastembed cache and rebuild once\n    throw new Error('FastEmbed produced no output — clear the ONNX model cache and retry init');\n  }\n  throw e;\n}","preventionTips":["Sanity-test embed('hello') right after constructing the embedder to catch broken model artifacts early","Pin the fastembed peer dependency version that matches your mem0-ts release","If a first-run download is interrupted, delete the fastembed cache directory and re-run"],"tags":["fastembed","embeddings","runtime","onnx"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}