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 2024/05/07 11:36:53 UTC

(camel) branch querybyid-pinecone created (now 4ddb4ab85f6)

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

acosentino pushed a change to branch querybyid-pinecone
in repository https://gitbox.apache.org/repos/asf/camel.git


      at 4ddb4ab85f6 CAMEL-20725 - Camel-Pinecone: Add more producer operations - Query by Id operation

This branch includes the following new commits:

     new 4ddb4ab85f6 CAMEL-20725 - Camel-Pinecone: Add more producer operations - Query by Id operation

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/01: CAMEL-20725 - Camel-Pinecone: Add more producer operations - Query by Id operation

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4ddb4ab85f6a025093eb2c16c65e3fe881c9d59b
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue May 7 12:28:28 2024 +0200

    CAMEL-20725 - Camel-Pinecone: Add more producer operations - Query by Id operation
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../camel/component/pinecone/PineconeVectorDbAction.java |  1 +
 .../component/pinecone/PineconeVectorDbProducer.java     | 15 +++++++++++++++
 .../camel/component/pinecone/it/PineconeComponentIT.java | 16 ++++++++++++++++
 3 files changed, 32 insertions(+)

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 a89a1ccb140..9fe76c664ba 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
@@ -24,5 +24,6 @@ public enum PineconeVectorDbAction {
     DELETE_INDEX,
     DELETE_COLLECTION,
     QUERY,
+    QUERY_BY_ID,
     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 cf7e86be9d0..f787c8342a6 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
@@ -87,6 +87,9 @@ public class PineconeVectorDbProducer extends DefaultProducer {
                 case QUERY:
                     query(exchange);
                     break;
+                case QUERY_BY_ID:
+                    queryById(exchange);
+                    break;
                 default:
                     throw new UnsupportedOperationException("Unsupported action: " + action.name());
             }
@@ -194,6 +197,18 @@ public class PineconeVectorDbProducer extends DefaultProducer {
         populateQueryResponse(result, exchange);
     }
 
+    private void queryById(Exchange exchange) throws Exception {
+        final Message in = exchange.getMessage();
+        String indexName = in.getHeader(PineconeVectorDb.Headers.INDEX_NAME, String.class);
+        int topK = in.getHeader(PineconeVectorDb.Headers.QUERY_TOP_K, Integer.class);
+        Index index = this.client.getIndexConnection(indexName);
+
+        String indexId = in.getHeader(PineconeVectorDb.Headers.INDEX_ID, String.class);
+        QueryResponseWithUnsignedIndices result = index.queryByVectorId(topK, indexId);
+
+        populateQueryResponse(result, exchange);
+    }
+
     // ***************************************
     //
     // Helpers
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 35f281a87ea..f1ad3fcbc59 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
@@ -115,6 +115,22 @@ public class PineconeComponentIT extends CamelTestSupport {
 
     @Test
     @Order(4)
+    public void queryById() {
+
+        Exchange result = fluentTemplate.to("pinecone:test-collection?token={{pinecone.token}}")
+                .withHeader(PineconeVectorDb.Headers.ACTION, PineconeVectorDbAction.QUERY_BY_ID)
+                .withHeader(PineconeVectorDb.Headers.INDEX_NAME, "test-serverless-index")
+                .withHeader(PineconeVectorDb.Headers.INDEX_ID, "elements")
+                .withHeader(PineconeVectorDb.Headers.QUERY_TOP_K, 3)
+                .request(Exchange.class);
+
+        assertThat(result).isNotNull();
+        assertThat(result.getException()).isNull();
+        assertThat(((QueryResponseWithUnsignedIndices) result.getMessage().getBody()).getMatchesList()).isNotEmpty();
+    }
+
+    @Test
+    @Order(5)
     public void deleteIndex() {
 
         Exchange result = fluentTemplate.to("pinecone:test-collection?token={{pinecone.token}}")