allthingssecurity opened a new pull request, #31015:
URL: https://github.com/apache/camel/pull/31015

   # Description
   
   [CAMEL-27632](https://issues.apache.org/jira/browse/CAMEL-27632)
   
   The ticket lists three problems of camel-pgvector that came up while the 
option descriptions were written for CAMEL-23832 (#30975). I checked each one 
against main. Two are fixed here, one is left as it is.
   
   Fixed:
   1. **The pgvector:embeddings transformer could write invalid JSON 
metadata.** `PgVectorEmbeddingsDataTypeTransformer.toJson()` builds the JSON by 
hand, and `escapeJson()` only escaped the backslash, the double quote, newline, 
carriage return and tab. A key or value with another control character, such as 
a form feed or U+0001 from an extracted document, went into the 
`CamelPgVectorMetadata` header unescaped, which is not valid JSON, so a later 
`metadata::jsonb` cast fails on that row. Every character below U+0020 is now 
escaped, as `\uXXXX` unless it has a short escape. I kept the small 
hand-written escaping instead of adding a JSON library dependency to the 
module. Metadata without control characters is written exactly as before.
   3. **The description of the transformer was vague.** It now says that the 
vector of the `CamelLangChain4jEmbeddingsVector` header becomes the body, as a 
List of Float, and that the `CamelPgVectorRecordId`, `CamelPgVectorTextContent` 
and `CamelPgVectorMetadata` headers of an UPSERT are set.
   
   Not changed:
   2. **dataSource is not marked required.** The endpoint does fail to start 
without a DataSource, but the option is `autowired`: it can be set on the 
component, or come from the registry when there is a single `DataSource`, as 
the `dataSource` of camel-sql, which is not marked required either. With 
`required = true` the catalog and the tools that validate endpoint URIs would 
report a missing option for `pgvector:myTable` URIs that work. #30975 already 
documents in the description of `dataSource` that the endpoint fails to start 
when no DataSource is set or autowired, which is the second choice the ticket 
offers.
   
   No upgrade guide entry: only metadata with control characters is written 
differently, and that JSON was not valid before.
   
   This PR does not touch the files of #30975 (it changes the transformer and 
its generated JSON only), so the two do not conflict, and I did not find a text 
of #30975 that becomes wrong.
   
   Tests:
   - `PgVectorEmbeddingsMetadataJsonTest` (new): metadata whose key and value 
have control characters (U+001F, a form feed, U+0001, newline, tab, carriage 
return) and a backslash and a double quote is written with every control 
character escaped, and parses back to the same key and value. Against the main 
sources it fails: the form feed and U+0001 are not escaped.
   
   Results (offline, module build of camel-pgvector, test phase, unit tests 
only): 19 tests run, 0 failures, 0 errors, 0 skipped. The new test class passed 
5 runs in a row.
   
   Generated files: `pgvector-embeddings.json` of the transformer and its 
catalog copy (the description).
   
   Built and tested offline against LangChain4j 1.22.0 (main uses 1.24.0); the 
change does not use any LangChain4j API that differs between the two.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it): 
[CAMEL-27632](https://issues.apache.org/jira/browse/CAMEL-27632).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     (I built camel-pgvector and ran its unit tests, and committed the 
regenerated transformer JSON. The catalog copy is a copy of it (the two were 
identical on main), as an offline build of the catalog was not possible here. I 
did not run the full root build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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]

Reply via email to