Fix EmbeddingOptions
- Remove the explicit EMPTY check when merging the default embedding options - Use the builder to build the default embedding options
This commit is contained in:
committed by
Mark Pollack
parent
69cd3173f7
commit
adefca13f8
@@ -130,7 +130,7 @@ public class BedrockCohereEmbeddingModel extends AbstractEmbeddingModel {
|
||||
.truncate(CohereEmbeddingRequest.Truncate.NONE)
|
||||
.build();
|
||||
|
||||
if (requestOptions != null && !EmbeddingOptions.EMPTY.equals(requestOptions)) {
|
||||
if (requestOptions != null) {
|
||||
options = ModelOptionsUtils.merge(requestOptions, options, BedrockCohereEmbeddingOptions.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ public class PostgresMlEmbeddingModel extends AbstractEmbeddingModel implements
|
||||
PostgresMlEmbeddingOptions options = (this.defaultOptions != null) ? this.defaultOptions
|
||||
: PostgresMlEmbeddingOptions.builder().build();
|
||||
|
||||
if (requestOptions != null && !EmbeddingOptions.EMPTY.equals(requestOptions)) {
|
||||
if (requestOptions != null) {
|
||||
options = ModelOptionsUtils.merge(requestOptions, options, PostgresMlEmbeddingOptions.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.document.MetadataMode;
|
||||
import org.springframework.ai.embedding.EmbeddingOptions;
|
||||
import org.springframework.ai.embedding.EmbeddingOptionsBuilder;
|
||||
import org.springframework.ai.embedding.EmbeddingRequest;
|
||||
import org.springframework.ai.embedding.EmbeddingResponse;
|
||||
import org.springframework.ai.embedding.EmbeddingResponseMetadata;
|
||||
@@ -179,7 +179,8 @@ class PostgresMlEmbeddingModelIT {
|
||||
true);
|
||||
embeddingModel.afterPropertiesSet();
|
||||
|
||||
var request1 = new EmbeddingRequest(List.of("Hello World!", "Spring AI!", "LLM!"), EmbeddingOptions.EMPTY);
|
||||
var request1 = new EmbeddingRequest(List.of("Hello World!", "Spring AI!", "LLM!"),
|
||||
EmbeddingOptionsBuilder.builder().build());
|
||||
|
||||
EmbeddingResponse embeddingResponse = embeddingModel.call(request1);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.ai.embedding.EmbeddingOptions;
|
||||
import org.springframework.ai.embedding.EmbeddingOptionsBuilder;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -62,7 +62,7 @@ public class PostgresMlEmbeddingOptionsTests {
|
||||
var jdbcTemplate = Mockito.mock(JdbcTemplate.class);
|
||||
PostgresMlEmbeddingModel embeddingModel = new PostgresMlEmbeddingModel(jdbcTemplate);
|
||||
|
||||
PostgresMlEmbeddingOptions options = embeddingModel.mergeOptions(EmbeddingOptions.EMPTY);
|
||||
PostgresMlEmbeddingOptions options = embeddingModel.mergeOptions(EmbeddingOptionsBuilder.builder().build());
|
||||
|
||||
// Default options
|
||||
assertThat(options.getTransformer()).isEqualTo(PostgresMlEmbeddingModel.DEFAULT_TRANSFORMER_MODEL);
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.embedding.DocumentEmbeddingModel;
|
||||
import org.springframework.ai.embedding.DocumentEmbeddingRequest;
|
||||
import org.springframework.ai.embedding.Embedding;
|
||||
import org.springframework.ai.embedding.EmbeddingOptions;
|
||||
import org.springframework.ai.embedding.EmbeddingResponse;
|
||||
import org.springframework.ai.embedding.EmbeddingResponseMetadata;
|
||||
import org.springframework.ai.embedding.EmbeddingResultMetadata;
|
||||
@@ -101,7 +100,7 @@ public class VertexAiMultimodalEmbeddingModel implements DocumentEmbeddingModel
|
||||
// merge the runtime and default vertex ai options.
|
||||
VertexAiMultimodalEmbeddingOptions mergedOptions = this.defaultOptions;
|
||||
|
||||
if (request.getOptions() != null && request.getOptions() != EmbeddingOptions.EMPTY) {
|
||||
if (request.getOptions() != null) {
|
||||
var defaultOptionsCopy = VertexAiMultimodalEmbeddingOptions.builder().from(this.defaultOptions).build();
|
||||
mergedOptions = ModelOptionsUtils.merge(request.getOptions(), defaultOptionsCopy,
|
||||
VertexAiMultimodalEmbeddingOptions.class);
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.springframework.ai.chat.metadata.Usage;
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.embedding.AbstractEmbeddingModel;
|
||||
import org.springframework.ai.embedding.Embedding;
|
||||
import org.springframework.ai.embedding.EmbeddingOptions;
|
||||
import org.springframework.ai.embedding.EmbeddingRequest;
|
||||
import org.springframework.ai.embedding.EmbeddingResponse;
|
||||
import org.springframework.ai.embedding.EmbeddingResponseMetadata;
|
||||
@@ -167,7 +166,7 @@ public class VertexAiTextEmbeddingModel extends AbstractEmbeddingModel {
|
||||
|
||||
VertexAiTextEmbeddingOptions mergedOptions = this.defaultOptions;
|
||||
|
||||
if (request.getOptions() != null && request.getOptions() != EmbeddingOptions.EMPTY) {
|
||||
if (request.getOptions() != null) {
|
||||
var defaultOptionsCopy = VertexAiTextEmbeddingOptions.builder().from(this.defaultOptions).build();
|
||||
mergedOptions = ModelOptionsUtils.merge(request.getOptions(), defaultOptionsCopy,
|
||||
VertexAiTextEmbeddingOptions.class);
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.ai.embedding.EmbeddingOptions;
|
||||
import org.springframework.ai.embedding.EmbeddingOptionsBuilder;
|
||||
import org.springframework.ai.embedding.EmbeddingResponse;
|
||||
import org.springframework.ai.watsonx.api.WatsonxAiApi;
|
||||
import org.springframework.ai.watsonx.api.WatsonxAiEmbeddingRequest;
|
||||
@@ -73,7 +74,7 @@ public class WatsonxAiEmbeddingModelTest {
|
||||
void createRequestWithNoOptions() {
|
||||
List<String> inputs = List.of("test");
|
||||
WatsonxAiEmbeddingRequest request = this.embeddingModel.watsonxAiEmbeddingRequest(inputs,
|
||||
EmbeddingOptions.EMPTY);
|
||||
EmbeddingOptionsBuilder.builder().build());
|
||||
|
||||
assertThat(request.getModel()).isEqualTo(WatsonxAiEmbeddingOptions.DEFAULT_MODEL);
|
||||
assertThat(request.getInputs().size()).isEqualTo(inputs.size());
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.embedding.DocumentEmbeddingRequest;
|
||||
import org.springframework.ai.embedding.EmbeddingOptions;
|
||||
import org.springframework.ai.embedding.EmbeddingOptionsBuilder;
|
||||
import org.springframework.ai.embedding.EmbeddingResponse;
|
||||
import org.springframework.ai.embedding.EmbeddingResultMetadata;
|
||||
import org.springframework.ai.vertexai.embedding.multimodal.VertexAiMultimodalEmbeddingModel;
|
||||
@@ -105,7 +105,7 @@ public class VertexAiTextEmbeddingModelAutoConfigurationIT {
|
||||
var document = new Document("Hello World");
|
||||
|
||||
DocumentEmbeddingRequest embeddingRequest = new DocumentEmbeddingRequest(List.of(document),
|
||||
EmbeddingOptions.EMPTY);
|
||||
EmbeddingOptionsBuilder.builder().build());
|
||||
|
||||
EmbeddingResponse embeddingResponse = multiModelEmbeddingModel.call(embeddingRequest);
|
||||
assertThat(embeddingResponse.getResults()).hasSize(1);
|
||||
|
||||
Reference in New Issue
Block a user