Skip to content

Commit

Permalink
Merge pull request #255 from milderhc/dimensions-bug
Browse files Browse the repository at this point in the history
Remove default dimensions for models that don't support it
  • Loading branch information
milderhc authored Oct 28, 2024
2 parents add005d + 7d9e3f1 commit 4bfe3e9
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class OpenAITextEmbeddingGenerationService extends OpenAiService<OpenAIAs

private static final Logger LOGGER = LoggerFactory
.getLogger(OpenAITextEmbeddingGenerationService.class);
private static final int DEFAULT_DIMENSIONS = 1536;
private final int dimensions;

/**
Expand Down Expand Up @@ -100,8 +99,10 @@ public Mono<List<Embedding>> generateEmbeddingsAsync(List<String> data) {
protected Mono<List<Embedding>> internalGenerateTextEmbeddingsAsync(List<String> data) {
EmbeddingsOptions options = new EmbeddingsOptions(data)
.setModel(getModelId())
.setDimensions(dimensions)
.setInputType("string");
if (dimensions > 0) {
options.setDimensions(dimensions);
}

return getClient()
.getEmbeddings(getModelId(), options)
Expand All @@ -118,7 +119,7 @@ protected Mono<List<Embedding>> internalGenerateTextEmbeddingsAsync(List<String>
public static class Builder extends
OpenAiServiceBuilder<OpenAIAsyncClient, OpenAITextEmbeddingGenerationService, OpenAITextEmbeddingGenerationService.Builder> {

private int dimensions = DEFAULT_DIMENSIONS;
private int dimensions = -1;

/**
* Sets the dimensions for the embeddings.
Expand Down

0 comments on commit 4bfe3e9

Please sign in to comment.