Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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();

}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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();

Expand Down Expand Up @@ -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;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -256,7 +256,7 @@ public static PgVectorStoreBuilder builder(JdbcTemplate jdbcTemplate, EmbeddingM

@Override
public void doAdd(List<Document> documents) {
List<float[]> embeddings = this.embeddingModel.embed(documents, EmbeddingOptionsBuilder.builder().build(),
List<float[]> embeddings = this.embeddingModel.embed(documents, EmbeddingOptions.builder().build(),
this.batchingStrategy);

List<List<Document>> batchedDocuments = batchDocuments(documents);
Expand Down