You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2025/09/10 13:46:16 UTC

(camel) branch main updated: Camel-Pinecone: Add deleteById operation (#19140)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new b7eddef8edc Camel-Pinecone: Add deleteById operation (#19140)
b7eddef8edc is described below

commit b7eddef8edc4b2d776b2417010d3e4e1f68217dc
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Sep 10 15:46:10 2025 +0200

    Camel-Pinecone: Add deleteById operation (#19140)
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../component/pinecone/PineconeVectorDbAction.java |  3 ++-
 .../pinecone/PineconeVectorDbProducer.java         | 26 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbAction.java b/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbAction.java
index 406b27aa1b6..bd68cd90d00 100644
--- a/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbAction.java
+++ b/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbAction.java
@@ -26,5 +26,6 @@ public enum PineconeVectorDbAction {
     DELETE_COLLECTION,
     QUERY,
     QUERY_BY_ID,
-    UPDATE
+    UPDATE,
+    DELETE_BY_ID
 }
diff --git a/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbProducer.java b/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbProducer.java
index c60a513f556..4965534c59a 100644
--- a/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbProducer.java
+++ b/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDbProducer.java
@@ -22,6 +22,7 @@ import java.util.concurrent.ExecutorService;
 import com.google.protobuf.Struct;
 import io.pinecone.clients.Index;
 import io.pinecone.clients.Pinecone;
+import io.pinecone.proto.DeleteResponse;
 import io.pinecone.proto.FetchResponse;
 import io.pinecone.proto.UpdateResponse;
 import io.pinecone.proto.UpsertResponse;
@@ -96,6 +97,9 @@ public class PineconeVectorDbProducer extends DefaultProducer {
                 case QUERY_BY_ID:
                     queryById(exchange);
                     break;
+                case DELETE_BY_ID:
+                    deleteByIds(exchange);
+                    break;
                 default:
                     throw new UnsupportedOperationException("Unsupported action: " + action.name());
             }
@@ -250,6 +254,23 @@ public class PineconeVectorDbProducer extends DefaultProducer {
         this.client.deleteCollection(collectionName);
     }
 
+    private void deleteByIds(Exchange exchange) throws Exception {
+        final Message in = exchange.getMessage();
+        List elements = in.getMandatoryBody(List.class);
+        String indexName = getEndpoint().getConfiguration().getIndexName();
+
+        if (in.getHeader(PineconeVectorDb.Headers.INDEX_NAME, String.class) != null) {
+            indexName = in.getHeader(PineconeVectorDb.Headers.INDEX_NAME, String.class);
+        }
+
+        Index index = this.client.getIndexConnection(indexName);
+
+        DeleteResponse result
+                = index.deleteByIds(elements);
+
+        populateDeleteResponse(result, exchange);
+    }
+
     private void fetch(Exchange exchange) throws Exception {
         final Message in = exchange.getMessage();
         List elements = in.getMandatoryBody(List.class);
@@ -361,4 +382,9 @@ public class PineconeVectorDbProducer extends DefaultProducer {
         Message out = exchange.getMessage();
         out.setBody(r);
     }
+
+    private void populateDeleteResponse(DeleteResponse r, Exchange exchange) {
+        Message out = exchange.getMessage();
+        out.setBody(r);
+    }
 }