Bug Description

The AzureVectorStore throws an UnsupportedOperationException when performing similarity searches. The error occurs because the code attempts to modify an immutable metadata map during result processing.

Environment

  • Spring AI version: 1.0.1
  • Java version: 21

Steps to Reproduce

  1. Configure AzureVectorStore with Azure AI Search backend
  2. Index documents using Azure AI Search indexer with skillset (document chunking and embedding generation)
  3. Perform a similarity search using Spring AI's VectorStore interface: ```java List results = vectorStore.similaritySearch("your query here");

Comment From: jinlee1703

I can reproduce this when the Azure result metadata map is immutable. The mapping logic later injects distance into the metadata and triggers UnsupportedOperationException. I’ll submit a PR to defensively copy incoming metadata into a mutable map before building the Document (and then set DocumentMetadata.DISTANCE). This mirrors the defensive fixes we’ve applied in other stores.

Comment From: injae-kim

Fix PR: https://github.com/spring-projects/spring-ai/pull/4131 PTAL :)