{"record":{"id":"fc3d2fe8ec7b6ae4","repo":"n8n-io/n8n","slug":"unexpected-embedding-response-from-bedrock","errorCode":null,"errorMessage":"Unexpected embedding response from Bedrock","messagePattern":"Unexpected embedding response from Bedrock","errorType":"exception","errorClass":"OperationalError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAwsBedrock/BedrockInvokeModelEmbeddings.ts","lineNumber":84,"sourceCode":"\t\t\t\t\taccept: 'application/json',\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst body = jsonParse<EmbeddingResponseBody>(new TextDecoder().decode(response.body));\n\t\t\tif (Array.isArray(body.embedding)) {\n\t\t\t\treturn body.embedding;\n\t\t\t}\n\t\t\tconst titanTyped = selectEmbeddingType(body.embeddingsByType);\n\t\t\tif (titanTyped) {\n\t\t\t\treturn titanTyped;\n\t\t\t}\n\t\t\tconst rows = Array.isArray(body.embeddings)\n\t\t\t\t? body.embeddings\n\t\t\t\t: selectEmbeddingType(body.embeddings);\n\t\t\tconst first = rows?.[0];\n\t\t\tif (Array.isArray(first)) {\n\t\t\t\treturn first;\n\t\t\t}\n\t\t\tthrow new OperationalError('Unexpected embedding response from Bedrock');\n\t\t});\n\t}\n\n\tasync embedDocuments(documents: string[]): Promise<number[][]> {\n\t\treturn await Promise.all(\n\t\t\tdocuments.map(async (document) => await this.embed(document, 'search_document')),\n\t\t);\n\t}\n\n\tasync embedQuery(text: string): Promise<number[]> {\n\t\treturn await this.embed(text, 'search_query');\n\t}\n}\n","sourceCodeStart":66,"sourceCodeEnd":98,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAwsBedrock/BedrockInvokeModelEmbeddings.ts#L66-L98","documentation":"Thrown by BedrockInvokeModelEmbeddings.embed() when the model response body could not be coerced into a flat array of numbers after every known shape was tried: body.embeddingsByType (Titan typed selectors), body.embeddings as a raw array, and selectEmbeddingType(body.embeddings). It is an OperationalError, signalling a transient/unexpected upstream response shape rather than a user configuration fault.","triggerScenarios":"An AWS Bedrock InvokeModel call returns an embedding payload whose structure differs from every shape the code understands — e.g. a Cohere or new model returning {data: [{embedding: [...]}]} without an embeddings/embeddingsByType field, a model returning a 200 with an empty body, or a region/model mismatch returning a non-embedding JSON object.","commonSituations":"Selecting a Bedrock model that does not output embeddings (e.g. a text-generation model chosen by mistake); AWS rolling out a response-format change; cross-region inference profile returning a wrapped payload; IAM/network layer truncating the body.","solutions":["Confirm the selected Bedrock model id is an embeddings model (e.g. amazon.titan-embed-text-v2:0, cohere.embed-english-v3).","Reproduce the raw InvokeModel response with the AWS CLI (aws bedrock invoke-model) and compare its JSON keys against embeddings / embeddingsByType.","If the model uses a new shape, extend BedrockInvokeModelEmbeddings to handle it (add a branch before the throw) or switch to a supported model.","Retry once to rule out a truncated streaming response; if intermittent, inspect retries/timeout options on the node."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before relying on the embedding, validate the body shape\nfunction extractEmbedding(body: any): number[] | null {\n  const typed = selectEmbeddingType(body.embeddingsByType);\n  if (typed) return typed;\n  const rows = Array.isArray(body.embeddings) ? body.embeddings : selectEmbeddingType(body.embeddings);\n  const first = rows?.[0];\n  return Array.isArray(first) ? first : null;\n}\nconst vec = extractEmbedding(body);\nif (!vec) throw new Error('Embedding response shape not recognised; inspect body');","typeGuard":"const isEmbeddingResponse = (b: unknown): b is { embeddings: number[][] } =>\n  typeof b === 'object' && b !== null &&\n  Array.isArray((b as any).embeddings) &&\n  Array.isArray((b as any).embeddings[0]);","tryCatchPattern":"try {\n  return extractEmbedding(body) ?? throwOperational();\n} catch (e) {\n  // log raw body for support, then retry once with a known-good model\n  logger.warn({ body }, 'Unrecognised Bedrock embedding response');\n  throw e;\n}","preventionTips":["Pin model ids to supported Bedrock embeddings models.","Add an integration test that hits a sandbox Bedrock account and asserts the response shape on every model upgrade.","Log the raw InvokeModel body when this path is reachable so future shape changes are diagnosable."],"tags":["aws","bedrock","embeddings","upstream-response","operational"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}