You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2025/02/28 07:32:05 UTC
(camel) branch main updated: CAMEL-21814 Add additional arguments to query actions for camel-pinecone (#17301)
This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 08240e851c1 CAMEL-21814 Add additional arguments to query actions for camel-pinecone (#17301)
08240e851c1 is described below
commit 08240e851c14c0d0b9b580c39fe25209db6a94e4
Author: Tom Cunningham <tc...@redhat.com>
AuthorDate: Fri Feb 28 02:31:59 2025 -0500
CAMEL-21814 Add additional arguments to query actions for camel-pinecone (#17301)
---
.../apache/camel/catalog/components/pinecone.json | 6 ++-
.../apache/camel/component/pinecone/pinecone.json | 6 ++-
.../camel/component/pinecone/PineconeVectorDb.java | 13 ++++++
.../pinecone/PineconeVectorDbProducer.java | 24 ++++++++++-
.../component/pinecone/it/PineconeComponentIT.java | 24 +++++++++++
.../PineconeVectorDbEndpointBuilderFactory.java | 48 ++++++++++++++++++++++
6 files changed, 117 insertions(+), 4 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 bc2ea0bcd5b..b485013342c 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
@@ -50,7 +50,11 @@
"CamelPineconeCollectionCloud": { "index": 9, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "enum": [ "aws", "gcp", "azure" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Collection Cloud Vendor", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#COLLECTION_CLOUD" },
"CamelPineconeCollectionCloudRegion": { "index": 10, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "enum": [ "aws", "gcp", "azure" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Collection Cloud Vendor Region", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#COLLECTION_CLOUD_REGION" },
"CamelPineconeIndexId": { "index": 11, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Index Upsert Id", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#INDEX_ID" },
- "CamelPineconeQueryTopK": { "index": 12, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "Integer", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Top K", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_TOP_K" }
+ "CamelPineconeQueryTopK": { "index": 12, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "Integer", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Top K", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_TOP_K" },
+ "CamelPineconeQueryNamespace": { "index": 13, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Namespace", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_NAMESPACE" },
+ "CamelPineconeQueryFilter": { "index": 14, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Filter", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_FILTER" },
+ "CamelPineconeQueryIncludeValues": { "index": 15, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Include Values", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_INCLUDE_VALUES" },
+ "CamelPineconeQueryIncludeMetadata": { "index": 16, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "com.google.protobuf.Struct", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Include Metadata", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_INCLUDE_METADATA" }
},
"properties": {
"collection": { "index": 0, "kind": "path", "displayName": "Collection", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The collection Name" },
diff --git a/components/camel-ai/camel-pinecone/src/generated/resources/META-INF/org/apache/camel/component/pinecone/pinecone.json b/components/camel-ai/camel-pinecone/src/generated/resources/META-INF/org/apache/camel/component/pinecone/pinecone.json
index bc2ea0bcd5b..b485013342c 100644
--- a/components/camel-ai/camel-pinecone/src/generated/resources/META-INF/org/apache/camel/component/pinecone/pinecone.json
+++ b/components/camel-ai/camel-pinecone/src/generated/resources/META-INF/org/apache/camel/component/pinecone/pinecone.json
@@ -50,7 +50,11 @@
"CamelPineconeCollectionCloud": { "index": 9, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "enum": [ "aws", "gcp", "azure" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Collection Cloud Vendor", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#COLLECTION_CLOUD" },
"CamelPineconeCollectionCloudRegion": { "index": 10, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "enum": [ "aws", "gcp", "azure" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Collection Cloud Vendor Region", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#COLLECTION_CLOUD_REGION" },
"CamelPineconeIndexId": { "index": 11, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Index Upsert Id", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#INDEX_ID" },
- "CamelPineconeQueryTopK": { "index": 12, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "Integer", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Top K", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_TOP_K" }
+ "CamelPineconeQueryTopK": { "index": 12, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "Integer", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Top K", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_TOP_K" },
+ "CamelPineconeQueryNamespace": { "index": 13, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Namespace", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_NAMESPACE" },
+ "CamelPineconeQueryFilter": { "index": 14, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Filter", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_FILTER" },
+ "CamelPineconeQueryIncludeValues": { "index": 15, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Include Values", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_INCLUDE_VALUES" },
+ "CamelPineconeQueryIncludeMetadata": { "index": 16, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "com.google.protobuf.Struct", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Query Include Metadata", "constantName": "org.apache.camel.component.pinecone.PineconeVectorDb$Headers#QUERY_INCLUDE_METADATA" }
},
"properties": {
"collection": { "index": 0, "kind": "path", "displayName": "Collection", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The collection Name" },
diff --git a/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDb.java b/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDb.java
index 2d0e87fe94d..923517193c4 100644
--- a/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDb.java
+++ b/components/camel-ai/camel-pinecone/src/main/java/org/apache/camel/component/pinecone/PineconeVectorDb.java
@@ -64,5 +64,18 @@ public class PineconeVectorDb {
@Metadata(description = "Query Top K", javaType = "Integer")
public static final String QUERY_TOP_K = "CamelPineconeQueryTopK";
+
+ @Metadata(description = "Query Namespace", javaType = "String")
+ public static final String QUERY_NAMESPACE = "CamelPineconeQueryNamespace";
+
+ @Metadata(description = "Query Filter", javaType = "String")
+ public static final String QUERY_FILTER = "CamelPineconeQueryFilter";
+
+ @Metadata(description = "Query Include Values", javaType = "boolean")
+ public static final String QUERY_INCLUDE_VALUES = "CamelPineconeQueryIncludeValues";
+
+ @Metadata(description = "Query Include Metadata", javaType = "com.google.protobuf.Struct")
+ public static final String QUERY_INCLUDE_METADATA = "CamelPineconeQueryIncludeMetadata";
+
}
}
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 5293b225dad..70f8c900a17 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
@@ -19,6 +19,7 @@ package org.apache.camel.component.pinecone;
import java.util.List;
import java.util.concurrent.ExecutorService;
+import com.google.protobuf.Struct;
import io.pinecone.clients.Index;
import io.pinecone.clients.Pinecone;
import io.pinecone.proto.UpdateResponse;
@@ -245,7 +246,16 @@ public class PineconeVectorDbProducer extends DefaultProducer {
int topK = in.getHeader(PineconeVectorDb.Headers.QUERY_TOP_K, Integer.class);
Index index = this.client.getIndexConnection(indexName);
- QueryResponseWithUnsignedIndices result = index.queryByVector(topK, elements);
+ // Optional arguments, can be null
+ String namespace = in.getHeader(PineconeVectorDb.Headers.QUERY_NAMESPACE, String.class);
+ Struct filter = in.getHeader(PineconeVectorDb.Headers.QUERY_FILTER, Struct.class);
+ boolean includeValues = (in.getHeader(PineconeVectorDb.Headers.QUERY_INCLUDE_VALUES, Boolean.class) == null)
+ ? false : in.getHeader(PineconeVectorDb.Headers.QUERY_INCLUDE_VALUES, Boolean.class);
+ boolean includeMetadata = (in.getHeader(PineconeVectorDb.Headers.QUERY_INCLUDE_METADATA, Boolean.class) == null)
+ ? false : in.getHeader(PineconeVectorDb.Headers.QUERY_INCLUDE_METADATA, Boolean.class);
+
+ QueryResponseWithUnsignedIndices result
+ = index.queryByVector(topK, elements, namespace, filter, includeValues, includeMetadata);
populateQueryResponse(result, exchange);
}
@@ -264,7 +274,17 @@ public class PineconeVectorDbProducer extends DefaultProducer {
Index index = this.client.getIndexConnection(indexName);
String indexId = in.getHeader(PineconeVectorDb.Headers.INDEX_ID, String.class);
- QueryResponseWithUnsignedIndices result = index.queryByVectorId(topK, indexId);
+
+ // Optional arguments, can be null
+ String namespace = in.getHeader(PineconeVectorDb.Headers.QUERY_NAMESPACE, String.class);
+ Struct filter = in.getHeader(PineconeVectorDb.Headers.QUERY_FILTER, Struct.class);
+ boolean includeValues = (in.getHeader(PineconeVectorDb.Headers.QUERY_INCLUDE_VALUES, Boolean.class) == null)
+ ? false : in.getHeader(PineconeVectorDb.Headers.QUERY_INCLUDE_VALUES, Boolean.class);
+ boolean includeMetadata = (in.getHeader(PineconeVectorDb.Headers.QUERY_INCLUDE_METADATA, Boolean.class) == null)
+ ? false : in.getHeader(PineconeVectorDb.Headers.QUERY_INCLUDE_METADATA, Boolean.class);
+
+ QueryResponseWithUnsignedIndices result
+ = index.queryByVectorId(topK, indexId, namespace, filter, includeValues, includeMetadata);
populateQueryResponse(result, exchange);
}
diff --git a/components/camel-ai/camel-pinecone/src/test/java/org/apache/camel/component/pinecone/it/PineconeComponentIT.java b/components/camel-ai/camel-pinecone/src/test/java/org/apache/camel/component/pinecone/it/PineconeComponentIT.java
index 47de8aeb71e..2907e9ef081 100644
--- a/components/camel-ai/camel-pinecone/src/test/java/org/apache/camel/component/pinecone/it/PineconeComponentIT.java
+++ b/components/camel-ai/camel-pinecone/src/test/java/org/apache/camel/component/pinecone/it/PineconeComponentIT.java
@@ -111,6 +111,30 @@ public class PineconeComponentIT extends CamelTestSupport {
assertThat(!result.getMessage().getBody(QueryResponseWithUnsignedIndices.class).getMatchesList().isEmpty());
}
+ @Test
+ @Order(4)
+ public void queryByVectorExtended() {
+
+ 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)
+ .withBody(
+ elements)
+ .withHeader(PineconeVectorDb.Headers.INDEX_NAME, "test-serverless-index")
+ .withHeader(PineconeVectorDb.Headers.QUERY_TOP_K, 3)
+ .withHeader(PineconeVectorDb.Headers.QUERY_NAMESPACE, "defaultNamespace")
+ .withHeader(PineconeVectorDb.Headers.QUERY_FILTER, "subject\": {\"$eq\": \"marine\"}")
+ .withHeader(PineconeVectorDb.Headers.QUERY_INCLUDE_VALUES, true)
+ .withHeader(PineconeVectorDb.Headers.QUERY_INCLUDE_METADATA, true)
+
+ .request(Exchange.class);
+
+ assertThat(result).isNotNull();
+ assertThat(result.getException()).isNull();
+ assertThat(!result.getMessage().getBody(QueryResponseWithUnsignedIndices.class).getMatchesList().isEmpty());
+ }
+
@Test
@Order(5)
public void queryById() {
diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/PineconeVectorDbEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/PineconeVectorDbEndpointBuilderFactory.java
index a31b50da267..8ef9071c926 100644
--- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/PineconeVectorDbEndpointBuilderFactory.java
+++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/PineconeVectorDbEndpointBuilderFactory.java
@@ -502,6 +502,54 @@ public interface PineconeVectorDbEndpointBuilderFactory {
public String pineconeQueryTopK() {
return "CamelPineconeQueryTopK";
}
+ /**
+ * Query Namespace.
+ *
+ * The option is a: {@code String} type.
+ *
+ * Group: producer
+ *
+ * @return the name of the header {@code PineconeQueryNamespace}.
+ */
+ public String pineconeQueryNamespace() {
+ return "CamelPineconeQueryNamespace";
+ }
+ /**
+ * Query Filter.
+ *
+ * The option is a: {@code String} type.
+ *
+ * Group: producer
+ *
+ * @return the name of the header {@code PineconeQueryFilter}.
+ */
+ public String pineconeQueryFilter() {
+ return "CamelPineconeQueryFilter";
+ }
+ /**
+ * Query Include Values.
+ *
+ * The option is a: {@code boolean} type.
+ *
+ * Group: producer
+ *
+ * @return the name of the header {@code PineconeQueryIncludeValues}.
+ */
+ public String pineconeQueryIncludeValues() {
+ return "CamelPineconeQueryIncludeValues";
+ }
+ /**
+ * Query Include Metadata.
+ *
+ * The option is a: {@code com.google.protobuf.Struct} type.
+ *
+ * Group: producer
+ *
+ * @return the name of the header {@code PineconeQueryIncludeMetadata}.
+ */
+ public String pineconeQueryIncludeMetadata() {
+ return "CamelPineconeQueryIncludeMetadata";
+ }
}
static PineconeVectorDbEndpointBuilder endpointBuilder(String componentName, String path) {
class PineconeVectorDbEndpointBuilderImpl extends AbstractEndpointBuilder implements PineconeVectorDbEndpointBuilder, AdvancedPineconeVectorDbEndpointBuilder {