Camel Components

weaviate

Since Camel 4.12

Only producer is supported

The Weaviate Component provides support for interacting with the weaviate Vector Database.

URI format

weaviate:collection[?options]

Where collection is the name of a Weaviate collection: a set of objects, each with properties and a vector.

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The weaviate component supports the following options which are listed below.

Name Description Default Type

action (producer)

The action to perform. The CamelWeaviateAction header, when set, wins over this option.

Enum values:

  • AGGREGATE

  • BATCH_CREATE

  • BM25_QUERY

  • CREATE_COLLECTION

  • CREATE

  • DELETE_BY_ID

  • DELETE_COLLECTION

  • HYBRID_QUERY

  • QUERY

  • QUERY_BY_ID

  • UPDATE_BY_ID

WeaviateVectorDbAction

apiKey (producer)

The API key to authenticate with Weaviate. The client sends it as a bearer token on the HTTP (REST) and gRPC connections. If not set, the client does not authenticate.

String

configuration (producer)

The configuration that the endpoints start from. Each endpoint gets a copy, and its options override the values of the copy.

WeaviateVectorDbConfiguration

grpcHost (producer)

The host name or IP address of the gRPC endpoint of Weaviate, without a port. If not set, the host of the host option is used.

String

grpcPort (producer)

The port of the gRPC endpoint of Weaviate.

50051

Integer

host (producer)

The host name or IP address of the Weaviate server, with an optional port for the HTTP (REST) connection, such as localhost:8080, without a scheme. The port is 8080 if not given.

String

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

scheme (producer)

The scheme of the connection to Weaviate: http, or https to use TLS for both the HTTP (REST) and the gRPC connection. With https, the ports stay 8080 and 50051 unless set in the host and grpcPort options.

http

String

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

Endpoint Options

The weaviate endpoint is configured using URI syntax:

weaviate:collection

With the following path and query parameters:

Path Parameters

Name Description Default Type

collection (producer)

Required The name of the collection that the action works on. The CamelWeaviateCollectionName header, when set, wins over it.

String

Query Parameters

Name Description Default Type

action (producer)

The action to perform. The CamelWeaviateAction header, when set, wins over this option.

Enum values:

  • AGGREGATE

  • BATCH_CREATE

  • BM25_QUERY

  • CREATE_COLLECTION

  • CREATE

  • DELETE_BY_ID

  • DELETE_COLLECTION

  • HYBRID_QUERY

  • QUERY

  • QUERY_BY_ID

  • UPDATE_BY_ID

WeaviateVectorDbAction

apiKey (producer)

The API key to authenticate with Weaviate. The client sends it as a bearer token on the HTTP (REST) and gRPC connections. If not set, the client does not authenticate.

String

grpcHost (producer)

The host name or IP address of the gRPC endpoint of Weaviate, without a port. If not set, the host of the host option is used.

String

grpcPort (producer)

The port of the gRPC endpoint of Weaviate.

50051

Integer

host (producer)

The host name or IP address of the Weaviate server, with an optional port for the HTTP (REST) connection, such as localhost:8080, without a scheme. The port is 8080 if not given.

String

scheme (producer)

The scheme of the connection to Weaviate: http, or https to use TLS for both the HTTP (REST) and the gRPC connection. With https, the ports stay 8080 and 50051 unless set in the host and grpcPort options.

http

String

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

Message Headers

The weaviate component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelWeaviateAction (producer)

Constant: ACTION

The action to perform. It wins over the action option.

Enum values:

  • AGGREGATE

  • BATCH_CREATE

  • BM25_QUERY

  • CREATE_COLLECTION

  • CREATE

  • DELETE_BY_ID

  • DELETE_COLLECTION

  • HYBRID_QUERY

  • QUERY

  • QUERY_BY_ID

  • UPDATE_BY_ID

String

CamelWeaviateTextFieldName (producer)

Constant: TEXT_FIELD_NAME

The name of the property in which the weaviate:embeddings data type transformer puts the text of the TextSegment, in the CamelWeaviateProperties header for CREATE and UPDATE_BY_ID. Default text. The producer does not read this header.

String

CamelWeaviateCollectionName (producer)

Constant: COLLECTION_NAME

The name of the collection that the action works on. It wins over the collection in the endpoint URI.

String

CamelWeaviateFields (producer)

Constant: FIELDS

The properties that QUERY, HYBRID_QUERY and BM25_QUERY return, as the keys of a Map (the values are not used). Without it, the query returns all properties that are not cross-references.

HashMap

CamelWeaviateProperties (producer)

Constant: PROPERTIES

The properties of the object for CREATE and UPDATE_BY_ID, as a Map of property name to value. Without it, CREATE inserts an object without properties.

HashMap

CamelWeaviateIndexId (producer)

Constant: INDEX_ID

The id (a UUID) of the object for QUERY_BY_ID, UPDATE_BY_ID and DELETE_BY_ID, which require it.

String

CamelWeaviateQueryTopK (producer)

Constant: QUERY_TOP_K

The maximum number of objects that QUERY, HYBRID_QUERY and BM25_QUERY return (the limit of the query). Default 10.

Integer

CamelWeaviateUpdateWithMerge (producer)

Constant: UPDATE_WITH_MERGE

Whether UPDATE_BY_ID merges the properties of the CamelWeaviateProperties header into the object (true, a PATCH request), or replaces all properties of the object with them (false, a PUT request), which removes the properties that are not in the header. The vector of the object is replaced in both cases.

true

Boolean

CamelWeaviateKeyName (producer)

Constant: KEY_NAME

The name of the property in which the weaviate:embeddings data type transformer puts the value of the CamelWeaviateKeyValue header, in the CamelWeaviateProperties header. Default id. The producer does not read this header.

String

CamelWeaviateKeyValue (producer)

Constant: KEY_VALUE

A value that the weaviate:embeddings data type transformer adds to the properties of the object, under the name in the CamelWeaviateKeyName header. It is a property, not the id (UUID) of the object, and only CREATE and UPDATE_BY_ID store it. The producer does not read this header.

String

CamelWeaviateHybridAlpha (producer)

Constant: HYBRID_ALPHA

The weight of the vector search against the keyword (BM25) search in HYBRID_QUERY, from 0 (keyword search only) to 1 (vector search only). Without it, Weaviate uses its default.

Float

CamelWeaviateQueryVector (producer)

Constant: QUERY_VECTOR

The vector for the vector search of HYBRID_QUERY, as a List of numbers. Without it, Weaviate computes the vector from the query text with the vectorizer of the collection.

List

Message Body

The message body at each side of the weaviate component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Producer input

list, text or null

By the action in the action option or the CamelWeaviateAction header: the vector as a List of numbers, such as the List of Double a JSON array unmarshals to, or a float or double array for CREATE, UPDATE_BY_ID and QUERY, with the properties in the CamelWeaviateProperties header, a List of WeaviateObject for BATCH_CREATE, and the query text for HYBRID_QUERY and BM25_QUERY. CREATE_COLLECTION, DELETE_COLLECTION, QUERY_BY_ID, DELETE_BY_ID and AGGREGATE do not read the body, the id is in the CamelWeaviateIndexId header. Another body fails: the weaviate:embeddings data type transformer builds the vector from the output of langchain4j-embeddings.

  • With action=CREATE: list

  • With action=BATCH_CREATE: list (java.util.List<io.weaviate.client6.v1.api.collections.WeaviateObject<java.util.Map<java.lang.String, java.lang.Object>>>)

  • With action=UPDATE_BY_ID: list

  • With action=QUERY: list

  • With action=HYBRID_QUERY: text (java.lang.String)

  • With action=BM25_QUERY: text (java.lang.String)

  • With action=CREATE_COLLECTION: any

  • With action=DELETE_COLLECTION: any

  • With action=QUERY_BY_ID: any

  • With action=DELETE_BY_ID: any

  • With action=AGGREGATE: any

Producer output

pojo or value

By the action: a WeaviateObject for CREATE, an InsertManyResponse for BATCH_CREATE, a QueryResponse for QUERY, HYBRID_QUERY and BM25_QUERY, an Optional of WeaviateObject for QUERY_BY_ID, an AggregateResponse for AGGREGATE, and a Boolean for CREATE_COLLECTION, UPDATE_BY_ID, DELETE_BY_ID and DELETE_COLLECTION.

  • With action=CREATE: pojo (io.weaviate.client6.v1.api.collections.WeaviateObject<java.util.Map<java.lang.String, java.lang.Object>>)

  • With action=BATCH_CREATE: pojo (io.weaviate.client6.v1.api.collections.data.InsertManyResponse)

  • With action=QUERY: pojo (io.weaviate.client6.v1.api.collections.query.QueryResponse<java.util.Map<java.lang.String, java.lang.Object>>)

  • With action=HYBRID_QUERY: pojo (io.weaviate.client6.v1.api.collections.query.QueryResponse<java.util.Map<java.lang.String, java.lang.Object>>)

  • With action=BM25_QUERY: pojo (io.weaviate.client6.v1.api.collections.query.QueryResponse<java.util.Map<java.lang.String, java.lang.Object>>)

  • With action=QUERY_BY_ID: pojo (java.util.Optional<io.weaviate.client6.v1.api.collections.WeaviateObject<java.util.Map<java.lang.String, java.lang.Object>>>)

  • With action=AGGREGATE: pojo (io.weaviate.client6.v1.api.collections.aggregate.AggregateResponse)

  • With action=CREATE_COLLECTION: value (java.lang.Boolean)

  • With action=UPDATE_BY_ID: value (java.lang.Boolean)

  • With action=DELETE_BY_ID: value (java.lang.Boolean)

  • With action=DELETE_COLLECTION: value (java.lang.Boolean)

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Usage

The action option of the endpoint, such as weaviate:myCollection?action=BM25_QUERY, or the CamelWeaviateAction header selects the operation; the header, when set, wins over the option. Without either, the producer fails. The weaviate:embeddings data type transformer runs before the endpoint, so it reads the header only. The routes below create a collection, add an object with its vector (the message body) and its properties (the CamelWeaviateProperties header), and run a keyword (BM25) search for the text in the message body:

- route:
    from:
      uri: direct:createCollection
      steps:
        - setHeader:
            name: CamelWeaviateAction
            expression:
              constant:
                expression: CREATE_COLLECTION
        - to:
            uri: weaviate:Articles
            parameters:
              host: localhost:8080
- route:
    from:
      uri: direct:addArticle
      steps:
        - setHeader:
            name: CamelWeaviateAction
            expression:
              constant:
                expression: CREATE
        - setHeader:
            name: CamelWeaviateProperties
            expression:
              groovy:
                expression: "[title: 'Camel in Action', category: 'books']"
        - setBody:
            expression:
              groovy:
                expression: "[0.1f, 0.2f, 0.3f]"
        - to:
            uri: weaviate:Articles
            parameters:
              host: localhost:8080
- route:
    from:
      uri: direct:search
      steps:
        - setHeader:
            name: CamelWeaviateAction
            expression:
              constant:
                expression: BM25_QUERY
        - setHeader:
            name: CamelWeaviateQueryTopK
            expression:
              constant:
                expression: "5"
        - to:
            uri: weaviate:Articles
            parameters:
              host: localhost:8080
        - log:
            message: "${body}"

The vector of CREATE, UPDATE_BY_ID and QUERY is the message body, and the optional vector of HYBRID_QUERY is the CamelWeaviateQueryVector header. Either is a List of numbers, such as the List of Double a JSON array unmarshals to, or a float[] or a double[]; each number is converted to a float. Another body fails, and so does a List with an element that is not a number.