This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch CAMEL-20725
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 74ff89dd45f6bc626d022bc66da5606504d28fbd
Author: Andrea Cosentino <anco...@gmail.com>
AuthorDate: Mon May 6 10:53:53 2024 +0200

    CAMEL-20725 - Camel-Pinecone: Add more producer operations - Update 
operation
    
    Signed-off-by: Andrea Cosentino <anco...@gmail.com>
---
 .../apache/camel/catalog/components/pinecone.json  |  2 +-
 .../apache/camel/component/pinecone/pinecone.json  |  2 +-
 .../camel/component/pinecone/PineconeVectorDb.java |  2 +-
 .../component/pinecone/PineconeVectorDbAction.java |  3 ++-
 .../pinecone/PineconeVectorDbProducer.java         | 22 ++++++++++++++++++++++
 .../component/pinecone/it/PineconeComponentIT.java | 20 +++++++++++++++++++-
 6 files changed, 46 insertions(+), 5 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pinecone.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pinecone.json
index 532bdd80669..4ed039bca90 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pinecone.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/pinecone.json
@@ -29,7 +29,7 @@
     "autowiredEnabled": { "index": 3, "kind": "property", "displayName": 
"Autowired Enabled", "group": "advanced", "label": "advanced", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": true, "description": 
"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 t [...]
   },
   "headers": {
-    "CamelPineconeAction": { "index": 0, "kind": "header", "displayName": "", 
"group": "producer", "label": "", "required": false, "javaType": "String", 
"enum": [ "CREATE_COLLECTION", "CREATE_INDEX", "UPSERT", "INSERT", "SEARCH", 
"DELETE" ], "deprecated": false, "deprecationNote": "", "autowired": false, 
"secret": false, "description": "The action to be performed.", "constantName": 
"org.apache.camel.component.pinecone.PineconeVectorDb$Headers#ACTION" },
+    "CamelPineconeAction": { "index": 0, "kind": "header", "displayName": "", 
"group": "producer", "label": "", "required": false, "javaType": "String", 
"enum": [ "CREATE_COLLECTION", "CREATE_INDEX", "UPSERT", "INSERT", "SEARCH", 
"DELETE", "UPDATE" ], "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "The action to be performed.", 
"constantName": 
"org.apache.camel.component.pinecone.PineconeVectorDb$Headers#ACTION" },
     "CamelPineconeOperationStatus": { "index": 1, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "Operation Status.", "constantName": 
"org.apache.camel.component.pinecone.PineconeVectorDb$Headers#OPERATION_STATUS" 
},
     "CamelPineconeOperationStatusValue": { "index": 2, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "Operation Status Value.", 
"constantName": 
"org.apache.camel.component.pinecone.PineconeVectorDb$Headers#OPERATION_STATUS_VALUE"
 },
     "CamelPineconeTextFieldName": { "index": 3, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "Text Field Name for Insert\/Upsert 
operation", "constantName": 
"org.apache.camel.component.pinecone.PineconeVectorDb$Headers#TEXT_FIELD_NAME" 
},
diff --git 
a/components/camel-pinecone/src/generated/resources/META-INF/org/apache/camel/component/pinecone/pinecone.json
 
b/components/camel-pinecone/src/generated/resources/META-INF/org/apache/camel/component/pinecone/pinecone.json
index 532bdd80669..4ed039bca90 100644
--- 
a/components/camel-pinecone/src/generated/resources/META-INF/org/apache/camel/component/pinecone/pinecone.json
+++ 
b/components/camel-pinecone/src/generated/resources/META-INF/org/apache/camel/component/pinecone/pinecone.json
@@ -29,7 +29,7 @@
     "autowiredEnabled": { "index": 3, "kind": "property", "displayName": 
"Autowired Enabled", "group": "advanced", "label": "advanced", "required": 
false, "type": "boolean", "javaType": "boolean", "deprecated": false, 
"autowired": false, "secret": false, "defaultValue": true, "description": 
"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 t [...]
   },
   "headers": {
-    "CamelPineconeAction": { "index": 0, "kind": "header", "displayName": "", 
"group": "producer", "label": "", "required": false, "javaType": "String", 
"enum": [ "CREATE_COLLECTION", "CREATE_INDEX", "UPSERT", "INSERT", "SEARCH", 
"DELETE" ], "deprecated": false, "deprecationNote": "", "autowired": false, 
"secret": false, "description": "The action to be performed.", "constantName": 
"org.apache.camel.component.pinecone.PineconeVectorDb$Headers#ACTION" },
+    "CamelPineconeAction": { "index": 0, "kind": "header", "displayName": "", 
"group": "producer", "label": "", "required": false, "javaType": "String", 
"enum": [ "CREATE_COLLECTION", "CREATE_INDEX", "UPSERT", "INSERT", "SEARCH", 
"DELETE", "UPDATE" ], "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "The action to be performed.", 
"constantName": 
"org.apache.camel.component.pinecone.PineconeVectorDb$Headers#ACTION" },
     "CamelPineconeOperationStatus": { "index": 1, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "Operation Status.", "constantName": 
"org.apache.camel.component.pinecone.PineconeVectorDb$Headers#OPERATION_STATUS" 
},
     "CamelPineconeOperationStatusValue": { "index": 2, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "Operation Status Value.", 
"constantName": 
"org.apache.camel.component.pinecone.PineconeVectorDb$Headers#OPERATION_STATUS_VALUE"
 },
     "CamelPineconeTextFieldName": { "index": 3, "kind": "header", 
"displayName": "", "group": "producer", "label": "", "required": false, 
"javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "Text Field Name for Insert\/Upsert 
operation", "constantName": 
"org.apache.camel.component.pinecone.PineconeVectorDb$Headers#TEXT_FIELD_NAME" 
},
diff --git 
a/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDb.java
 
b/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDb.java
index ecfcbbc2c11..3f7e76901d7 100644
--- 
a/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDb.java
+++ 
b/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDb.java
@@ -26,7 +26,7 @@ public class PineconeVectorDb {
 
     public static class Headers {
         @Metadata(description = "The action to be performed.", javaType = 
"String",
-                  enums = 
"CREATE_COLLECTION,CREATE_INDEX,UPSERT,INSERT,SEARCH,DELETE")
+                  enums = 
"CREATE_COLLECTION,CREATE_INDEX,UPSERT,INSERT,SEARCH,DELETE,UPDATE")
         public static final String ACTION = "CamelPineconeAction";
 
         @Metadata(description = "Operation Status.", javaType = "String")
diff --git 
a/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbAction.java
 
b/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbAction.java
index 779a5b8d93f..a89a1ccb140 100644
--- 
a/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbAction.java
+++ 
b/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbAction.java
@@ -23,5 +23,6 @@ public enum PineconeVectorDbAction {
     UPSERT,
     DELETE_INDEX,
     DELETE_COLLECTION,
-    QUERY
+    QUERY,
+    UPDATE
 }
diff --git 
a/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbProducer.java
 
b/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbProducer.java
index c4268ad6bc6..cf7e86be9d0 100644
--- 
a/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbProducer.java
+++ 
b/components/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbProducer.java
@@ -21,6 +21,7 @@ import java.util.concurrent.ExecutorService;
 
 import io.pinecone.clients.Index;
 import io.pinecone.clients.Pinecone;
+import io.pinecone.proto.UpdateResponse;
 import io.pinecone.proto.UpsertResponse;
 import io.pinecone.unsigned_indices_model.QueryResponseWithUnsignedIndices;
 import org.apache.camel.CamelContext;
@@ -74,6 +75,9 @@ public class PineconeVectorDbProducer extends DefaultProducer 
{
                 case UPSERT:
                     upsert(exchange);
                     break;
+                case UPDATE:
+                    update(exchange);
+                    break;
                 case DELETE_INDEX:
                     deleteIndex(exchange);
                     break;
@@ -153,6 +157,19 @@ public class PineconeVectorDbProducer extends 
DefaultProducer {
 
     }
 
+    private void update(Exchange exchange) throws Exception {
+        final Message in = exchange.getMessage();
+        List elements = in.getMandatoryBody(List.class);
+        String indexName = in.getHeader(PineconeVectorDb.Headers.INDEX_NAME, 
String.class);
+        String indexId = in.getHeader(PineconeVectorDb.Headers.INDEX_ID, 
String.class);
+        Index index = this.client.getIndexConnection(indexName);
+
+        UpdateResponse result = index.update(indexId, elements);
+
+        populateUpdateResponse(result, exchange);
+
+    }
+
     private void deleteIndex(Exchange exchange) throws Exception {
         final Message in = exchange.getMessage();
         String indexName = in.getHeader(PineconeVectorDb.Headers.INDEX_NAME, 
String.class);
@@ -202,6 +219,11 @@ public class PineconeVectorDbProducer extends 
DefaultProducer {
         out.setBody(r);
     }
 
+    private void populateUpdateResponse(UpdateResponse r, Exchange exchange) {
+        Message out = exchange.getMessage();
+        out.setBody(r);
+    }
+
     private void populateQueryResponse(QueryResponseWithUnsignedIndices r, 
Exchange exchange) {
         Message out = exchange.getMessage();
         out.setBody(r);
diff --git 
a/components/camel-pinecone/src/test/java/org/apache/camel/component/pinecone/it/PineconeComponentIT.java
 
b/components/camel-pinecone/src/test/java/org/apache/camel/component/pinecone/it/PineconeComponentIT.java
index 7765a45eb8b..35f281a87ea 100644
--- 
a/components/camel-pinecone/src/test/java/org/apache/camel/component/pinecone/it/PineconeComponentIT.java
+++ 
b/components/camel-pinecone/src/test/java/org/apache/camel/component/pinecone/it/PineconeComponentIT.java
@@ -74,11 +74,29 @@ public class PineconeComponentIT extends CamelTestSupport {
         assertThat(result.getException()).isNull();
     }
 
+    @Test
+    @Order(3)
+    public void update() {
+
+        List<Float> elements = Arrays.asList(1.0f, 2.0f, 3.2f);
+
+        Exchange result = 
fluentTemplate.to("pinecone:test-collection?token={{pinecone.token}}")
+                .withHeader(PineconeVectorDb.Headers.ACTION, 
PineconeVectorDbAction.UPDATE)
+                .withBody(
+                        elements)
+                .withHeader(PineconeVectorDb.Headers.INDEX_NAME, 
"test-serverless-index")
+                .withHeader(PineconeVectorDb.Headers.INDEX_ID, "elements")
+                .request(Exchange.class);
+
+        assertThat(result).isNotNull();
+        assertThat(result.getException()).isNull();
+    }
+
     @Test
     @Order(3)
     public void queryByVector() {
 
-        List<Float> elements = Arrays.asList(1.0f, 2.0f, 3.0f);
+        List<Float> elements = Arrays.asList(1.0f, 2.0f, 3.2f);
 
         Exchange result = 
fluentTemplate.to("pinecone:test-collection?token={{pinecone.token}}")
                 .withHeader(PineconeVectorDb.Headers.ACTION, 
PineconeVectorDbAction.QUERY)

Reply via email to