Class VertexAiEmbeddingModel

java.lang.Object
dev.langchain4j.model.embedding.DimensionAwareEmbeddingModel
dev.langchain4j.model.vertexai.VertexAiEmbeddingModel
All Implemented Interfaces:
dev.langchain4j.model.embedding.EmbeddingModel

public class VertexAiEmbeddingModel extends dev.langchain4j.model.embedding.DimensionAwareEmbeddingModel
Represents a Google Vertex AI embedding model, such as textembedding-gecko. See details here.

This embedding model transparently handles call batching, however the underlying API has imposes a maximum of 250 embeddings per call, with a max of 20,000 tokens per call. You can tweak those two parameters with the maxSegmentsPerBatch() and maxTokensPerBatch() builder methods. For example, if you hit the 20,000 error, set maxTokensPerBatch(18_000).

For authentication and authorization, please follow these steps before using this model:
1. Authentication
When developing locally, you can use one of:
a) Google Cloud SDK
b) Service account When using service account, ensure that GOOGLE_APPLICATION_CREDENTIALS environment variable points to your JSON service account key.
2. Authorization
3. Prerequisites
  • Constructor Details

  • Method Details

    • embedAll

      public dev.langchain4j.model.output.Response<List<dev.langchain4j.data.embedding.Embedding>> embedAll(List<dev.langchain4j.data.segment.TextSegment> segments)
    • calculateTokensCounts

      public List<Integer> calculateTokensCounts(List<dev.langchain4j.data.segment.TextSegment> segments)
      Calculates the number of tokens for each segment in the input list.
      Parameters:
      segments - a list of TextSegments
      Returns:
      a list of tokens counts for each segment
    • knownDimension

      protected Integer knownDimension()
      Overrides:
      knownDimension in class dev.langchain4j.model.embedding.DimensionAwareEmbeddingModel
    • builder

      public static VertexAiEmbeddingModel.Builder builder()