{"record":{"id":"ff5547072fad72a9","repo":"mem0ai/mem0","slug":"aws-bedrock-model-this-model-returned-no-embedd","errorCode":null,"errorMessage":"AWS Bedrock model ${this.model} returned no embedding for one or more inputs","messagePattern":"AWS Bedrock model (.+?) returned no embedding for one or more inputs","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/embeddings/aws_bedrock.ts","lineNumber":255,"sourceCode":"\n    // Validated outside the try so this message is not re-wrapped by the catch.\n    // Cohere v3 replies with a flat `embeddings` array; v4 (when\n    // embedding_types is requested) nests it under `.float`.\n    const embeddings = this.isCohereModel()\n      ? Array.isArray(payload.embeddings)\n        ? payload.embeddings\n        : payload.embeddings?.float\n      : payload.embedding && [payload.embedding];\n\n    // `[]` is truthy, so a lone zero-length vector must be checked for\n    // explicitly -- otherwise it passes the length check and hands the\n    // caller an empty embedding instead of an error.\n    if (\n      !embeddings ||\n      embeddings.length !== texts.length ||\n      embeddings.some((embedding) => embedding.length === 0)\n    ) {\n      throw new Error(\n        `AWS Bedrock model ${this.model} returned no embedding for one or more inputs`,\n      );\n    }\n    return embeddings;\n  }\n\n  async embed(\n    text: string,\n    memoryAction?: \"add\" | \"update\" | \"search\",\n  ): Promise<number[]> {\n    return (await this.invoke([text], memoryAction))[0];\n  }\n\n  async embedBatch(\n    texts: string[],\n    memoryAction?: \"add\" | \"update\" | \"search\",\n  ): Promise<number[][]> {\n    if (texts.length === 0) return [];","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/embeddings/aws_bedrock.ts#L237-L273","documentation":"Thrown by the AWS Bedrock embedder after a successful invoke when the response shape is unusable: no embeddings array at all, a count that does not match the number of input texts, or at least one zero-length vector. The explicit zero-length check exists because an empty array is truthy in JS and would otherwise slip through a naive length check and hand the caller a degenerate embedding.","triggerScenarios":"Bedrock returns partial results (batch throttled mid-response); a Cohere v3 flat payload vs v4 payload-shape mismatch; payload.embeddings undefined because the response body was an error object that still parsed as JSON; one input string rejected (e.g. empty text after preprocessing) yielding a null/empty vector.","commonSituations":"Sending a batch larger than the model limit so the service returns fewer vectors; empty-string inputs in the batch; model family whose response format changed (Cohere v3 'embeddings' vs v4 nested '.float'); intermittent partial responses under load.","solutions":["Log texts.length and the raw payload (or catch and inspect) to see which of the three conditions fired: missing / count mismatch / zero-length vector","Filter empty or whitespace-only strings from the batch before embedding","Reduce batch size below the model's per-request input limit (Cohere embed on Bedrock allows far fewer than unbounded arrays)","Confirm the configured model name matches the response format you expect — do not mix a v4 model ID with v3 handling assumptions"],"exampleFix":"// before\nconst vectors = await embedder.embedBatch(allTexts); // 1 empty string in batch -> zero-length vector\n\n// after\nconst clean = allTexts.map((t) => t.trim()).filter((t) => t.length > 0);\nconst vectors = await embedder.embedBatch(clean);","handlingStrategy":"validation","validationCode":"const clean = texts.map((t) => t.trim()).filter((t) => t.length > 0);\nif (clean.length !== texts.length) {\n  // decide how to map vectors back if you drop inputs\n  console.warn(`dropped ${texts.length - clean.length} empty inputs`);\n}\nawait embedder.embedBatch(clean);","typeGuard":null,"tryCatchPattern":"try {\n  vectors = await embedder.embedBatch(batch);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('returned no embedding')) {\n    // data-integrity failure: shrink the batch and retry once; do not use partial vectors\n    vectors = await embedder.embedBatch(batch.slice(0, Math.ceil(batch.length / 2)));\n  } else throw e;\n}","preventionTips":["Filter empty/whitespace strings out of every batch before embedding","Keep batch sizes well under the Bedrock model's per-request input limit","Treat this error as fail-hard: never proceed with partial or zero-length vectors"],"tags":["aws","bedrock","embeddings","data-integrity","runtime"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}