Skip to content

feat(dotAI): Dot AI LangChain4J - Amazon Bedrock#35242

Draft
ihoffmann-dot wants to merge 15 commits intodot-ai-langchain-azure-openaifrom
dot-ai-langchain-amazon-bedrock
Draft

feat(dotAI): Dot AI LangChain4J - Amazon Bedrock#35242
ihoffmann-dot wants to merge 15 commits intodot-ai-langchain-azure-openaifrom
dot-ai-langchain-amazon-bedrock

Conversation

@ihoffmann-dot
Copy link
Copy Markdown
Member

Summary

Adds AWS Bedrock as a supported provider. Bedrock is a managed platform that
proxies multiple model families (Anthropic, Amazon Titan, Cohere, Meta, etc.)
via a unified Converse API — a single integration covers all of them.

  • Add langchain4j-bedrock dependency
  • Add bedrock case to LangChain4jModelFactory switch
  • Implement buildBedrockChatModel using BedrockRuntimeClient with explicit or IAM role credentials
  • Implement buildBedrockEmbeddingModel with automatic Titan/Cohere dispatch by model ID prefix
  • Add embeddingInputType field to ProviderConfig (Cohere-specific; default: search_document)
  • buildBedrockImageModel throws UnsupportedOperationException (no LangChain4J support)
  • Add 4 unit tests in LangChain4jModelFactoryTest

Configuration

{
  "chat": {
    "provider": "bedrock",
    "region": "us-east-1",
    "accessKeyId": "...",
    "secretAccessKey": "...",
    "model": "anthropic.claude-3-5-sonnet-20241022-v2:0",
    "maxTokens": 16384,
    "temperature": 1.0
  },
  "embeddings": {
    "provider": "bedrock",
    "region": "us-east-1",
    "accessKeyId": "...",
    "secretAccessKey": "...",
    "model": "amazon.titan-embed-text-v2:0"
  }
}

Notes

  • If accessKeyId / secretAccessKey are omitted, credentials resolve via DefaultCredentialsProvider (IAM role, environment, ~/.aws/credentials).
  • Embedding dispatch: model IDs starting with cohere. → BedrockCohereEmbeddingModel; all others → BedrockTitanEmbeddingModel.
  • embeddingInputType is Cohere-only. Use search_document when indexing content, search_query when embedding a search query. Titan silently ignores this field.
  • Image generation via Bedrock is not available through LangChain4J. Attempting it throws UnsupportedOperationException.

Related Issue

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

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 7, 2026

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


PR Review: feat(dotAI) - Amazon Bedrock

  • Gather context
  • Read changed files
  • Post review

Several issues worth addressing before merge:

1. Resource leak — AWS SDK clients are never closed

LangChain4jModelFactory.java:282-294

bedrockClient() and bedrockAsyncClient() construct a new BedrockRuntimeClient / BedrockRuntimeAsyncClient on every invocation, each owning an HTTP connection pool. These are injected into the model builders but nothing closes them. If the factory is called repeatedly (e.g., on config refresh, per-request), SDK clients accumulate indefinitely. Both implement Closeable. The model needs to either take ownership and close the client, or the factory needs a lifecycle hook. Fix this →

2. model not validated for Bedrock — silent null reaches AWS

LangChain4jModelFactory.java:141-143 and 297-338

validateBedrock only checks region. For chat/streaming, config.model() is passed directly to .modelId() with no null check — the builder may accept null silently, then fail at invocation with an unhelpful error. For embeddings (buildBedrockEmbeddingModel, line 323-338), model is null-checked for the Cohere prefix but then passed straight to BedrockTitanEmbeddingModel.builder().model(null) if null. Compare with OpenAI which calls requireNonBlank(config.model(), "model", modelType) in validateOpenAi. Fix this →

3. build() signature is growing per-provider — will break at Vertex AI

LangChain4jModelFactory.java:102-106

The build() method now has 5 parameters (config, modelType, openAiFn, azureOpenAiFn, bedrockFn). Adding Vertex AI (listed as planned) adds a 6th. The existing pattern is the debt; this PR deepens it. Consider a Map<String, Function<ProviderConfig, T>> or a ProviderBuilder interface before this gets worse. Not a blocker but worth addressing soon.

4. embeddingInputType is unvalidated

ProviderConfig.java:80-81

The field accepts any string. The Bedrock Cohere API only accepts specific enum values (search_document, search_query, classification, clustering). An invalid value passes through to AWS and fails at call time with an opaque error. Fix this →

5. Missing tests

  • No test for buildStreamingChatModel with Bedrock (the only model type missing Bedrock coverage).
  • No test for partial credentials (one of accessKeyId/secretAccessKey set, other absent) — the bedrockCredentials() code at line 275 handles this case but it's untested. Fix this →

6. dotCMS/pom.xml dependency comment style (minor)

The XML comment is placed inside the <dependency> element, which is unusual and may not render in all tooling. Convention in this file is to place comments before the opening <dependency> tag.


@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 7, 2026

Claude finished @ihoffmann-dot's task in 54s —— View job


I'll analyze this and get back to you.

@dotCMS dotCMS deleted a comment from github-actions Bot Apr 20, 2026
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