Error while embedding string using spring-ai

22 views Asked by At

I am using Spring-AI to embed string into vector. Here is the code snippet

@Autowired
private EmbeddingClient embeddingClient;

String text = title + " " + overview;
List<Double> embeddings = embeddingClient.embed(text);

I am getting the following exception

org.springframework.web.client.RestClientException: Error while extracting response for type [org.springframework.ai.openai.api.OpenAiApi$EmbeddingList<org.springframework.ai.openai.api.OpenAiApi$Embedding>] and content type [application/json;charset=utf-8]
at org.springframework.web.client.DefaultRestClient.readWithMessageConverters(DefaultRestClient.java:231) ~[spring-web-6.1.2.jar:6.1.2]
at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.readBody(DefaultRestClient.java:659) ~[spring-web-6.1.2.jar:6.1.2]

Caused by: java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1796) ~[na:na]

What could be the probable issue?

1

There are 1 answers

0
Swarup Saha On

Well, at last I was able to solve the error.

I just needed to add the following dependency into the pom.xml

    <dependency>
        <groupId>org.apache.httpcomponents.client5</groupId>
        <artifactId>httpclient5</artifactId>
        <version>5.2.1</version>
    </dependency>

Hope it will help others if they face such issues.