atiaomar1978-hub opened a new pull request, #24914: URL: https://github.com/apache/camel/pull/24914
## CAMEL-23949 — Full Summary **Jira:** https://issues.apache.org/jira/browse/CAMEL-23949 **Title:** camel-langchain4j-embeddingstore: ADD without embedding header calls EmbeddingStore.add(null) instead of failing **Type / Priority / Status:** Bug · Major · Open **Component:** camel-langchain4j-embeddings **Created:** 2026-07-08 --- ### Problem In `LangChain4jEmbeddingStoreProducer.add()`, the ADD action did not validate that the required embedding header (`CamelLangChain4jEmbeddingsEmbedding` / `LangChain4jEmbeddingsHeaders.EMBEDDING`) was present. When the header was missing, the producer called `EmbeddingStore.add(null)`. The exchange completed without a Camel-level error, unlike the missing action case, which already threw `NoSuchHeaderException`. Depending on the backing store, that could mean: - a store-specific NPE later, or - silently persisting invalid data --- ### Fix Added a fail-fast null check before calling the store, matching the existing action-validation pattern: ```java if (in.getHeader(LangChain4jEmbeddingsHeaders.EMBEDDING) == null) { throw new NoSuchHeaderException( "The embedding is a required header for ADD operations", exchange, LangChain4jEmbeddingsHeaders.EMBEDDING); } ``` **Scope:** ADD only. REMOVE and SEARCH behavior unchanged. **Generated artifacts:** none — no catalog/endpoint DSL regen needed. --- ### Files Changed (2 files, +210 / −6) | File | Change | |------|--------| | `LangChain4jEmbeddingStoreProducer.java` | Validation guard in `add()` | | `LangChain4jEmbeddingStoreMissingEmbeddingHeaderTest.java` | New test class (202 lines) | --- ### Test Coverage — 7/7 passed New class: `LangChain4jEmbeddingStoreMissingEmbeddingHeaderTest` Uses a `RecordingEmbeddingStore` (extends `InMemoryEmbeddingStore`) to assert the store is not called on failure. | Test | Verifies | |------|----------| | `addWithoutEmbeddingHeaderFailsFast` | ADD with action header only → NoSuchHeaderException, 0 store calls | | `addWithEndpointDefaultActionAndMissingEmbeddingHeaderFailsFast` | ADD via `?action=ADD` without embedding → same | | `addWithTextSegmentButNoEmbeddingHeaderFailsFast` | Text segment present but no embedding → still fails | | `addWithEmbeddingHeaderSucceeds` | Valid ADD stores embedding | | `addWithEmbeddingAndTextSegmentSucceeds` | ADD with both headers works | | `missingActionHeaderFailsFast` | Existing action validation still works | | `removeWithoutEmbeddingHeaderSucceeds` | REMOVE regression — no embedding header required | **Run command:** ```powershell $env:JAVA_HOME = "C:\Program Files\Eclipse Adoptium\jdk-21.0.11.10-hotspot" Set-Location C:\c\camel-23949-fix .\mvnw.cmd -pl components/camel-ai/camel-langchain4j-embeddingstore -am -DskipTests install -q .\mvnw.cmd -pl components/camel-ai/camel-langchain4j-embeddingstore "-Dtest=LangChain4jEmbeddingStoreMissingEmbeddingHeaderTest" test ``` --- ### Git Status | Item | Value | |------|-------| | **Branch** | `CAMEL-23949-embeddingstore-missing-embedding-header` | | **Commit** | `479b783b4122` | | **Author** | `atiaomar1978-hub <[email protected]>` | | **Date** | Sun Jul 19, 2026 10:50 AM (UTC-7) | | **Remote** | Pushed to https://github.com/atiaomar1978-hub/camel | | **Worktree** | `C:\c\camel-23949-fix` | | **PR** | Not created yet | **Commit message:** ``` CAMEL-23949: Fail fast when ADD is missing embedding header Throw NoSuchHeaderException instead of calling EmbeddingStore.add(null) when the CamelLangChain4jEmbeddingsEmbedding header is absent on ADD. Co-Authored-By: Cursor <[email protected]> ``` **Summary** - Fail fast on ADD when `CamelLangChain4jEmbeddingsEmbedding` is missing - Aligns with existing missing-action validation via `NoSuchHeaderException` - Adds focused unit tests with a recording store stub **Test plan** - [x] `LangChain4jEmbeddingStoreMissingEmbeddingHeaderTest` — 7/7 passed locally - [ ] CI green on fork PR against `apache/camel` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
