CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-dev-langchain4j--langchain4j-vertex-ai

LangChain4j integration for Google Vertex AI models including chat, language, embedding, image, and scoring capabilities

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

overview.mddocs/models/embedding/

Embedding Model Overview

Text embeddings using Google Vertex AI embedding models for semantic search, retrieval, and similarity. Extends LangChain4j DimensionAwareEmbeddingModel.

Class

public class VertexAiEmbeddingModel extends DimensionAwareEmbeddingModel {
    public Response<List<Embedding>> embedAll(List<TextSegment> segments);
    public String modelName();
    public List<Integer> calculateTokensCounts(List<TextSegment> segments);
    public static Builder builder();

    // Public constants
    public static final Integer DEFAULT_MAX_SEGMENTS_PER_BATCH = 250;
    public static final Integer DEFAULT_MAX_TOKENS_PER_BATCH = 20000;
}

Imports

import dev.langchain4j.model.vertexai.VertexAiEmbeddingModel;
import dev.langchain4j.model.vertexai.VertexAiEmbeddingModel.TaskType;
import dev.langchain4j.model.vertexai.VertexAiEmbeddingModelName;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.data.embedding.Embedding;
import dev.langchain4j.model.output.Response;

Minimal Example

VertexAiEmbeddingModel model = VertexAiEmbeddingModel.builder()
    .endpoint("us-central1-aiplatform.googleapis.com:443")
    .project("your-project-id")
    .location("us-central1")
    .publisher("google")
    .modelName("text-embedding-004")
    .build();

List<TextSegment> segments = List.of(
    TextSegment.from("First document"),
    TextSegment.from("Second document")
);

Response<List<Embedding>> response = model.embedAll(segments);
List<Embedding> embeddings = response.content();

Supported Models

  • text-embedding-004 - Latest, 768 dimensions
  • textembedding-gecko@001/002/003 - Gecko models, 768 dimensions
  • text-multilingual-embedding-002 - Multilingual, 768 dimensions
  • multimodalembedding - Multimodal, 1408 dimensions

Configuration Parameters

Required

  • endpoint - API endpoint (different format: {region}-aiplatform.googleapis.com:443)
  • project - Google Cloud Project ID
  • location - GCP region
  • publisher - Model publisher ("google")
  • modelName - Model name/version

Optional

  • maxRetries (Integer) - Retry attempts (default: 2)
  • maxSegmentsPerBatch (Integer) - Max segments per API call (default: 250)
  • maxTokensPerBatch (Integer) - Max tokens per batch (default: 20,000)
  • taskType (TaskType) - Optimization for specific tasks
  • titleMetadataKey (String) - Metadata key for titles (default: "title")
  • autoTruncate (Boolean) - Auto-truncate long texts (default: false)
  • outputDimensionality (Integer) - Custom embedding dimension
  • credentials (GoogleCredentials) - Custom auth

Task Types

public enum TaskType {
    RETRIEVAL_QUERY,        // Query for retrieval
    RETRIEVAL_DOCUMENT,     // Document for retrieval
    SEMANTIC_SIMILARITY,    // Similarity comparison
    CLASSIFICATION,         // Text classification
    CLUSTERING,             // Text clustering
    QUESTION_ANSWERING,     // Question answering
    FACT_VERIFICATION,      // Fact verification
    CODE_RETRIEVAL_QUERY    // Code retrieval
}

Usage: Use RETRIEVAL_DOCUMENT for indexing, RETRIEVAL_QUERY for searching.

Use Cases

  • Semantic search and retrieval
  • Document similarity
  • Recommendation systems
  • Clustering and classification
  • Retrieval Augmented Generation (RAG)

See Also

  • Examples - Detailed usage examples
  • API Reference - Complete API documentation

Install with Tessl CLI

npx tessl i tessl/maven-dev-langchain4j--langchain4j-vertex-ai

docs

index.md

quick-reference.md

tile.json