How to fix Error with the Azure Javascript SDK for Ai Search: unexpected 'StartObject' node was found for property named 'metadata' when reading from the JSON reader

Kent Morgan 0 Reputation points
2024-10-22T17:52:26.2266667+00:00

I'm trying to make calls to a Azure Ai Search index I have already set up. Specifically I'm trying to add documents via the AzureAISearchVectorStore.addDocuments from the "@langchain/community/vectorstores/azure_aisearch" package.

No matter what I've tried I get the error:

Azure AI Search uploadDocuments batch failed: RestError: The request is invalid. Details: An unexpected 'StartObject' node was found for property named 'metadata' when reading from the JSON reader. A 'PrimitiveValue' node was expected

Even if I omit metadata entirely.

My code looks something like this:


const embeddings = new AzureOpenAIEmbeddings({
  maxRetries: 1,
  // azureOpenAIApiKey etc in env
});

const searchClient = new SearchClient
Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,083 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
1,003 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kent Morgan 0 Reputation points
    2024-10-22T18:08:11.46+00:00

    Hmmm, it looks like the python langchain_core.documents Documents class was casting metadata to a stringified object. That may be my issue.

    Looks like there's no way to do the same in the JS version


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.