-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
Ensure this github issue is solved in the LangChain repository: https://github.com/langchain-ai/langchainjs/issues/10031
TLDR: Invalid Voyage config (e.g., bad API key) causes VoyageEmbeddings.embedDocuments() to throw a TypeError when parsing the response instead of surfacing the underlying API error.
Description
Without proper error logging, users with an invalid Voyage configuration (eg: lacking a payment method, using the wrong end points, etc) may remain blocked to address their issue on Atlas.
This error occurs due to embedDocuments() trying to parse an invalid response from embeddingWithRetry(). In this case, the response is expected to be a string but it is in fact a JSON object {detail: 'Provided API key is invalid.'}
Example Code
This code should fail with a server error:
const collection = new MongoClient(MONGODB_URI).db("langchain_test").collection("docs"); const embeddings = new VoyageEmbeddings({ apiKey: "WRONG-API-KEY" }); const vectorStore = new MongoDBAtlasVectorSearch(embeddings, { collection }); await vectorStore.addDocuments([{ pageContent: "string", metadata: {} }]);
Instead, it is failing with a Type Error:
file:///Users/user/Documents/repos/langchain-mongodb/node_modules/@langchain/community/dist/embeddings/voyage.js:64
for (let j = 0; j < batch.length; j += 1) embeddings.push(batchResponse[j].embedding);
^
TypeError: Cannot read properties of undefined (reading '0')
at VoyageEmbeddings.embedDocuments (file:///Users/user/Documents/repos/langchain-mongodb/node_modules/@langchain/community/dist/embeddings/voyage.js:64:75)
at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
at async MongoDBAtlasVectorSearch.addDocuments (file:///Users/user/Documents/repos/langchain-mongodb/node_modules/@langchain/mongodb/dist/vectorstores.js:69:26)
at async file:///Users/user/Documents/repos/langchain-mongodb/report.ts:15:1
Node.js v24.12.0
Acceptance Criteria
- Open a PR agains https://github.com/langchain-ai/langchainjs.
- Surface and throw Voyage's server errors with HTTP status code and message.
- The LangChain team acknowledges the PR