Skip to content

feat(dotAI): Dot AI LangChain4J - Google Vertex#35241

Draft
ihoffmann-dot wants to merge 7 commits intodot-ai-langchain-amazon-bedrockfrom
dot-ai-langchain-google-vertex
Draft

feat(dotAI): Dot AI LangChain4J - Google Vertex#35241
ihoffmann-dot wants to merge 7 commits intodot-ai-langchain-amazon-bedrockfrom
dot-ai-langchain-google-vertex

Conversation

@ihoffmann-dot
Copy link
Copy Markdown
Member

Summary

Adds Google Vertex AI (Gemini) as a supported chat provider.
Auth is handled via Application Default Credentials — no API key required.

  • Add langchain4j-vertex-ai-gemini dependency (with enforcer exclusions)
  • Add vertex_ai case to LangChain4jModelFactory switch
  • Implement buildVertexAiChatModel using VertexAiGeminiChatModel
  • buildVertexAiEmbeddingModel and buildVertexAiImageModel throw UnsupportedOperationException
  • Add 3 unit tests in LangChain4jModelFactoryTest

Configuration

{
  "chat": {
    "provider": "vertex_ai",
    "projectId": "my-gcp-project",
    "location": "us-central1",
    "model": "gemini-1.5-pro",
    "maxTokens": 8192,
    "temperature": 1.0
  }
}

Notes

  • Authentication uses ADC automatically. The host running dotCMS must have a valid GCP identity configured (gcloud auth application-default login or a service account attached to the instance).
  • No API key is needed or accepted for Vertex AI.
  • Embeddings and image generation are not available for this provider via LangChain4J. Both operations throw UnsupportedOperationException.
  • Two transitive dependencies banned by the project Maven enforcer (org.checkerframework:checker-qual, com.google.android:annotations) are explicitly excluded from the langchain4j-vertex-ai-gemini dependency.

Related Issue

This PR fixes #35183
EPIC: dotAI Multi-Provider Support #33970

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

❌ Issue Linking Required

This PR could not be linked to an issue. All PRs must be linked to an issue for tracking purposes.

How to fix this:

Option 1: Add keyword to PR body (Recommended - auto-removes this comment)
Edit this PR description and add one of these lines:

  • This PR fixes #123 or Fixes: #123

  • This PR closes #123 or Closes: #123

  • This PR resolves #123 or Resolves: #123

  • Other supported keywords: fix, fixed, close, closed, resolve, resolved
    Option 2: Link via GitHub UI (Note: won't clear the failed check)

  1. Go to the PR → Development section (right sidebar)

  2. Click "Link issue" and select an existing issue

  3. Push a new commit or re-run the workflow to clear the failed check
    Option 3: Use branch naming
    Create a new branch with one of these patterns:

  • 123-feature-description (number at start)

  • issue-123-feature-description (issue-number at start)

  • feature-issue-123 (issue-number anywhere)

Why is this required?

Issue linking ensures proper tracking, documentation, and helps maintain project history. It connects your code changes to the problem they solve.---

This comment was automatically generated by the issue linking workflow

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 7, 2026

Claude finished @ihoffmann-dot's task in 1m 57s —— View job


PR Review: feat(dotAI): Dot AI LangChain4J - Google Vertex

  • Gather context: read changed files
  • Review dotCMS/pom.xml changes
  • Review LangChain4jModelFactory.java changes
  • Review ProviderConfig.java changes
  • Review LangChain4jModelFactoryTest.java changes
  • Post review findings

Issues

1. Unit test likely fails in CI — ADC initialized at build time

test_buildChatModel_vertexAi_returnsModel calls LangChain4jModelFactory.buildChatModel(vertexAiConfig(...)), which calls VertexAiGeminiChatModel.builder().build(). Unlike OpenAI (lazy), the LangChain4J Vertex AI Gemini implementation wraps the Google Vertex AI SDK, which instantiates a VertexAI object and attempts to load Application Default Credentials at build() time — before any request is made. In a CI environment with no GCP identity, this will throw at build rather than at invocation.

The parallel tests for OpenAI pass fake keys and succeed because OpenAI is lazy. Bedrock passes because BedrockRuntimeClient doesn't call AWS until a request is made. Vertex AI Gemini is different: it calls the gRPC channel initialization during construction.

Fix: Either mock the builder or expect the test to throw an exception related to credential loading rather than asserting assertNotNull. Fix this →


2. maxRetries applied in chat model but not streaming chat model

buildVertexAiChatModel (line 353) applies maxRetries conditionally; buildVertexAiStreamingChatModel (lines 359–367) does not, despite VertexAiGeminiStreamingChatModel.Builder likely supporting it. This is inconsistent with how the Azure and Bedrock streaming builders handle retries. Fix this →


3. Misleading exception for unsupported operations when required fields are absent

When a caller configures vertex_ai as the embeddings provider but omits projectId, they get IllegalArgumentException: providerConfig.embeddings.projectId is required — from validateVertexAi — instead of UnsupportedOperationException: Embeddings are not supported.... The validation runs before the unsupported-operation guard. The useful error is swallowed behind a field-validation error that implies the operation would work if only projectId were provided.

Consider checking for unsupported operations first in buildVertexAiEmbeddingModel/buildVertexAiImageModel by throwing immediately in the build() switch, or by skipping validateVertexAi for model types the provider doesn't support. Fix this →


Minor notes

  • build() method signature grows with each provider (6 positional Function<> args now). This is pre-existing debt, but this PR makes it worse. Consider a Map-based dispatch in a follow-up.
  • No streaming chat model test — happy path coverage stops at non-streaming chat. buildStreamingChatModel with vertex_ai is untested.
  • pom.xml comment placement — the inline comment is inside <dependency> rather than above it like other vendor comments; minor style inconsistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant