Class VoyageAiEmbeddingModel.Builder

java.lang.Object
dev.langchain4j.model.voyageai.VoyageAiEmbeddingModel.Builder
Enclosing class:
VoyageAiEmbeddingModel

public static class VoyageAiEmbeddingModel.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • httpClientBuilder

      public VoyageAiEmbeddingModel.Builder httpClientBuilder(HttpClientBuilder 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

      public VoyageAiEmbeddingModel.Builder customHeaders(Map<String,String> 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

      public VoyageAiEmbeddingModel.Builder baseUrl(String 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

      public VoyageAiEmbeddingModel.Builder timeout(Duration timeout)
      Sets the HTTP request timeout. Defaults to 60 seconds.
      Parameters:
      timeout - the request timeout
      Returns:
      this
    • maxRetries

      public VoyageAiEmbeddingModel.Builder maxRetries(Integer maxRetries)
      Sets the maximum number of retries on transient errors. Defaults to 3.
      Parameters:
      maxRetries - the maximum number of retries
      Returns:
      this
    • apiKey

      public VoyageAiEmbeddingModel.Builder apiKey(String 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

      public VoyageAiEmbeddingModel.Builder modelName(String modelName)
      Name of the model.
      Parameters:
      modelName - Name of the model.
      See Also:
    • inputType

      public VoyageAiEmbeddingModel.Builder inputType(String 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

      public VoyageAiEmbeddingModel.Builder truncation(Boolean 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

      public VoyageAiEmbeddingModel.Builder encodingFormat(String 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

      public VoyageAiEmbeddingModel.Builder logRequests(Boolean logRequests)
      Enables debug logging of request bodies sent to the Voyage AI API.
      Parameters:
      logRequests - true to enable request logging
      Returns:
      this
    • logResponses

      public VoyageAiEmbeddingModel.Builder logResponses(Boolean logResponses)
      Enables debug logging of response bodies received from the Voyage AI API.
      Parameters:
      logResponses - true to enable response logging
      Returns:
      this
    • logger

      public VoyageAiEmbeddingModel.Builder logger(org.slf4j.Logger logger)
      Parameters:
      logger - an alternate Logger to be used instead of the default one provided by Langchain4J for logging requests and responses.
      Returns:
      this.
    • maxSegmentsPerBatch

      public VoyageAiEmbeddingModel.Builder maxSegmentsPerBatch(Integer maxSegmentsPerBatch)
      Sets the maximum number of text segments to include in a single embedding batch request. Defaults to 72.
      Parameters:
      maxSegmentsPerBatch - the maximum number of segments per batch
      Returns:
      this
    • build

      public VoyageAiEmbeddingModel build()