diff --git a/spring-ai-model/src/main/java/org/springframework/ai/embedding/DefaultEmbeddingOptions.java b/spring-ai-model/src/main/java/org/springframework/ai/embedding/DefaultEmbeddingOptions.java new file mode 100644 index 00000000000..f76fa65cefb --- /dev/null +++ b/spring-ai-model/src/main/java/org/springframework/ai/embedding/DefaultEmbeddingOptions.java @@ -0,0 +1,48 @@ +/* + * Copyright 2023-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ai.embedding; + +/** + * Default implementation of {@link EmbeddingOptions}. + * + * @author Thomas Vitale + */ +public class DefaultEmbeddingOptions implements EmbeddingOptions { + + private String model; + + private Integer dimensions; + + @Override + public String getModel() { + return this.model; + } + + public void setModel(String model) { + this.model = model; + } + + @Override + public Integer getDimensions() { + return this.dimensions; + } + + public void setDimensions(Integer dimensions) { + this.dimensions = dimensions; + } + +} diff --git a/spring-ai-model/src/main/java/org/springframework/ai/embedding/DefaultEmbeddingOptionsBuilder.java b/spring-ai-model/src/main/java/org/springframework/ai/embedding/DefaultEmbeddingOptionsBuilder.java new file mode 100644 index 00000000000..0db06b262fb --- /dev/null +++ b/spring-ai-model/src/main/java/org/springframework/ai/embedding/DefaultEmbeddingOptionsBuilder.java @@ -0,0 +1,45 @@ +/* + * Copyright 2023-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ai.embedding; + +/** + * Default implementation of {@link EmbeddingOptions.Builder}. + * + * @author Thomas Vitale + */ +public class DefaultEmbeddingOptionsBuilder implements EmbeddingOptions.Builder { + + private final DefaultEmbeddingOptions embeddingOptions = new DefaultEmbeddingOptions(); + + @Override + public EmbeddingOptions.Builder model(String model) { + this.embeddingOptions.setModel(model); + return this; + } + + @Override + public EmbeddingOptions.Builder dimensions(Integer dimensions) { + this.embeddingOptions.setDimensions(dimensions); + return this; + } + + @Override + public EmbeddingOptions build() { + return this.embeddingOptions; + } + +} diff --git a/spring-ai-model/src/main/java/org/springframework/ai/embedding/EmbeddingOptions.java b/spring-ai-model/src/main/java/org/springframework/ai/embedding/EmbeddingOptions.java index 73a9d4d3ade..aa9dbf18903 100644 --- a/spring-ai-model/src/main/java/org/springframework/ai/embedding/EmbeddingOptions.java +++ b/spring-ai-model/src/main/java/org/springframework/ai/embedding/EmbeddingOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,4 +33,18 @@ public interface EmbeddingOptions extends ModelOptions { @Nullable Integer getDimensions(); + static Builder builder() { + return new DefaultEmbeddingOptionsBuilder(); + } + + interface Builder { + + Builder model(String model); + + Builder dimensions(Integer dimensions); + + EmbeddingOptions build(); + + } + } diff --git a/spring-ai-model/src/main/java/org/springframework/ai/embedding/EmbeddingOptionsBuilder.java b/spring-ai-model/src/main/java/org/springframework/ai/embedding/EmbeddingOptionsBuilder.java index 69a5ab5170d..f7b845ff257 100644 --- a/spring-ai-model/src/main/java/org/springframework/ai/embedding/EmbeddingOptionsBuilder.java +++ b/spring-ai-model/src/main/java/org/springframework/ai/embedding/EmbeddingOptionsBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,10 @@ * * @author Thomas Vitale * @since 1.0.0 + * @deprecated in favor of {@link EmbeddingOptions#builder()} */ -public final class EmbeddingOptionsBuilder { +@Deprecated +public final class EmbeddingOptionsBuilder implements EmbeddingOptions.Builder { private final DefaultEmbeddingOptions embeddingOptions = new DefaultEmbeddingOptions(); @@ -57,30 +59,4 @@ public EmbeddingOptions build() { return this.embeddingOptions; } - private static class DefaultEmbeddingOptions implements EmbeddingOptions { - - private String model; - - private Integer dimensions; - - @Override - public String getModel() { - return this.model; - } - - public void setModel(String model) { - this.model = model; - } - - @Override - public Integer getDimensions() { - return this.dimensions; - } - - public void setDimensions(Integer dimensions) { - this.dimensions = dimensions; - } - - } - } diff --git a/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorStore.java b/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorStore.java index 177d14da801..b6d53828bc0 100644 --- a/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorStore.java +++ b/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorStore.java @@ -36,7 +36,7 @@ import org.springframework.ai.document.Document; import org.springframework.ai.document.DocumentMetadata; import org.springframework.ai.embedding.EmbeddingModel; -import org.springframework.ai.embedding.EmbeddingOptionsBuilder; +import org.springframework.ai.embedding.EmbeddingOptions; import org.springframework.ai.observation.conventions.VectorStoreProvider; import org.springframework.ai.observation.conventions.VectorStoreSimilarityMetric; import org.springframework.ai.util.JacksonUtils; @@ -256,7 +256,7 @@ public static PgVectorStoreBuilder builder(JdbcTemplate jdbcTemplate, EmbeddingM @Override public void doAdd(List documents) { - List embeddings = this.embeddingModel.embed(documents, EmbeddingOptionsBuilder.builder().build(), + List embeddings = this.embeddingModel.embed(documents, EmbeddingOptions.builder().build(), this.batchingStrategy); List> batchedDocuments = batchDocuments(documents);