Class VoyageAiEmbeddingModel.Builder
java.lang.Object
dev.langchain4j.model.voyageai.VoyageAiEmbeddingModel.Builder
- Enclosing class:
VoyageAiEmbeddingModel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the Voyage AI API key used to authenticate requests.Sets the base URL of the Voyage AI API.build()customHeaders(Supplier<Map<String, String>> customHeadersSupplier) Sets a supplier for custom HTTP headers.customHeaders(Map<String, String> customHeaders) Sets custom HTTP headers.encodingFormat(String encodingFormat) Format in which the embeddings are encoded.httpClientBuilder(HttpClientBuilder httpClientBuilder) Sets a custom HTTP client builder, allowing fine-grained control over the HTTP client configuration such as timeouts and proxy settings.Type of the input text.logger(org.slf4j.Logger logger) logRequests(Boolean logRequests) Enables debug logging of request bodies sent to the Voyage AI API.logResponses(Boolean logResponses) Enables debug logging of response bodies received from the Voyage AI API.maxRetries(Integer maxRetries) Sets the maximum number of retries on transient errors.maxSegmentsPerBatch(Integer maxSegmentsPerBatch) Sets the maximum number of text segments to include in a single embedding batch request.modelName(VoyageAiEmbeddingModelName modelName) Name of the model.Name of the model.Sets the HTTP request timeout.truncation(Boolean truncation) Whether to truncate the input texts to fit within the context length.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
httpClientBuilder
Sets a custom HTTP client builder, allowing fine-grained control over the HTTP client configuration such as timeouts and proxy settings.- Parameters:
httpClientBuilder- the HTTP client builder- Returns:
this
-
customHeaders
Sets custom HTTP headers. -
customHeaders
public VoyageAiEmbeddingModel.Builder customHeaders(Supplier<Map<String, String>> customHeadersSupplier) Sets a supplier for custom HTTP headers. The supplier is called before each request, allowing dynamic header values. For example, this is useful for OAuth2 tokens that expire and need refreshing. -
baseUrl
Sets the base URL of the Voyage AI API. Defaults to"https://api.voyageai.com/v1/".- Parameters:
baseUrl- the base URL- Returns:
this
-
timeout
Sets the HTTP request timeout. Defaults to 60 seconds.- Parameters:
timeout- the request timeout- Returns:
this
-
maxRetries
Sets the maximum number of retries on transient errors. Defaults to3.- Parameters:
maxRetries- the maximum number of retries- Returns:
this
-
apiKey
Sets the Voyage AI API key used to authenticate requests. See Voyage AI dashboard to obtain a key.- Parameters:
apiKey- the Voyage AI API key- Returns:
this
-
modelName
Name of the model.- Parameters:
modelName- Name of the model.- See Also:
-
modelName
Name of the model.- Parameters:
modelName- Name of the model.- See Also:
-
inputType
Type of the input text. Defaults to null. Other options: query, document.- query: Use this for search or retrieval queries. Voyage AI will prepend a prompt to optimize the embeddings for query use cases.
- document: Use this for documents or content that you want to be retrievable. Voyage AI will prepend a prompt to optimize the embeddings for document use cases.
- null (default): The input text will be directly encoded without any additional prompt.
- Parameters:
inputType- Type of input text
-
truncation
Whether to truncate the input texts to fit within the context length. Defaults to true.- If true, over-length input texts will be truncated to fit within the context length, before vectorized by the embedding model.
- If false, an error will be raised if any given text exceeds the context length.
- Parameters:
truncation- Whether to truncate the input texts.
-
encodingFormat
Format in which the embeddings are encoded. We support two options:- If not specified (defaults to null): the embeddings are represented as lists of floating-point numbers;
- base64: the embeddings are compressed to base64 encodings.
- Parameters:
encodingFormat- Format in which the embeddings are encoded. Support format is "null" and "base64".
-
logRequests
Enables debug logging of request bodies sent to the Voyage AI API.- Parameters:
logRequests-trueto enable request logging- Returns:
this
-
logResponses
Enables debug logging of response bodies received from the Voyage AI API.- Parameters:
logResponses-trueto enable response logging- Returns:
this
-
logger
- Parameters:
logger- an alternateLoggerto be used instead of the default one provided by Langchain4J for logging requests and responses.- Returns:
this.
-
maxSegmentsPerBatch
Sets the maximum number of text segments to include in a single embedding batch request. Defaults to72.- Parameters:
maxSegmentsPerBatch- the maximum number of segments per batch- Returns:
this
-
build
-