Voyage AI: set default maxSegmentsPerBatch value to 128

This commit is contained in:
LangChain4j 2024-10-06 19:32:07 +02:00
parent 9d42a15ca8
commit 6981d6458e
1 changed files with 3 additions and 10 deletions

View File

@ -15,7 +15,6 @@ import java.util.List;
import static dev.langchain4j.internal.RetryUtils.withRetry; import static dev.langchain4j.internal.RetryUtils.withRetry;
import static dev.langchain4j.internal.Utils.getOrDefault; import static dev.langchain4j.internal.Utils.getOrDefault;
import static dev.langchain4j.internal.ValidationUtils.ensureNotBlank; import static dev.langchain4j.internal.ValidationUtils.ensureNotBlank;
import static dev.langchain4j.internal.ValidationUtils.ensureNotNull;
import static dev.langchain4j.model.voyageai.VoyageAiApi.DEFAULT_BASE_URL; import static dev.langchain4j.model.voyageai.VoyageAiApi.DEFAULT_BASE_URL;
import static java.time.Duration.ofSeconds; import static java.time.Duration.ofSeconds;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
@ -32,7 +31,7 @@ public class VoyageAiEmbeddingModel extends DimensionAwareEmbeddingModel {
private final String inputType; private final String inputType;
private final Boolean truncation; private final Boolean truncation;
private final String encodingFormat; private final String encodingFormat;
private Integer maxSegmentsPerBatch; private final Integer maxSegmentsPerBatch;
public VoyageAiEmbeddingModel( public VoyageAiEmbeddingModel(
String baseUrl, String baseUrl,
@ -47,11 +46,9 @@ public class VoyageAiEmbeddingModel extends DimensionAwareEmbeddingModel {
Boolean logResponses, Boolean logResponses,
Integer maxSegmentsPerBatch Integer maxSegmentsPerBatch
) { ) {
// Below attributes are force to non-null.
this.maxRetries = getOrDefault(maxRetries, 3); this.maxRetries = getOrDefault(maxRetries, 3);
this.modelName = ensureNotBlank(modelName, "modelName"); this.modelName = ensureNotBlank(modelName, "modelName");
this.maxSegmentsPerBatch = getOrDefault(maxSegmentsPerBatch, 1000); this.maxSegmentsPerBatch = getOrDefault(maxSegmentsPerBatch, 128);
// Below attributes can be null.
this.truncation = truncation; this.truncation = truncation;
this.inputType = inputType; this.inputType = inputType;
this.encodingFormat = encodingFormat; this.encodingFormat = encodingFormat;
@ -95,11 +92,7 @@ public class VoyageAiEmbeddingModel extends DimensionAwareEmbeddingModel {
inputTokenCount += getTokenUsage(response); inputTokenCount += getTokenUsage(response);
} }
return Response.from( return Response.from(embeddings, new TokenUsage(inputTokenCount));
embeddings,
new TokenUsage(inputTokenCount)
);
} }
@Override @Override