Class VertexAiEmbeddingModel
java.lang.Object
dev.langchain4j.model.embedding.DimensionAwareEmbeddingModel
dev.langchain4j.model.vertexai.VertexAiEmbeddingModel
- All Implemented Interfaces:
EmbeddingModel
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
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
2. Authorization
3. Prerequisites
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic enum -
Field Summary
Fields inherited from class DimensionAwareEmbeddingModel
dimension -
Constructor Summary
ConstructorsConstructorDescriptionVertexAiEmbeddingModel(String endpoint, String project, String location, String publisher, String modelName, Integer maxRetries, Integer maxSegmentsPerBatch, Integer maxTokensPerBatch, VertexAiEmbeddingModel.TaskType taskType, String titleMetadataKey, Integer outputDimensionality, Boolean autoTruncate) Deprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()calculateTokensCounts(List<TextSegment> segments) Calculates the number of tokens for each segment in the input list.embedAll(List<TextSegment> segments) Embeds the text content of a list of TextSegments.protected IntegerWhen known (e.g., can be derived from the model name), returns the dimension of theEmbeddingproduced by this embedding model.Methods inherited from class DimensionAwareEmbeddingModel
dimensionMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EmbeddingModel
embed, embed
-
Constructor Details
-
VertexAiEmbeddingModel
-
VertexAiEmbeddingModel
@Deprecated(forRemoval=true, since="1.2.0") public VertexAiEmbeddingModel(String endpoint, String project, String location, String publisher, String modelName, Integer maxRetries, Integer maxSegmentsPerBatch, Integer maxTokensPerBatch, VertexAiEmbeddingModel.TaskType taskType, String titleMetadataKey, Integer outputDimensionality, Boolean autoTruncate) Deprecated, for removal: This API element is subject to removal in a future version.Please useVertexAiEmbeddingModel(Builder)instead
-
-
Method Details
-
embedAll
Description copied from interface:EmbeddingModelEmbeds the text content of a list of TextSegments.- Parameters:
segments- the text segments to embed.- Returns:
- the embeddings.
-
calculateTokensCounts
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
Description copied from class:DimensionAwareEmbeddingModelWhen known (e.g., can be derived from the model name), returns the dimension of theEmbeddingproduced by this embedding model. Otherwise, it returnsnull.- Overrides:
knownDimensionin classDimensionAwareEmbeddingModel- Returns:
- the known dimension of the
Embedding, ornullif unknown.
-
builder
-
VertexAiEmbeddingModel(Builder)instead