Claus Ibsen created CAMEL-27632:
-----------------------------------

             Summary: camel-pgvector: embeddings transformer writes invalid 
JSON, dataSource not marked required
                 Key: CAMEL-27632
                 URL: https://issues.apache.org/jira/browse/CAMEL-27632
             Project: Camel
          Issue Type: Bug
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while improving the option descriptions of camel-pgvector for CAMEL-23832 
(PR https://github.com/apache/camel/pull/30975).
These are separate problems of the component; the descriptions PR only 
documents the current behavior.

h4. 1. The pgvector:embeddings transformer can write invalid JSON metadata
{{PgVectorEmbeddingsDataTypeTransformer.toJson()}} builds the JSON of the 
metadata of the TextSegment by hand. {{escapeJson()}} escapes only backslash, 
double quote, newline, carriage return and tab.
JSON requires an escape for every control character from U+0000 to U+001F. A 
metadata key or value with another control character, such as a form feed or 
U+0001 from an extracted document, gives a {{CamelPgVectorMetadata}} header 
that is not valid JSON. UPSERT stores it as it is, and a later 
{{metadata::jsonb}} cast in a filter fails on that row.
Proposed change: build the JSON with a JSON library, or escape every character 
below U+0020 as {{\uXXXX}}.

h4. 2. The dataSource option is not marked as required
{{PgVectorEndpoint.doStart()}} throws an {{IllegalArgumentException}} when 
{{PgVectorConfiguration.getDataSource()}} is null, so the endpoint cannot start 
without a DataSource. The metadata still marks {{dataSource}} as {{"required": 
false}} for the component and the endpoint. Tools that read the catalog, such 
as validators and editors, do not report a missing DataSource.
Proposed change: add {{required = true}} to the {{@Metadata}} of 
{{dataSource}}, or document why it stays optional.

h4. 3. The description of the pgvector:embeddings transformer is vague
The {{@DataTypeTransformer}} of {{PgVectorEmbeddingsDataTypeTransformer}} has 
the description "Prepares the message to become an object writable by PgVector 
component". It does not say that the transformer puts the vector of the 
{{CamelLangChain4jEmbeddingsVector}} header in the body as a List of Float, and 
sets the {{CamelPgVectorRecordId}}, {{CamelPgVectorTextContent}} and 
{{CamelPgVectorMetadata}} headers for UPSERT.
Proposed change: rewrite the description, for example "Turns the embedding of 
camel-langchain4j-embeddings into the vector and headers of a pgvector UPSERT."

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to