Commit Graph

207 Commits

Author SHA1 Message Date
Omkar Kathile c27e6e9c2d
Redact sensitive AWS auth headers (Authorization, X-Amz-Security-Toke… (#5799)
## Issue

Closes #5798

## Change

When `logRequests`/`logResponses` are enabled, `AwsLoggingInterceptor`
logs the full HTTP header set. Because `beforeTransmission` runs after
SigV4 signing, this includes the `Authorization` header (access key ID +
signature) and, when temporary/STS credentials are used (assumed roles,
EC2/ECS/EKS instance roles, IAM Identity Center), the
`X-Amz-Security-Token` a live, replayable session token writing
credentials to whatever log sink is configured (CWE-532).

This PR masks the values of these two headers (case-insensitive) with
`[REDACTED]` before logging, via a small package-private `maskHeaders()`
helper. This matches the header redaction already used elsewhere in
langchain4j (core `HttpRequestLogger`, and the cohere/jina/ovh-ai/nomic
request logging interceptors) and the AWS SDK's own wire logging, which
never emits these values.

All other headers, URL, query parameters, and body are logged unchanged.
No public API or request-behavior change only debug log text. Adds
`AwsLoggingInterceptorTest` (7 unit tests covering redaction of both
headers, case variants, non-sensitive header preservation, multi-value
headers, and null/empty maps).

Note: the import re-sort in the diff is mandated by the repo's spotless
config (matches sibling `BedrockCustomHeadersInterceptor`); no other
reformatting was done. `spotless:check` passes.

## General checklist

<!-- Please double-check the following points and mark them like this:
[X] -->

- [X] There are no breaking changes (API, behaviour)
- [X] I have added unit and/or integration tests for my change
- [X] The tests cover both positive and negative cases
- [X] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [ ] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green


## Checklist for adding new maven module

<!-- Please double-check the following points and mark them like this:
[X] -->

- [ ] I have added my new module in the root `pom.xml` and
`langchain4j-bom/pom.xml`

## Checklist for adding new embedding store integration

<!-- Please double-check the following points and mark them like this:
[X] -->

- [ ] I have added a `{NameOfIntegration}EmbeddingStoreIT` that extends
from either `EmbeddingStoreIT` or `EmbeddingStoreWithFilteringIT`
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreRemovalIT` that
extends from `EmbeddingStoreWithRemovalIT`

## Checklist for changing existing embedding store integration

<!-- Please double-check the following points and mark them like this:
[X] -->

- [ ] I have manually verified that the
`{NameOfIntegration}EmbeddingStore` works correctly with the data
persisted using the latest released version of LangChain4j
2026-07-20 09:10:03 +02:00
github-actions[bot] a39f132b91 Update versions to 1.19.0-SNAPSHOT and 1.19.0-beta29-SNAPSHOT 2026-07-17 13:42:56 +00:00
github-actions[bot] 66ad5ee6d5 Release versions 1.18.0 and 1.18.0-beta28 2026-07-17 12:34:45 +00:00
Dmytro Liubarskyi 2101288ad7
EmbeddingModel: request/response API with per-call parameters, multimodal inputs, and observability (#5735)
## Issue
Closes #1153 — distinguish APIs for embedding queries vs. documents/keys
(adds `EmbeddingInputType.QUERY`/`DOCUMENT` as a per-call parameter,
plus opt-in `embeddingInputType(...)` on
  `EmbeddingStoreContentRetriever` / `EmbeddingStoreIngestor`).

Partially addresses #4019 — adds the multimodal image-embedding API at
the core level (`EmbeddingInput` of `Content` parts) and wires Cohere,
Voyage, Jina, Google (Gemini Embedding 2), and Bedrock Titan; does
  not implement it for `OnnxEmbeddingModel`.

Relates to #5142 — provider-specific / per-call parameters for OpenAI
embeddings (`OpenAiEmbeddingRequestParameters`: `user`,
`encodingFormat`, `customParameters`; e.g. NVIDIA NIM `input_type` via
custom
  parameters).

Relates to #4273 — observability for `EmbeddingModel` via listeners
(`EmbeddingModelListener` + request/response/error contexts, wired
across providers).

  ## Change

Introduces an `EmbeddingModel.embed(EmbeddingRequest) →
EmbeddingResponse` API, structured like `ChatModel`'s request/response
API, so embeddings can carry **per-call parameters** and **multimodal
inputs** and
participate in **observability**. Everything is additive and
`@Experimental`; the existing `embed(String)` / `embed(TextSegment)` /
`embedAll(List)` methods keep working unchanged.

  ### Core (`langchain4j-core`)
- New request/response types: `EmbeddingRequest`, `EmbeddingResponse`,
`EmbeddingResponseMetadata`, `EmbeddingRequestParameters` (+
`DefaultEmbeddingRequestParameters` and typed `EmbeddingParameter<T>`
  tokens), `EmbeddingInput`, `EmbeddingInputType`.
- New default methods on `EmbeddingModel`: `embed(EmbeddingRequest)`,
`doEmbed(...)`, `defaultRequestParameters()`, `supportedParameters()`,
`supportedContentTypes()`, `provider()`, `listeners()`.
- **Strict opt-in / fail-fast:** per-call parameters and content types
are token/type-checked; a request that uses something the model doesn't
declare is rejected with `UnsupportedFeatureException` instead of
being silently ignored. `overrideWith` preserves the provider-specific
parameters subtype (as on the chat side).
- **Multimodal:** an `EmbeddingInput` is an ordered list of `Content`
parts (text/image); models fuse them into one embedding (or
one-per-item, per provider). Modality is auto-detected — no manual flag.
- **Observability:** `EmbeddingModelListener` + request/response/error
contexts (same shape as `ChatModelListener`), fired inline from
`embed(EmbeddingRequest)`. `addListener(...)` still works.
- **RAG opt-in:** `EmbeddingStoreContentRetriever` and
`EmbeddingStoreIngestor` gain an optional `embeddingInputType(...)`
(QUERY / DOCUMENT). Default behavior is unchanged (no input type sent).
- `ModelProvider`: added `COHERE`, `VOYAGE_AI`, `JINA`, with matching
OpenTelemetry `gen_ai.provider.name` mappings (`cohere` is a well-known
OTel value; `voyage_ai` / `jina` are custom, as permitted by the
  spec).

### Providers
- **OpenAI** (dimensions, `user`/`encodingFormat`/custom params),
**Cohere** (Embed v4 multimodal + input types), **Voyage** (multimodal +
input types), **Jina** (CLIP multimodal), **Google AI Gemini** (input
types; **Gemini Embedding 2** multimodal), **Amazon Bedrock Titan**
(multimodal).
- **Google Gen AI** (`langchain4j-google-genai`): input type → SDK
`task_type`, per-call dimensions → `outputDimensionality`, `provider()`,
listeners.
- **Ollama**: text-only — `provider()` + listeners (per-call params
correctly fail fast).
- **In-process models** (ONNX / `AbstractInProcessEmbeddingModel`):
already work via the default `doEmbed→embedAll` bridge (text-only,
image/param requests fail fast); observability via `addListener(...)`.
No
code change (no builders to wire listeners into, no dedicated
`ModelProvider`).
- **Gemini Embedding 2** dropped the `task_type` parameter, so input
types are applied as prompt instructions (`task: search result | query:
…` / `title: none | text: …`) automatically; `gemini-embedding-001`
  still uses `task_type`.
- `modelName` in the response metadata reflects the API-reported model
where the provider returns one (OpenAI/Voyage/Jina), falling back to the
configured name.

  ### Tests
- `AbstractEmbeddingModelIT` — a shared IT base (like
`AbstractChatModelIT`) covering the new API, convenience methods,
listeners, and fail-fast; each provider adds a small
`common/…EmbeddingModelIT` that
parameterizes it and declares its capabilities via `supports*()`
overrides.
- Mock-based unit tests per provider for wire format / routing /
fail-fast (run in CI without keys), plus core value-type and listener
tests.

### Docs
- Embedding-model section in the RAG tutorial (request/response,
multimodal, query-vs-document opt-in), the EmbeddingModel listener
section in the Observability tutorial, the embedding contribution
guidance in
  `CONTRIBUTING.md`, and the six provider integration pages.

  ### Notes
- `EmbeddingResponseMetadata` intentionally has no `finishReason`
(embeddings have no finish reason). No real provider is affected: the
only provider that emits `STOP` (Cloudflare WorkersAI) overrides the
convenience methods directly, and every other provider always returned
`null` here.
- `revapi.json` suppressions were added where the new (non-breaking)
types are exposed in provider APIs.

  ## General checklist
  - [x] There are no breaking changes (API, behaviour)
  - [x] I have added unit and/or integration tests for my change
  - [x] The tests cover both positive and negative cases
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
  - [x] I have added/updated the documentation
- [ ] I have manually run all the unit and integration tests in the core
and main modules, and they are all green
- [ ] I have added an example in the examples repo (only for "big"
features)
  - [ ] I have added/updated Spring Boot starter(s) (if applicable)

---------

Co-authored-by: agent <agent@langchain4j.dev>
2026-07-09 22:09:34 +02:00
github-actions[bot] 7d7c3349d7 Update versions to 1.18.0-SNAPSHOT and 1.18.0-beta28-SNAPSHOT 2026-06-26 14:49:40 +00:00
github-actions[bot] 207407aec9 Release versions 1.17.0 and 1.17.0-beta27 2026-06-26 13:13:06 +00:00
Dmytro Liubarskyi 05d06fe104 Expose unmapped raw streaming events (#5589) 2026-06-25 22:09:50 +02:00
Dmytro Liubarskyi 194b864211
Expose unmapped raw streaming events (#5589)
## Issue

  Closes #5116

  ## Change

Adds a new **`onUnmappedRawEvent`** streaming callback that gives
advanced users access to provider streaming events that LangChain4j does
**not** map to one of its typed callbacks — e.g. OpenAI server-tool
lifecycle events (`response.web_search_call.in_progress` / `searching` /
`completed`). This is an escape hatch so power users don't have to fall
back to a provider's native SDK for events we don't model yet.

**API** (both `@Experimental`, `@since 1.17.0`, `default` so nothing
breaks):

- `StreamingChatResponseHandler.onUnmappedRawEvent(Object rawEvent)` —
low-level API
- `TokenStream.onUnmappedRawEvent(Consumer<Object> rawEventHandler)` —
AI Services API

**Semantics — no duplication.** The callback fires **only** for events
that were *not* already delivered via a typed callback
(`onPartialResponse`, `onPartialThinking`, `onPartialToolCall`,
`onCompleteToolCall`, `onCompleteResponse`). So you can consume the
typed callbacks and the raw stream together without seeing the same
event twice. This is enforced by a small internal
`MappingTrackingStreamingChatResponseHandler` that records whether an
event was mapped to a typed callback (`wasMapped()`), and providers emit
the raw event only when it wasn't.

> Naming note: it's called `onUnmappedRawEvent` (not `onRawEvent`) to
leave room for a planned follow-up that also exposes the raw event
behind *mapped* callbacks (e.g. `PartialToolCall.rawEvent()`), giving a
  clean mapped/unmapped split.

  **The concrete `rawEvent` type is provider-specific:**

  | Provider | Raw event type |
  |---|---|
| OpenAI, Anthropic, Google AI Gemini, Mistral, Ollama |
`dev.langchain4j.http.client.sse.ServerSentEvent` |
| OpenAI (official) – Responses API |
`com.openai.models.responses.ResponseStreamEvent` |
| OpenAI (official) – Chat Completions API |
`com.openai.models.chat.completions.ChatCompletionChunk` |
| Amazon Bedrock |
`software.amazon.awssdk.services.bedrockruntime.model.ConverseStreamOutput`
|
  | Google GenAI | `com.google.genai.types.GenerateContentResponse` |

**Providers wired:** OpenAI (Chat Completions + Responses),
OpenAI-official (Chat Completions + Responses), Anthropic, Google AI
Gemini, Google GenAI, Amazon Bedrock, Mistral, Ollama.

**Docs:** added a "Unmapped Raw Events" section to
`response-streaming.md` and the callback to the `TokenStream` example in
`ai-services.md`.

  ## General checklist
- [x] There are no breaking changes (API, behaviour) — all additions are
`default` and `@Experimental`
  - [x] I have added unit and/or integration tests for my change
- [x] The tests cover both positive and negative cases — i.e. unmapped
events are forwarded *and* typed (text/tool) events are **not** repeated
as raw events
- [x] I have manually run all the unit and integration tests in the
module(s) I have added/changed, and they are all green
- [x] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and

[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
- [x] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
2026-06-25 21:14:30 +02:00
Aditya Pimpalkar beda3d68a6
feat(bedrock): add enableAdaptiveReasoning for Claude Opus 4.7+ (#5358)
## Issue
Closes #5138

## Change
Adds
`BedrockChatRequestParameters.Builder.enableAdaptiveReasoning(String
effort)`,
which serializes to `reasoning_config: {type: "adaptive"}` and, when
effort is
non-null, `output_config: {effort: "..."}`. This is the payload
@jfigueiras-denodo
confirmed working against Claude Opus 4.7 in #5138, where the legacy
`budget_tokens`
reasoning config now returns a 400.

The existing `enableReasoning(Integer budgetTokens)` is left unchanged,
so
Opus 4.6 / Sonnet 4.6 users keep working — matching the
deprecation/migration path
described in the issue. Added two unit tests covering
adaptive-with-effort and
adaptive-without-effort (null) serialization.

## General checklist
- [x] There are no breaking changes (API, behaviour)
- [x] I have added unit and/or integration tests for my change
- [x] The tests cover both positive and negative cases
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [x] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)
2026-06-25 13:47:24 +02:00
Eunbin Son 675731c906
fix: prevent integer overflow in AwsDocumentConverter for long and BigInteger tool arguments (#5503)
## Issue
<!-- Update with the real issue number once the issue is filed -->
Closes #5502

## Change

`AwsDocumentConverter.getDocument(JsonNode)` matched the integer branch
on `isInt() || isLong() || isShort() || isBigInteger()` but converted
with `Document.fromNumber(value.asInt())`. Jackson `asInt()` narrows
`long`/`BigInteger` to `(int)`, silently corrupting values outside the
int range (`9223372036854775807` becomes `-1`).

This is reached on a normal path:
`AbstractBedrockChatModel.convertToolRequests()` converts LLM tool-call
argument JSON to a `Document` via `documentFromJson(...)`, so large
integer tool arguments were mangled before being sent to Bedrock.

Fix: convert with `value.bigIntegerValue()`. A
`Document.fromNumber(BigInteger)` overload exists in sdk-core, so no new
import or dependency is needed. This is width-preserving and symmetric
with the reverse `documentToObject()` (`asNumber()`) and the `double`
branch (`asDouble()`). In-range `int` values are unchanged (backward
compatible).

Tests: added `documentFromJson` round-trip tests for `Long.MAX_VALUE`, a
value above `Long.MAX_VALUE`, and an in-range int regression. The first
two fail on the old code and pass after the fix.

Note: spotless ratchet reformatted three pre-existing text blocks in the
touched test file (required to pass CI `spotless:check`).

## General checklist
- [X] There are no breaking changes (API, behaviour)
- [X] I have added unit and/or integration tests for my change
- [X] The tests cover both positive and negative cases
- [X] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [ ] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)

<!-- "new maven module" and "embedding store" checklists omitted: not
applicable to this bug fix. -->

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 11:59:20 +02:00
github-actions[bot] 01de41d641 Update versions to 1.17.0-SNAPSHOT and 1.17.0-beta27-SNAPSHOT 2026-06-06 06:46:38 +00:00
github-actions[bot] cd836845dd Release versions 1.16.0 and 1.16.0-beta26 2026-06-05 15:46:56 +00:00
github-actions[bot] 6185599e37 Update versions to 1.16.0-SNAPSHOT and 1.16.0-beta26-SNAPSHOT 2026-05-15 16:21:14 +00:00
github-actions[bot] d0e54aa006 Release versions 1.15.0 and 1.15.0-beta25 2026-05-15 15:55:12 +00:00
renovate[bot] 6903660a8a
fix(deps): update dependency commons-codec:commons-codec to v1.22.0 (#5187)
This PR contains the following updates:

| Package | Change |
[Age](https://docs.renovatebot.com/merge-confidence/) |
[Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
|
[commons-codec:commons-codec](https://commons.apache.org/proper/commons-codec/)
([source](https://redirect.github.com/apache/commons-codec)) | `1.20.0`
→ `1.22.0` |
![age](https://developer.mend.io/api/mc/badges/age/maven/commons-codec:commons-codec/1.22.0?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/commons-codec:commons-codec/1.20.0/1.22.0?slim=true)
|
|
[commons-codec:commons-codec](https://commons.apache.org/proper/commons-codec/)
([source](https://redirect.github.com/apache/commons-codec)) | `1.17.1`
→ `1.22.0` |
![age](https://developer.mend.io/api/mc/badges/age/maven/commons-codec:commons-codec/1.22.0?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/commons-codec:commons-codec/1.17.1/1.22.0?slim=true)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the [Dependency
Dashboard](../issues/2069) for more information.

---

### Release Notes

<details>
<summary>apache/commons-codec (commons-codec:commons-codec)</summary>

###
[`v1.22.0`](https://redirect.github.com/apache/commons-codec/blob/HEAD/RELEASE-NOTES.txt#Apache-Commons-Codec-1220-Release-Notes)

The Apache Commons Codec team is pleased to announce the release of
Apache Commons Codec 1.22.0.

The Apache Commons Codec component contains encoders and decoders for
formats such as Base16, Base32, Base64, digest, and Hexadecimal. In
addition to these
widely used encoders and decoders, the codec package also maintains a
collection of phonetic encoding utilities.

This is a feature and maintenance release. Java 8 or later is required.

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/langchain4j/langchain4j).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNzMuNiIsInVwZGF0ZWRJblZlciI6IjQzLjE3My42IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-05-13 11:19:16 +02:00
C M Abdullah Khan 9b87248e3d
fix: correct spelling of 'outputAssessments' in GuardrailAssessmentSummary (#5059)
<!--
Thank you so much for your contribution!

Please fill in all the sections below.
Please open the PR as a draft initially. Once it is reviewed and
approved, we will ask you to add documentation and examples.
Please note that PRs with breaking changes or without tests will be
rejected.

Please note that PRs will be reviewed based on the priority of the
issues they address.
We ask for your patience. We are doing our best to review your PR as
quickly as possible.
Please refrain from pinging and asking when it will be reviewed. Thank
you for understanding!
-->

## Issue
<!-- Please specify the ID of the issue this PR is addressing. For
example: "Closes #1234" or "Fixes #1234" -->
Closes #

## Change
<!-- Please describe the changes you made. -->
This PR corrects the misspelled `ouputAssessments` name in the Bedrock
guardrail assessment summary API by renaming it to `outputAssessments`.

The change updates:
- `GuardrailAssessmentSummary` field, getter, builder setter, and
related `equals`, `hashCode`, and `toString` methods
- `AbstractBedrockChatModel` so the mapped metadata uses the corrected
builder method
- `BedrockGuardrailIT` and `BedrockStreamingGuardrailIT` to assert
against the corrected accessor

## General checklist
<!-- Please double-check the following points and mark them like this:
[X] -->
- [x] There are no breaking changes (API, behaviour)
- [x] I have added unit and/or integration tests for my change
- [x] The tests cover both positive and negative cases
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [ ] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)
2026-05-12 16:25:41 +02:00
brian-mulier-p 250c9af844
feat: add customHeaders support to BedrockChatModel and BedrockStreamingChatModel (#5112)
## Issue
Closes #5108

## Change
Added `customHeaders(Map<String, String>)` and
`customHeaders(Supplier<Map<String, String>>)` builder methods to
`BedrockChatModel` and `BedrockStreamingChatModel`.

Since Bedrock uses the AWS SDK rather than langchain4j's HTTP client
abstraction, header injection goes through a new
`BedrockCustomHeadersInterceptor` — an `ExecutionInterceptor` that calls
`modifyHttpRequest()` before each HTTP request, following the same
pattern as the existing `AwsLoggingInterceptor`.

The `Supplier` overload allows dynamic headers per request (e.g.
rotating tokens).

## General checklist
- [x] There are no breaking changes (API, behaviour)
- [x] I have added unit and/or integration tests for my change
- [x] The tests cover both positive and negative cases
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [x] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
2026-05-07 10:29:52 +02:00
github-actions[bot] 628ac34c01 Update versions to 1.15.0-SNAPSHOT and 1.15.0-beta25-SNAPSHOT 2026-04-30 18:43:12 +00:00
github-actions[bot] 4917afa297 Release versions 1.14.0 and 1.14.0-beta24 2026-04-30 18:10:30 +00:00
DragonFSKY eca856a734
fix: expose Bedrock Cohere embedding token usage (#5064)
Fixes #5057

## Summary
- Read Bedrock Cohere input token counts from
`x-amzn-bedrock-input-token-count`
- Fall back to the response body token count when the header is not
present
- Sum token usage across batched embedding requests and keep
`tokenUsage()` null when no count is provided

## Testing
- `mvn -pl langchain4j-bedrock spotless:check`
- `mvn -pl langchain4j-bedrock -am
-Dtest=BedrockCohereEmbeddingModelTest,BedrockCohereEmbeddingModelIT
-Dsurefire.failIfNoSpecifiedTests=false test`
2026-04-30 10:45:19 +02:00
Dmytro Liubarskyi 5eb889ad4a fixing tests 2026-04-29 13:32:30 +02:00
정다해(Dahae Jung) 5a0a327c20
feat(bedrock): add CacheTTL support for prompt caching (#4920)
## Summary

Add configurable cache TTL support for Bedrock prompt caching.
Currently, all cache points use the default 5-minute TTL because
`CachePointBlock` is created without a TTL parameter. The AWS Bedrock
SDK (`bedrockruntime` 2.41+) supports `CacheTTL` with `VALUE_5_M` (5
minutes) and `VALUE_1_H` (1 hour), but there is no way to configure it
through LangChain4j.

## Problem

The `CACHE_POINT_BLOCK` in `AbstractBedrockChatModel` is hardcoded as a
static final field without TTL:

```java
private static final SystemContentBlock CACHE_POINT_BLOCK = SystemContentBlock.builder()
        .cachePoint(CachePointBlock.builder()
                .type(CachePointType.DEFAULT)
                // no TTL set → defaults to 5 minutes
                .build())
        .build();
```

Users who need 1-hour TTL (e.g., for APIs called less frequently than
every 5 minutes) must bypass LangChain4j and call the Bedrock SDK
directly, losing access to LangChain4j's listener-based metrics, message
conversion, and other features.

## Solution

- **`BedrockChatRequestParameters`** — Added `cacheTtl` field and
`promptCaching(placement, ttl)` overload:
  ```java
  BedrockChatRequestParameters.builder()
.promptCaching(BedrockCachePointPlacement.AFTER_SYSTEM,
CacheTTL.VALUE_1_H)
      .build()
  ```

- **`AbstractBedrockChatModel`** — Replaced static `CACHE_POINT_BLOCK`
with dynamic `buildCachePoint(cacheTtl)` method that creates
`CachePointBlock` with the specified TTL. Applied to all 4 cache point
creation sites (system messages, user messages, tool configurations).

- **`BedrockChatModel` + `BedrockStreamingChatModel`** — Pass `cacheTtl`
through to all `extract*` methods.

## Backward Compatibility

**Fully backward-compatible.** When `cacheTtl` is `null` (default), the
behavior is identical to the existing implementation:
- The existing `promptCaching(placement)` method continues to work
unchanged
- `buildCachePoint(null)` returns a `CachePointBlock` without TTL (same
as before)
- No changes required in existing user code

## Usage

```java
// Existing code — unchanged, still works (5-minute default)
BedrockChatRequestParameters.builder()
    .promptCaching(BedrockCachePointPlacement.AFTER_SYSTEM)
    .build()

// New — 1-hour TTL
BedrockChatRequestParameters.builder()
    .promptCaching(BedrockCachePointPlacement.AFTER_SYSTEM, CacheTTL.VALUE_5_M)
    .build()
```

## Changed Files

| File | Change |
|------|--------|
| `BedrockChatRequestParameters.java` | Added `cacheTtl` field +
`promptCaching(placement, ttl)` overload |
| `AbstractBedrockChatModel.java` | Replaced static cache point with
dynamic `buildCachePoint(cacheTtl)` |
| `BedrockChatModel.java` | Pass `cacheTtl` to extract methods |
| `BedrockStreamingChatModel.java` | Pass `cacheTtl` to extract methods
|

## References

- [AWS Bedrock Prompt Caching
docs](https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html)
- AWS SDK `CacheTTL` enum: `VALUE_5_M`, `VALUE_1_H`
- 1-hour TTL supported models: Claude Sonnet 4.5, Claude Opus 4.5,
Claude Haiku 4.5

---------

Co-authored-by: Dmytro Liubarskyi <ljubarskij@gmail.com>
2026-04-20 18:01:03 +02:00
Dmytro Liubarskyi f184ef8de2
Add automated API backward compatibility checks with Revapi (#4908)
## Issue
Closes https://github.com/langchain4j/langchain4j/issues/3804
Closes https://github.com/langchain4j/langchain4j/issues/3320

## Change
- Integrate https://revapi.org/ (`revapi-maven-plugin`) into the build
to automatically detect breaking API changes
- Revapi runs during the `verify` phase on every build, comparing the
current code against the latest released version on Maven Central
(`RELEASE`)
- Suppress `java.method.varargOverloadsOnlyDifferInVarargParameter`
globally — this is a design warning about varargs overloads, not an
actual breaking change
- Add per-module `revapi.json` justifications for pre-existing
`java.class.nonPublicPartOfAPI` warnings in `langchain4j-ollama`,
`langchain4j-bedrock`, `langchain4j-onnx-scoring`, and
`langchain4j-google-ai-gemini` — these are package-private classes
exposed through protected members on package-private base classes, so
they cannot actually leak to external
  users
- Do not check depndencies - we do not expose them explicitly and are
not responsible for any changes there
- skip `integration-tests` modules - we do not release them

### How it works
- Revapi downloads the latest released JAR from Maven Central and
compares it against the locally built JAR at the bytecode level
- Any removal, signature change, or visibility reduction of public API
elements will fail the build
- Adding new public API is always fine
- To justify an intentional breaking change, add a `revapi.json` in the
module root — justifications auto-expire on the next release since the
baseline moves forward

## General checklist
- [X] There are no breaking changes (API, behaviour)
- [X] I have added unit and/or integration tests for my change
- [X] The tests cover both positive and negative cases
- [X] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [X] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)
2026-04-13 18:44:05 +02:00
github-actions[bot] 4798a89d66 Update versions to 1.14.0-SNAPSHOT and 1.14.0-beta24-SNAPSHOT 2026-04-09 14:41:27 +00:00
github-actions[bot] 759cd9a236 Release versions 1.13.0 and 1.13.0-beta23 2026-04-09 13:07:30 +00:00
Dmytro Liubarskyi 8ff282f12c
Support Tools Returning Images (#4851)
## Issue
Closes https://github.com/langchain4j/langchain4j/issues/4652

## Change
- Add support for `@Tool`-annotated methods to return multimodal content
(images) to the LLM, not just text. Tools can now return `Image`,
`ImageContent`, `Content`, `List<Content>`, `Content[]`, etc.
- Refactor `ToolExecutionResultMessage` to store `List<Content>`
internally instead of a plain `String`, with backward-compatible
`text()` accessor and new `contents()` / `hasSingleText()`
  methods.
- Refactor `ToolExecutionResult` to support
`resultContents(List<Content>)` as an alternative to
`resultText(String)` and `resultTextSupplier(Supplier)`.
- Implement multimodal tool result mapping for providers that support
it: Anthropic, Amazon Bedrock, and Google AI Gemini.
- Add `UnsupportedFeatureException` guards in providers that do not
support non-text tool results: Azure OpenAI, GitHub Models, Jlama,
Mistral AI, Ollama, OpenAI (Chat Completions
& Responses), Vertex AI (Anthropic & Gemini), Watsonx, and Workers AI.
- Update `ToolExecutedEvent` / `DefaultToolExecutedEvent` to carry
`resultContents` alongside the existing `resultText` accessor.
- Add comprehensive unit and integration tests
(`should_execute_tool_returning_Image`,
`should_execute_tool_returning_ImageContent`,
`should_execute_tool_returning_ContentList`,

`should_fail_when_tool_returns_image_and_provider_does_not_support_it`).
- Update tools documentation with new "Returning Images and Multimodal
Content" and "Multimodal Tool Results" sections.

## General checklist
- [X] There are no breaking changes (API, behaviour)
- [X] I have added unit and/or integration tests for my change
- [X] The tests cover both positive and negative cases
- [X] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [X] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
- [X] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)
2026-04-07 13:54:34 +02:00
Dmytro Liubarskyi e10abf04d0
Update versions to 1.13.0-SNAPSHOT and 1.13.0-beta23-SNAPSHOT (#4710)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-13 11:39:50 +01:00
Dmytro Liubarskyi c92ea033e4
Update versions to 1.13.0-SNAPSHOT and 1.13.0-beta22-SNAPSHOT (#4666)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-05 17:18:22 +01:00
Jonathan Nuñez fab6ed380f
Bedrock: Adding service tiers. Adding another strategy for caching points, aft… (#4563)
…er the last user message.


## Issue
Closes #4562

## Change
Add support for Service Tiers in Bedrock.
New cache point for after last user message in Bedrock.
Allowing the user to configure the guardrail processing mode (sync and
asynchronous).


## General checklist
- [x] There are no breaking changes (API, behaviour)
- [x] I have added unit and/or integration tests for my change
- [x] The tests cover both positive and negative cases
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [x] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)


## Checklist for adding new maven module
- [ ] I have added my new module in the root `pom.xml` and
`langchain4j-bom/pom.xml`


## Checklist for adding new embedding store integration
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreIT` that extends
from either `EmbeddingStoreIT` or `EmbeddingStoreWithFilteringIT`
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreRemovalIT` that
extends from `EmbeddingStoreWithRemovalIT`

## Checklist for changing existing embedding store integration
- [x] I have manually verified that the
`{NameOfIntegration}EmbeddingStore` works correctly with the data
persisted using the latest released version of LangChain4j

---------

Co-authored-by: Jonathan Nunez Aguin <jonathannunezaguin@fico.com>
Co-authored-by: Dmytro Liubarskyi <ljubarskij@gmail.com>
2026-03-05 11:26:02 +01:00
Dmytro Liubarskyi 57c78808fa feat(bedrock): add structured output support (issue #4543) (#4552) 2026-03-04 18:15:08 +01:00
Mohan Kumar S 5caccf9cb3
feat(bedrock): add structured output support (issue #4543) (#4552)
## Issue
Closes #4543

## Change
Implemented support for **Structured Output** in AWS Bedrock, allowing
models to generate responses adhering to a specific JSON schema.

**Key changes:**
- **SDK Upgrade**: Upgraded `aws-java-sdk-bedrockruntime` from `2.33.5`
to `2.41.22` to access `OutputConfig` and `JsonSchemaDefinition` APIs.
- **New Feature**: Added `outputConfig` support to `ConverseRequest` in
`BedrockChatModel` and `BedrockStreamingChatModel`.
- **Schema Mapping**: Created `BedrockSchemaMapper` to convert
LangChain4j `JsonSchema` objects into AWS SDK `Document` format.
- **Validation**: Removed the `UnsupportedFeatureException` that was
previously thrown when `ResponseFormat.JSON` was requested.

## General checklist
- [x] There are no breaking changes (API, behaviour)
- [x] I have added unit and/or integration tests for my change
- [x] The tests cover both positive and negative cases
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [ ] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)

## Checklist for adding new maven module
- [ ] I have added my new module in the root
[pom.xml](cci:7://file:///Users/mohankumarsagadevan/Documents/projects/github/langchain4j/langchain4j-parent/pom.xml:0:0-0:0)
and
[langchain4j-bom/pom.xml](cci:7://file:///Users/mohankumarsagadevan/Documents/projects/github/langchain4j/langchain4j-bom/pom.xml:0:0-0:0)

## Checklist for adding new embedding store integration
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreIT` that extends
from either `EmbeddingStoreIT` or `EmbeddingStoreWithFilteringIT`
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreRemovalIT` that
extends from `EmbeddingStoreWithRemovalIT`

## Checklist for changing existing embedding store integration
- [ ] I have manually verified that the
`{NameOfIntegration}EmbeddingStore` works correctly with the data
persisted using the latest released version of LangChain4j

---------

Co-authored-by: Mohan Kumar Sagadevan <mohankumarsagadevan@Mohans-MacBook-Air.local>
Co-authored-by: Dmytro Liubarskyi <ljubarskij@gmail.com>
2026-03-04 18:14:16 +01:00
Dmytro Liubarskyi 9836ca38bd disabling flaky tests 2026-03-03 09:54:18 +01:00
Dmytro Liubarskyi 2747fc82a8 disabling flaky tests 2026-03-02 09:17:23 +01:00
Dmytro Liubarskyi 68178d398a
Tool Search (#4570)
## Change
Implements Tool Search Tool feature initially introduced by
[Anthropic](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-search-tool).

### Tool Search

When working with a large number of tools,
sending all tools on every request can significantly increase token
usage and reduce model performance.
To address this, LangChain4j provides a tool search mechanism
that allows tools to be discovered dynamically by the LLM itself,
instead of being exposed upfront.

The core idea is simple:
- Initially, the LLM is exposed to one or more special tool-search tools
- The LLM can call these tools to search for relevant tools
- Once relevant tools are found, they are included in subsequent
requests to the LLM

This enables scalable, token-efficient, and model-driven tool discovery.

#### How Tool Search Works

A tool search flow typically looks like this:
1. Initial request:
   - The LLM sees only tool-search tools (not the full tool set)
2. Tool search
- The LLM calls a tool-search tool, describing what kind of tool it
needs
- The tool-search strategy matches the request against available tools
4. Tool exposure
   - Matching tools are added to the next request to the LLM
5. Tool execution
   - The LLM can now call the found tools normally

Previously found tools are accumulated across multiple tool-search
calls.
Each time the LLM invokes the tool-search tool,
the newly matched tools are added to the existing set of tools visible
to the LLM (they are merged, not replaced).
This means the list of tools visible to the LLM can grow over time.
Found tools remain visible to the LLM until their corresponding
`ToolExecutionResultMessage`
is evicted from the `ChatMemory`, and at least until the end of the AI
Service invocation.

If `ChatMemory` is not configured, the found tools remain visible to the
LLM
only until the end of the AI service invocation.

#### ToolSearchStrategy

Tool search is implemented via the `ToolSearchStrategy` interface:

```java
@Experimental
public interface ToolSearchStrategy {

    List<ToolSpecification> getToolSearchTools(InvocationContext invocationContext);

    ToolSearchResult search(ToolSearchRequest toolSearchRequest);
}
```

A `ToolSearchStrategy` is responsible for:
- Exposing tool-search tools to the LLM
- Executing tool search requests generated by the LLM
- Returning matching tool names, which will then be resolved and exposed

LangChain4j currently provides 2 out-of-the-box implementations:
- `SimpleToolSearchStrategy` – keyword-based matching
- `VectorToolSearchStrategy` – semantic search using embeddings

See Javadoc of these classes for more details.

You can also implement custom strategies.

#### Configuring Tool Search in AI Services

Tool search is configured at the AI Service level:

```java
Assistant assistant = AiServices.builder(Assistant.class)
    .chatModel(chatModel)
    .chatMemory(chatMemory)
    .tools(tools) // tool search works for static tools
    .toolProvider(mcpToolProvider) // tool search works for tools provided dynamically (e.g., MCP)
    .toolSearchStrategy(new SimpleToolSearchStrategy())
    .build();
```

Once configured:
- The LLM no longer sees all tools upfront
- Tool discovery becomes an explicit, model-driven step
- Token usage is reduced, especially with large tool sets

#### When to Use Tool Search

Tool search is especially useful when:
- You have many tools (dozens or hundreds)
- Tools are domain-specific or rarely used
- Tool availability depends on context, user, or permissions
- You want the LLM to reason about which tools it needs, instead of
guessing from a long list

If you have only a small number of tools, or all tools are always
relevant,
using regular approach may be simpler.

#### Always Visible Tools

When tool search is enabled, tools are normally hidden from the LLM
until they are discovered via a tool-search call.
However, in some cases you may want certain tools to always be visible
to the LLM.

Typical use cases:
- Core tools that should always be accessible
- Frequently used tools where search overhead is unnecessary
- Utility tools

LangChain4j supports this via the `ALWAYS_VISIBLE` tool search behavior.

##### How It Works

When a tool is marked as `ALWAYS_VISIBLE`:
- It is exposed to the LLM in the very first request
- It does not require discovery via tool search
- It remains visible throughout the AI Service invocation
- It is not included in searchable tool candidates

All other tools continue to follow the normal tool-search flow.

##### Using `@Tool` Annotation

You can mark a tool as always visible via the @Tool annotation:
```java
@Tool(searchBehavior = ALWAYS_VISIBLE)
String getWeather(String city) {
    return weatherService.getWeather(city);
}
```

##### Using `McpToolProvider`

When using MCP tools (via `McpToolProvider`), always-visible tools can
be configured via `alwaysVisibleToolNames`:

```java
McpToolProvider.builder()
    .mcpClients(mcpClient)
    .alwaysVisibleToolNames("getWeather")
    .build();
```

##### Using `ToolSpecification`

If you configure tools programmatically, you can mark them as always
visible using `metadata`:
```java
ToolSpecification toolSpecification = ToolSpecification.builder()
    .name("getWeather")
    .parameters(JsonObjectSchema.builder()
        .addStringProperty("city")
        .required("city")
        .build())
    .metadata(Map.of(ToolSpecification.METADATA_SEARCH_BEHAVIOR, SearchBehavior.ALWAYS_VISIBLE))
    .build();
```

#### Notes and Limitations

NOTE: Tool search relies on the LLM’s ability to understand when and how
to search for tools.
The effectiveness of this feature depends heavily on the chosen model.

NOTE: Tool search is currently marked as experimental and may evolve in
future releases.

## General checklist
- [x] There are no breaking changes (API, behaviour)
- [X] I have added unit and/or integration tests for my change
- [X] The tests cover both positive and negative cases
- [X] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [X] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
- [X] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)
2026-02-23 14:56:01 +01:00
Dmytro Liubarskyi 9fdd860d98 added convenience methods for setting listeners 2026-02-10 12:51:14 +01:00
Dmytro Liubarskyi 336b2accce
Update versions to 1.12.0-SNAPSHOT and 1.12.0-beta20-SNAPSHOT (#4537)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-04 14:27:44 +01:00
Dmytro Liubarskyi 5f002cde91 feat(bedrock): Add granular cache points support for system messages (#4277) 2026-02-02 18:26:04 +01:00
Karan Bansal 2922db065a
feat(bedrock): Add granular cache points support for system messages (#4277)
## Summary

Adds `BedrockSystemMessage` class to support granular cache point
placement within system messages for AWS Bedrock prompt caching.

This enables caching static portions (instructions, examples) while
keeping dynamic portions (user context) uncached, improving cache
efficiency in multi-user scenarios.

**Example usage:**
```java
BedrockSystemMessage systemMessage = BedrockSystemMessage.builder()
    .addText("You are an AI assistant.")
    .addTextWithCachePoint("Here are 50 examples:\n" + examples)  // Cached
    .addText("Current user: " + userName)  // Not cached
    .build();
```

## Changes

### New Classes (4 files)
- `BedrockSystemContent`: Sealed interface for content blocks with cache
points
- `BedrockSystemContentType`: Enum for content types (TEXT)
- `BedrockSystemTextContent`: Text content with optional cache point
marker
- `BedrockSystemMessage`: System message supporting multiple content
blocks

### Modified Classes (2 files)
- `AbstractBedrockChatModel`: 
- Updated `extractSystemMessages()` and `extractRegularMessages()` to
handle `BedrockSystemMessage`
  - Added cache point validation (max 4 per request)
  - Added null-safety checks for message lists
- `BedrockCachePointPlacement`: Enhanced JavaDoc with AWS requirements

### Tests (5 files)
- `BedrockSystemContentTest`: Unit tests for content blocks
- `BedrockSystemMessageTest`: Unit tests for message builder and
validation
- `BedrockSystemMessageExtractionTest`: Unit tests for extraction logic
with mixed message types
- `BedrockTokenUsageTest`: Unit tests for token usage equals/hashCode
- `BedrockPromptCachingIT`: Integration tests with actual AWS Bedrock

## Key Features
- Granular cache point placement within system messages
- Max 4 cache points per request (AWS limit, validated at build time and
request time)
- Max 10 content blocks per message (with validation)
- Max 1MB text per content block (with validation)
- Backward compatible with existing `AFTER_SYSTEM` placement
- Immutable, thread-safe message design with builder pattern
- Comprehensive JavaDoc with AWS Bedrock caching requirements

## AWS Bedrock Caching Requirements (documented in JavaDoc)
- Maximum 4 cache points per request (across system, user, and tools)
- Minimum ~1,024 tokens for caching to activate
- 5-minute cache TTL (resets on each cache hit)
- Only Claude 3.x and Amazon Nova models support caching

## Backward Compatibility
- Existing `BedrockCachePointPlacement.AFTER_SYSTEM` continues to work
unchanged
- When using `BedrockSystemMessage` with granular cache points,
`AFTER_SYSTEM` is automatically skipped (with warning log)
- Regular `SystemMessage` usage is unaffected

## Known Limitations (documented in JavaDoc)
- Not compatible with `ChatMessageSerializer` (use `toSystemMessage()`
for persistence)
- `MessageWindowChatMemory`/`TokenWindowChatMemory` won't recognize as
system message
- `SystemMessage.findFirst()`/`findAll()`/`findLast()` won't find
`BedrockSystemMessage` instances

Resolves #4187

---------

Co-authored-by: Dmytro Liubarskyi <ljubarskij@gmail.com>
2026-02-02 18:24:48 +01:00
Jonathan Nuñez 9c4892323e
Add support for Bedrock Guardrails (#3988)
## Issue
Closes https://github.com/langchain4j/langchain4j/issues/3987

## Change
For the Bedrock backend interaction, you can now include the guardrails
details so the Converse or Converse Stream will use them on the request.


## General checklist
- [X] There are no breaking changes (API, behaviour)
- [X] I have added unit and/or integration tests for my change
- [X ] The tests cover both positive and negative cases
- [X] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [X] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)


## Checklist for adding new maven module
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added my new module in the root `pom.xml` and
`langchain4j-bom/pom.xml`


## Checklist for adding new embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreIT` that extends
from either `EmbeddingStoreIT` or `EmbeddingStoreWithFilteringIT`
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreRemovalIT` that
extends from `EmbeddingStoreWithRemovalIT`

## Checklist for changing existing embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have manually verified that the
`{NameOfIntegration}EmbeddingStore` works correctly with the data
persisted using the latest released version of LangChain4j

---------

Co-authored-by: Jonathan Nunez Aguin <jonathannunezaguin@fico.com>
Co-authored-by: Dmytro Liubarskyi <ljubarskij@gmail.com>
2026-01-15 18:37:48 +01:00
Jonathan Nuñez b1576e4006
Using the local AWS region instead of cross region inferences to have… (#4412)
… more reliable results on IT tests.


## Issue
Improves the IT tests for caching interactions on AWS Bedrock.

## Change
Uses the local AWS region instead of cross region models.


## General checklist
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ x] There are no breaking changes (API, behaviour)
- [ x] I have added unit and/or integration tests for my change
- [ x] The tests cover both positive and negative cases
- [ x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [ x] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)


## Checklist for adding new maven module
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added my new module in the root `pom.xml` and
`langchain4j-bom/pom.xml`


## Checklist for adding new embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreIT` that extends
from either `EmbeddingStoreIT` or `EmbeddingStoreWithFilteringIT`
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreRemovalIT` that
extends from `EmbeddingStoreWithRemovalIT`

## Checklist for changing existing embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have manually verified that the
`{NameOfIntegration}EmbeddingStore` works correctly with the data
persisted using the latest released version of LangChain4j

Co-authored-by: Jonathan Nunez Aguin <jonathannunezaguin@fico.com>
2026-01-12 11:44:38 +01:00
Tyler J Barkley f459f89e04
[BUG] Remove duplicate tool description in Bedrock API requests (#4035) (#4376)
## Issue
Closes #4035

## Change
- Removed duplicate description field from inputSchema.json in
AwsDocumentConverter
- Tool description now only appears in toolSpec level per AWS Bedrock
documentation
- Updated tests to reflect single description placement

This fix reduces token usage by eliminating unnecessary duplication of
tool descriptions in Bedrock API requests.

## General checklist
- [x] There are no breaking changes (API, behaviour)
- [x] I have written unit and/or integration tests for my change
- [x] I have manually verified that the affected modules build and run
correctly

## Checklist for adding new maven module
- [ ] I have added my new module in the root `pom.xml` and
`langchain4j-bom/pom.xml`

## Checklist for adding new embedding store integration
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreIT`
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreRemovalIT`

## Checklist for changing existing embedding store integration
- [ ] I have manually verified compatibility with data persisted using
the latest released version of LangChain4j
2026-01-09 12:22:41 +01:00
Dmytro Liubarskyi 6363fdb80a CI: parallelize tests in main module 2026-01-09 11:11:57 +01:00
Dmytro Liubarskyi 36754e3f73 cleanup 2025-12-29 10:06:02 +01:00
Dmytro Liubarskyi 9017fb864a fixing flaky tests 2025-12-25 10:53:58 +01:00
Dmytro Liubarskyi 778be1b360
Update versions to 1.11.0-SNAPSHOT and 1.11.0-beta19-SNAPSHOT (#4285)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-24 15:38:05 +01:00
Jonathan Nuñez f511327d10
Increasing system prompt size to be above 1K to get reliable results. (#4270)
## Issue
Fixes issue with the Integration Tests while using Nova Micro.

## Change
Using 1K as the system prompt to Bedrock creates the caching point more
reliable.

## General checklist
<!-- Please double-check the following points and mark them like this:
[X] -->
- [x] There are no breaking changes (API, behaviour)
- [x] I have added unit and/or integration tests for my change
- [x] The tests cover both positive and negative cases
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [x] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)


## Checklist for adding new maven module
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added my new module in the root `pom.xml` and
`langchain4j-bom/pom.xml`


## Checklist for adding new embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreIT` that extends
from either `EmbeddingStoreIT` or `EmbeddingStoreWithFilteringIT`
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreRemovalIT` that
extends from `EmbeddingStoreWithRemovalIT`

## Checklist for changing existing embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have manually verified that the
`{NameOfIntegration}EmbeddingStore` works correctly with the data
persisted using the latest released version of LangChain4j

---------

Co-authored-by: Jonathan Nunez Aguin <jonathannunezaguin@fico.com>
2025-12-22 15:26:17 +01:00
Mario Fusco 2c9941dd8c
Allow to pass ChatRequestParameters to AIServices (#4226)
<!--
Thank you so much for your contribution!

Please fill in all the sections below.
Please open the PR as a draft initially. Once it is reviewed and
approved, we will ask you to add documentation and examples.
Please note that PRs with breaking changes or without tests will be
rejected.

Please note that PRs will be reviewed based on the priority of the
issues they address.
We ask for your patience. We are doing our best to review your PR as
quickly as possible.
Please refrain from pinging and asking when it will be reviewed. Thank
you for understanding!
-->

## Issue
<!-- Please specify the ID of the issue this PR is addressing. For
example: "Closes #1234" or "Fixes #1234" -->
Closes #2410
Closes #3871
Replaces #2411

## Change
<!-- Please describe the changes you made. -->

Allows to set custom `ChatRequestParameters` when calling chat method on
`AiServices` interface.

## General checklist
<!-- Please double-check the following points and mark them like this:
[X] -->
- [x] There are no breaking changes (API, behaviour)
- [x] I have added unit and/or integration tests for my change
- [x] The tests cover both positive and negative cases
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [ ] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)


## Checklist for adding new maven module
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added my new module in the root `pom.xml` and
`langchain4j-bom/pom.xml`


## Checklist for adding new embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreIT` that extends
from either `EmbeddingStoreIT` or `EmbeddingStoreWithFilteringIT`
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreRemovalIT` that
extends from `EmbeddingStoreWithRemovalIT`

## Checklist for changing existing embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have manually verified that the
`{NameOfIntegration}EmbeddingStore` works correctly with the data
persisted using the latest released version of LangChain4j

---------

Co-authored-by: Dmytro Liubarskyi <ljubarskij@gmail.com>
2025-12-16 13:34:18 +01:00
ncilib-ssc 4f6e40f8ba
Issue #4190 : [BUG] AwsDocumentConverter adds all parameters as required instead of using "required" list (#4214)
<!--
Thank you so much for your contribution!

Please fill in all the sections below.
Please open the PR as a draft initially. Once it is reviewed and
approved, we will ask you to add documentation and examples.
Please note that PRs with breaking changes or without tests will be
rejected.

Please note that PRs will be reviewed based on the priority of the
issues they address.
We ask for your patience. We are doing our best to review your PR as
quickly as possible.
Please refrain from pinging and asking when it will be reviewed. Thank
you for understanding!
-->

## Issue
<!-- Please specify the ID of the issue this PR is addressing. For
example: "Closes #1234" or "Fixes #1234" -->
Fixes #4190 

## Change
<!-- Please describe the changes you made. -->
AwsDocumentConverter was setting all of the "properties" as being
required instead of actual "required" property

## General checklist
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] There are no breaking changes (API, behaviour)
- [X] I have added unit and/or integration tests for my change
- [X] The tests cover both positive and negative cases
- [X] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [X] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)


## Checklist for adding new maven module
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added my new module in the root `pom.xml` and
`langchain4j-bom/pom.xml`


## Checklist for adding new embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreIT` that extends
from either `EmbeddingStoreIT` or `EmbeddingStoreWithFilteringIT`
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreRemovalIT` that
extends from `EmbeddingStoreWithRemovalIT`

## Checklist for changing existing embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have manually verified that the
`{NameOfIntegration}EmbeddingStore` works correctly with the data
persisted using the latest released version of LangChain4j

---------

Co-authored-by: Nathan Ciliberto <nciliber@sscinc.com>
2025-12-12 08:51:50 +01:00
Dmytro Liubarskyi 25d3b3ec87 cleaned up test dependencies 2025-12-10 10:18:30 +01:00
Dmytro Liubarskyi ca6097e35d
Update versions to 1.10.0-SNAPSHOT and 1.10.0-beta18-SNAPSHOT (#4152)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-11-28 12:21:30 +01:00