我正在使用 Spring-AI 将字符串嵌入到向量中。这是代码片段
@Autowired
private EmbeddingClient embeddingClient;
String text = title + " " + overview;
List<Double> embeddings = embeddingClient.embed(text);
我遇到以下异常
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]
可能的问题是什么?
好吧,我终于解决了这个错误。
我只需要将以下依赖项添加到 pom.xml 中
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
</dependency>
希望它能帮助其他遇到此类问题的人。