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
- Configure AzureVectorStore with Azure AI Search backend
- Index documents using Azure AI Search indexer with skillset (document chunking and embedding generation)
- 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 :)