n8n-io/n8n · error · OperationalError
Unexpected embedding response from Bedrock
Error message
Unexpected embedding response from Bedrock
What it means
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.
Source
Thrown at packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsAwsBedrock/BedrockInvokeModelEmbeddings.ts:84
accept: 'application/json',
}),
);
const body = jsonParse<EmbeddingResponseBody>(new TextDecoder().decode(response.body));
if (Array.isArray(body.embedding)) {
return body.embedding;
}
const titanTyped = selectEmbeddingType(body.embeddingsByType);
if (titanTyped) {
return titanTyped;
}
const rows = Array.isArray(body.embeddings)
? body.embeddings
: selectEmbeddingType(body.embeddings);
const first = rows?.[0];
if (Array.isArray(first)) {
return first;
}
throw new OperationalError('Unexpected embedding response from Bedrock');
});
}
async embedDocuments(documents: string[]): Promise<number[][]> {
return await Promise.all(
documents.map(async (document) => await this.embed(document, 'search_document')),
);
}
async embedQuery(text: string): Promise<number[]> {
return await this.embed(text, 'search_query');
}
}
View on GitHub (pinned to 5ac6606e81)
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.
Defensive patterns
Strategy: validation
Validate before calling
// Before relying on the embedding, validate the body shape
function extractEmbedding(body: any): number[] | null {
const typed = selectEmbeddingType(body.embeddingsByType);
if (typed) return typed;
const rows = Array.isArray(body.embeddings) ? body.embeddings : selectEmbeddingType(body.embeddings);
const first = rows?.[0];
return Array.isArray(first) ? first : null;
}
const vec = extractEmbedding(body);
if (!vec) throw new Error('Embedding response shape not recognised; inspect body'); Type guard
const isEmbeddingResponse = (b: unknown): b is { embeddings: number[][] } =>
typeof b === 'object' && b !== null &&
Array.isArray((b as any).embeddings) &&
Array.isArray((b as any).embeddings[0]); Try / catch
try {
return extractEmbedding(body) ?? throwOperational();
} catch (e) {
// log raw body for support, then retry once with a known-good model
logger.warn({ body }, 'Unrecognised Bedrock embedding response');
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- NVIDIA embeddings API returned ${data.length} embeddings for
- Additional Model Request Fields must be valid JSON
- Additional Model Request Fields must be a JSON object
- Cannot embed empty or undefined text
- Documents must be an array
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/fc3d2fe8ec7b6ae4.
Report an issue: GitHub.