Pinecone
Since Camel 4.6
Only producer is supported
The Pinecone Component provides support for interacting with the Pinecone Vector Database.
URI format
pinecone:collection[?options]
Where collection represents a named set of points (vectors with a payload) defined in your database.
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,*.yamlfiles, 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 Pinecone component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Action to perform. Enum values:
| PineconeVectorDbAction | ||
Sets the cloud type to use (aws/gcp/azure). Enum values:
| String | ||
Sets the cloud region. | String | ||
Sets the Collection Dimension to use (1-1536). | 1536 | Integer | |
Sets the Collection Similarity Metric to use (cosine/euclidean/dotproduct). | String | ||
The configuration;. | PineconeVectorDbConfiguration | ||
Sets a custom host URL to connect to. | String | ||
Sets the index name to use. | String | ||
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 | |
Set the proxy host. | String | ||
Set the proxy port. | Integer | ||
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 | |
Whether the client uses Transport Layer Security (TLS) to secure communications. | false | boolean | |
Sets the API key to use for authentication. | String |
Endpoint Options
The Pinecone endpoint is configured using URI syntax:
pinecone:collection
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Action to perform. Enum values:
| PineconeVectorDbAction | ||
Sets the cloud type to use (aws/gcp/azure). Enum values:
| String | ||
Sets the cloud region. | String | ||
Sets the Collection Dimension to use (1-1536). | 1536 | Integer | |
Sets the Collection Similarity Metric to use (cosine/euclidean/dotproduct). | String | ||
Sets a custom host URL to connect to. | String | ||
Sets the index name to use. | String | ||
Set the proxy host. | String | ||
Set the proxy port. | Integer | ||
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 | |
Whether the client uses Transport Layer Security (TLS) to secure communications. | false | boolean | |
Sets the API key to use for authentication. | String |
Message Headers
The Pinecone component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelPineconeAction (producer) Constant: | The action to be performed. Enum values:
| String | |
CamelPineconeTextFieldName (producer) Constant: | Text Field Name for Insert/Upsert operation. | String | |
CamelPineconeVectorFieldName (producer) Constant: | Vector Field Name for Insert/Upsert operation. | String | |
CamelPineconeIndexName (producer) Constant: | Index Name. | String | |
CamelPineconeIndexPodType (producer) Constant: | Index Pod Type. | String | |
CamelPineconeIndexPodEnvironment (producer) Constant: | Index Pod Environment. | String | |
CamelPineconeCollectionName (producer) Constant: | Collection Name for Insert/Upsert operation. | String | |
CamelPineconeCollectionSimilarityMetric (producer) Constant: | Collection Similarity Metric. Enum values:
| String | |
CamelPineconeCollectionDimension (producer) Constant: | Collection Dimension. | int | |
CamelPineconeCollectionCloud (producer) Constant: | Collection Cloud Vendor. Enum values:
| String | |
CamelPineconeCollectionCloudRegion (producer) Constant: | Collection Cloud Vendor Region. Enum values:
| String | |
CamelPineconeIndexId (producer) Constant: | The id of the vector for UPSERT, UPDATE and QUERY_BY_ID. Without it, UPSERT generates a random UUID and sets this header to it. | String | |
CamelPineconeQueryTopK (producer) Constant: | The number of matches QUERY and QUERY_BY_ID return. | 10 | Integer |
CamelPineconeNamespace (producer) Constant: | Namespace for actions (query/upsert/etc). | String | |
CamelPineconeQueryFilter (producer) Constant: | Query Filter. | Struct | |
CamelPineconeQueryIncludeValues (producer) Constant: | Query Include Values. | boolean | |
CamelPineconeQueryIncludeMetadata (producer) Constant: | Query Include Metadata. | boolean | |
CamelPineconeMetadata (producer) Constant: | The metadata UPSERT stores with the vector, and the fields of the metadata UPDATE sets. The pinecone:embeddings data type transformer puts the text of the embedding in its text_segment field, which the pinecone:rag data type transformer reads. | Struct |
Message Body
The message body at each side of the Pinecone 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 |
| By the action in the action option or the CamelPineconeAction 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 UPSERT, UPDATE and QUERY, with the id in the CamelPineconeIndexId header (UPSERT generates one without it), and the ids as a List of String for FETCH and DELETE_BY_ID. The other actions do not read the body. Another body fails: the pinecone:embeddings data type transformer builds the vector from the output of langchain4j-embeddings.
|
Producer output |
| By the action: the response of the Pinecone SDK, such as an UpsertResponse, a FetchResponse or a QueryResponseWithUnsignedIndices with the matches. DELETE_INDEX and DELETE_COLLECTION keep the body.
|
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, or the CamelPineconeAction header, selects the operation. The first route below creates a serverless index. The second route queries the index with a vector, and the CamelPineconeQueryTopK header sets how many matches it returns (10 without it):
- route:
from:
uri: direct:createIndex
steps:
- to:
uri: pinecone:my-collection
parameters:
action: CREATE_SERVERLESS_INDEX
token: "{{pinecone.token}}"
indexName: my-index
collectionSimilarityMetric: cosine
collectionDimension: 3
cloud: aws
cloudRegion: us-east-1
- route:
from:
uri: direct:query
steps:
- setHeader:
name: CamelPineconeQueryTopK
expression:
constant:
expression: "3"
- setBody:
expression:
groovy:
expression: "[0.1f, 0.2f, 0.3f]"
- to:
uri: pinecone:my-collection
parameters:
action: QUERY
token: "{{pinecone.token}}"
indexName: my-index
- log:
message: "${body}" The vector of UPSERT, UPDATE and QUERY is the message body: 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. UPSERT stores the vector under the id in the CamelPineconeIndexId header; without the header, it generates a random UUID and sets the header to it.
UPSERT stores the CamelPineconeMetadata header, a com.google.protobuf.Struct, as the metadata of the vector, and UPDATE sets the fields of that header in the metadata of the vector.
The pinecone:embeddings data type transformer turns the embedding of the CamelLangChain4jEmbeddingsVector header, which the langchain4j-embeddings component sets, into the vector of the message body, and fails when the header is missing. It puts the text of a LangChain4j TextSegment or String body in the text_segment field of the CamelPineconeMetadata header, and keeps the other fields of that header. Without the CamelPineconeIndexName and CamelPineconeIndexId headers, it sets them to embeddings and to a random UUID.
The pinecone:rag data type transformer turns the result of a QUERY or QUERY_BY_ID into the List of the texts of its matches, read from their text_segment metadata, which the query returns when the CamelPineconeQueryIncludeMetadata header is true.