{"record":{"id":"05bd1b56db80f3b5","repo":"n8n-io/n8n","slug":"nvidia-embeddings-api-returned-data-length-embe","errorCode":null,"errorMessage":"NVIDIA embeddings API returned ${data.length} embeddings for a batch of ${expected} inputs","messagePattern":"NVIDIA embeddings API returned (.+?) embeddings for a batch of (.+?) inputs","errorType":"exception","errorClass":"OperationalError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsNvidia/helpers.ts","lineNumber":70,"sourceCode":"\t\t\t\tmodel: this.model,\n\t\t\t\tinput: batch,\n\t\t\t\tinput_type: inputType,\n\t\t\t};\n\t\t\tif (this.dimensions) params.dimensions = this.dimensions;\n\t\t\tif (this.encodingFormat) params.encoding_format = this.encodingFormat;\n\t\t\tconst { data } = await this.embeddingWithRetry(params);\n\t\t\treturn { expected: batch.length, data };\n\t\t});\n\n\t\tconst batchResponses = await Promise.all(batchRequests);\n\n\t\t// The caller maps each input text to the embedding at the same position, so every batch must\n\t\t// return exactly one embedding per input. Flatten by input position (like the base class) and\n\t\t// fail loudly on a malformed response rather than silently dropping or shifting embeddings.\n\t\tconst embeddings: number[][] = [];\n\t\tfor (const { expected, data } of batchResponses) {\n\t\t\tif (data.length !== expected) {\n\t\t\t\tthrow new OperationalError(\n\t\t\t\t\t`NVIDIA embeddings API returned ${data.length} embeddings for a batch of ${expected} inputs`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (const entry of data) {\n\t\t\t\tembeddings.push(entry.embedding);\n\t\t\t}\n\t\t}\n\t\treturn embeddings;\n\t}\n}\n","sourceCodeStart":52,"sourceCodeEnd":81,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/embeddings/EmbeddingsNvidia/helpers.ts#L52-L81","documentation":"An OperationalError raised while flattening NVIDIA embeddings batch responses: each batch must return exactly one embedding per input so the caller can zip them by position. If data.length !== expected for any batch, embedding alignment would be corrupted, so the helper fails loudly instead of silently shifting vectors.","triggerScenarios":"NVIDIA's /v1/embeddings endpoint returns fewer or more entries than the number of input texts in a batch — caused by the API dropping empty inputs, deduplicating identical texts, a rate-limit returning a partial body, or a model cap on batch size that truncates the response.","commonSituations":"Sending a batch larger than the model's max batch size; sending duplicate or whitespace-only strings the API collapses; endpoint misbehaviour under load; using a non-embedding NVIDIA model that returns a single aggregate vector.","solutions":["Reduce the batch size (chunk documents before calling embedDocuments) to stay under the NVIDIA model's limit.","Sanitise inputs — remove empty/whitespace strings and de-duplicate before embedding, then re-expand the result.","Confirm the NVIDIA model id is an embeddings model (e.g. NV-Embed-QA, nvidia/embedqa-4).","Retry once; if intermittent, lower concurrency or add maxRetries/timeout options."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Chunk inputs to a safe batch size before calling embedDocuments\nconst MAX_BATCH = 16; // consult NVIDIA model docs\nfor (let i = 0; i < documents.length; i += MAX_BATCH) {\n  const batch = documents.slice(i, i + MAX_BATCH).filter(d => d.trim().length > 0);\n  // ... call embedWithRetry(batch)\n}","typeGuard":"const matchesBatchSize = (data: unknown[], expected: number): boolean =>\n  Array.isArray(data) && data.length === expected;","tryCatchPattern":"try {\n  return embedBatch(batch);\n} catch (e) {\n  if (/returned \\d+ embeddings for a batch of/i.test((e as Error).message)) {\n    // retry with batch size 1 to localise the failing input\n    return batch.map(one => embedBatch([one])[0]);\n  }\n  throw e;\n}","preventionTips":["Cap batch size below the NVIDIA model's documented maximum.","Sanitise and de-duplicate inputs before embedding.","Confirm the model id is an embeddings model before invoking."],"tags":["nvidia","embeddings","batch","upstream-response","operational"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}