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 is the name of the Pinecone collection, a static copy of an index, that CREATE_COLLECTION creates and DELETE_COLLECTION deletes. The other actions work on the index of the indexName option or the CamelPineconeIndexName header, and do not use it.
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 |
|---|---|---|---|
The action to perform. The CamelPineconeAction header, when set, wins over this option. Enum values:
| PineconeVectorDbAction | ||
The cloud provider that hosts the serverless index that CREATE_SERVERLESS_INDEX creates, which requires it. CREATE_POD_INDEX does not use it. The CamelPineconeCollectionCloud header, when set, wins over this option. Enum values:
| String | ||
The region of the cloud provider that hosts the serverless index that CREATE_SERVERLESS_INDEX creates, such as us-east-1, which it requires. CREATE_POD_INDEX does not use it. The CamelPineconeCollectionCloudRegion header, when set, wins over this option. | String | ||
The number of dimensions of the vectors in the index that CREATE_SERVERLESS_INDEX and CREATE_POD_INDEX create, which must match the embedding model, and be at least 1. The CamelPineconeCollectionDimension header, when set, wins over this option. | 1536 | Integer | |
The similarity metric of the index that CREATE_SERVERLESS_INDEX and CREATE_POD_INDEX create: cosine, euclidean or dotproduct, in lower case. CREATE_SERVERLESS_INDEX requires it, CREATE_POD_INDEX uses cosine if not set. The CamelPineconeCollectionSimilarityMetric header, when set, wins over this option. | String | ||
The configuration that the endpoints of this component start from: each endpoint gets a copy of it, and its own options override the copy. | PineconeVectorDbConfiguration | ||
The base URL of the Pinecone control plane (REST), such as http://localhost:5080 for Pinecone Local. If not set, https://api.pinecone.io is used. The data plane (gRPC) connects to the host that Pinecone returns for the index, not to this one. Not used when a Pinecone client is set with PineconeVectorDbConfiguration.setClient(). | String | ||
The name of the index that the action works on, the index that CREATE_SERVERLESS_INDEX and CREATE_POD_INDEX create, or the source index of CREATE_COLLECTION. DELETE_COLLECTION does not use it. The CamelPineconeIndexName header, when set, wins over this option. | 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 | |
The host name or IP address of an HTTP proxy that the control plane (REST) and data plane (gRPC) requests go through. Only used together with proxyPort. Not used when a Pinecone client is set with PineconeVectorDbConfiguration.setClient(). | String | ||
The port of the HTTP proxy that the control plane (REST) and data plane (gRPC) requests go through. Only used together with proxyHost. Not used when a Pinecone client is set with PineconeVectorDbConfiguration.setClient(). | 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 data plane (gRPC) connection to the index uses TLS. Default false, unlike the Pinecone client, which enables TLS by default: with false, the vectors, and the API key in the api-key metadata, are sent in clear text. Set it to true for an index in the Pinecone cloud; false is for a local server such as Pinecone Local. The control plane (REST) uses the scheme of the host option instead. Not used when a Pinecone client is set with PineconeVectorDbConfiguration.setClient(). | false | boolean | |
The API key of the Pinecone project. The client sends it in the Api-Key header of the control plane (REST) requests and in the api-key metadata of the data plane (gRPC) requests. Required: without it, the producer fails to start. Not used when a Pinecone client is set with PineconeVectorDbConfiguration.setClient(). | String |
Endpoint Options
The Pinecone endpoint is configured using URI syntax:
pinecone:collection
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The name of the collection that CREATE_COLLECTION creates and DELETE_COLLECTION deletes. A Pinecone collection is a static copy of an index. The CamelPineconeCollectionName header, when set, wins over it. The other actions do not use it. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The action to perform. The CamelPineconeAction header, when set, wins over this option. Enum values:
| PineconeVectorDbAction | ||
The cloud provider that hosts the serverless index that CREATE_SERVERLESS_INDEX creates, which requires it. CREATE_POD_INDEX does not use it. The CamelPineconeCollectionCloud header, when set, wins over this option. Enum values:
| String | ||
The region of the cloud provider that hosts the serverless index that CREATE_SERVERLESS_INDEX creates, such as us-east-1, which it requires. CREATE_POD_INDEX does not use it. The CamelPineconeCollectionCloudRegion header, when set, wins over this option. | String | ||
The number of dimensions of the vectors in the index that CREATE_SERVERLESS_INDEX and CREATE_POD_INDEX create, which must match the embedding model, and be at least 1. The CamelPineconeCollectionDimension header, when set, wins over this option. | 1536 | Integer | |
The similarity metric of the index that CREATE_SERVERLESS_INDEX and CREATE_POD_INDEX create: cosine, euclidean or dotproduct, in lower case. CREATE_SERVERLESS_INDEX requires it, CREATE_POD_INDEX uses cosine if not set. The CamelPineconeCollectionSimilarityMetric header, when set, wins over this option. | String | ||
The base URL of the Pinecone control plane (REST), such as http://localhost:5080 for Pinecone Local. If not set, https://api.pinecone.io is used. The data plane (gRPC) connects to the host that Pinecone returns for the index, not to this one. Not used when a Pinecone client is set with PineconeVectorDbConfiguration.setClient(). | String | ||
The name of the index that the action works on, the index that CREATE_SERVERLESS_INDEX and CREATE_POD_INDEX create, or the source index of CREATE_COLLECTION. DELETE_COLLECTION does not use it. The CamelPineconeIndexName header, when set, wins over this option. | String | ||
The host name or IP address of an HTTP proxy that the control plane (REST) and data plane (gRPC) requests go through. Only used together with proxyPort. Not used when a Pinecone client is set with PineconeVectorDbConfiguration.setClient(). | String | ||
The port of the HTTP proxy that the control plane (REST) and data plane (gRPC) requests go through. Only used together with proxyHost. Not used when a Pinecone client is set with PineconeVectorDbConfiguration.setClient(). | 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 data plane (gRPC) connection to the index uses TLS. Default false, unlike the Pinecone client, which enables TLS by default: with false, the vectors, and the API key in the api-key metadata, are sent in clear text. Set it to true for an index in the Pinecone cloud; false is for a local server such as Pinecone Local. The control plane (REST) uses the scheme of the host option instead. Not used when a Pinecone client is set with PineconeVectorDbConfiguration.setClient(). | false | boolean | |
The API key of the Pinecone project. The client sends it in the Api-Key header of the control plane (REST) requests and in the api-key metadata of the data plane (gRPC) requests. Required: without it, the producer fails to start. Not used when a Pinecone client is set with PineconeVectorDbConfiguration.setClient(). | 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 perform. It wins over the action option. Enum values:
| String | |
CamelPineconeTextFieldName (producer) Constant: | Not used: neither the producer nor the data type transformers read this header. | String | |
CamelPineconeVectorFieldName (producer) Constant: | Not used: neither the producer nor the data type transformers read this header. | String | |
CamelPineconeIndexName (producer) Constant: | The name of the index that the action works on, the index that CREATE_SERVERLESS_INDEX and CREATE_POD_INDEX create, or the source index of CREATE_COLLECTION. It wins over the indexName option. DELETE_COLLECTION does not use it. | String | |
CamelPineconeIndexPodType (producer) Constant: | The pod type of the index that CREATE_POD_INDEX creates, which requires it: s1, p1 or p2, then a dot and the size x1, x2, x4 or x8, such as p1.x1. | String | |
CamelPineconeIndexPodEnvironment (producer) Constant: | The environment (cloud region) that hosts the index that CREATE_POD_INDEX creates, which requires it, such as us-east4-gcp. | String | |
CamelPineconeCollectionName (producer) Constant: | The name of the collection that CREATE_COLLECTION creates and DELETE_COLLECTION deletes. It wins over the collection in the endpoint URI. | String | |
CamelPineconeCollectionSimilarityMetric (producer) Constant: | The similarity metric of the index that CREATE_SERVERLESS_INDEX and CREATE_POD_INDEX create, in lower case. It wins over the collectionSimilarityMetric option. Enum values:
| String | |
CamelPineconeCollectionDimension (producer) Constant: | The number of dimensions of the vectors in the index that CREATE_SERVERLESS_INDEX and CREATE_POD_INDEX create. It wins over the collectionDimension option. | int | |
CamelPineconeCollectionCloud (producer) Constant: | The cloud provider that hosts the serverless index that CREATE_SERVERLESS_INDEX creates. It wins over the cloud option. Enum values:
| String | |
CamelPineconeCollectionCloudRegion (producer) Constant: | The region of the cloud provider that hosts the serverless index that CREATE_SERVERLESS_INDEX creates, such as us-east-1. It wins over the cloudRegion option. Enum values:
| String | |
CamelPineconeIndexId (producer) Constant: | The id of the vector for UPSERT, UPDATE and QUERY_BY_ID, which UPDATE requires. 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: | The namespace in the index that UPSERT, UPDATE, QUERY and QUERY_BY_ID work on. Without it, they work on the default namespace. FETCH and DELETE_BY_ID do not use it, and always work on the default namespace. | String | |
CamelPineconeQueryFilter (producer) Constant: | The metadata filter of QUERY and QUERY_BY_ID, as a Struct in the filter syntax of Pinecone (metadata fields with operators such as $eq or $in): only the vectors whose metadata matches it are returned. Without it, the query does not filter. | Struct | |
CamelPineconeQueryIncludeValues (producer) Constant: | Whether QUERY and QUERY_BY_ID return the values (the vector) of each match. Default false. | boolean | |
CamelPineconeQueryIncludeMetadata (producer) Constant: | Whether QUERY and QUERY_BY_ID return the metadata of each match, which the pinecone:rag data type transformer reads. Default false. | 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 CamelPineconeIndexId header, it sets it to a random UUID. It leaves the CamelPineconeIndexName header unset when the route does not set it, so that the producer uses the indexName option of its endpoint.
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.