Update VoyageEmbeddings to parse server errors

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • NODE-7340[LangChainJS] add Auto Embedding support
    • 2
    • None
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • 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

            Assignee:
            Raschid Jimenez
            Reporter:
            Raschid Jimenez
            Raschid Jimenez
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: