Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"CamelQdrantWithPayload": { "index": 6, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": "true", "description": "Include Payload.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#INCLUDE_PAYLOAD" },
"CamelQdrantWithVectors": { "index": 7, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": "false", "description": "Include Vectors.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#INCLUDE_VECTORS" },
"CamelQdrantSize": { "index": 8, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The number of elements.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#SIZE" },
"CamelQdrantPointId": { "index": 9, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The point id to use for operation.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#POINT_ID" }
"CamelQdrantPointId": { "index": 9, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The point id to use for operation.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#POINT_ID" },
"CamelQdrantMaxResults": { "index": 10, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The maximum number of results to return from a similarity search.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#MAX_RESULTS" }
},
"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" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"CamelQdrantWithPayload": { "index": 6, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": "true", "description": "Include Payload.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#INCLUDE_PAYLOAD" },
"CamelQdrantWithVectors": { "index": 7, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "boolean", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": "false", "description": "Include Vectors.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#INCLUDE_VECTORS" },
"CamelQdrantSize": { "index": 8, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The number of elements.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#SIZE" },
"CamelQdrantPointId": { "index": 9, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The point id to use for operation.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#POINT_ID" }
"CamelQdrantPointId": { "index": 9, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The point id to use for operation.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#POINT_ID" },
"CamelQdrantMaxResults": { "index": 10, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "int", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The maximum number of results to return from a similarity search.", "constantName": "org.apache.camel.component.qdrant.QdrantHeaders#MAX_RESULTS" }
},
"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" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ private QdrantHeaders() {

@Metadata(description = "The point id to use for operation.", javaType = "int")
public static final String POINT_ID = "CamelQdrantPointId";

@Metadata(description = "The maximum number of results to return from a similarity search.", javaType = "int")
public static final String MAX_RESULTS = "CamelQdrantMaxResults";
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ private boolean similaritySearch(Exchange exchange, AsyncCallback callback) thro
}

ObjectHelper.notNull(vectors, "vectors");
final int maxResults = getEndpoint().getConfiguration().getMaxResults();
final int maxResults = in.getHeader(
QdrantHeaders.MAX_RESULTS,
getEndpoint().getConfiguration().getMaxResults(),
int.class);
final Common.Filter filter = getEndpoint().getConfiguration().getFilter();
final Duration timeout = getEndpoint().getConfiguration().getTimeout();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.qdrant.rag;

import io.qdrant.client.grpc.Collections;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.qdrant.QdrantAction;
import org.apache.camel.component.qdrant.QdrantHeaders;

public class RAGCreateCollection implements Processor {

private String size = "768";
private String distance = "Cosine";

@Override
public void process(Exchange exchange) throws Exception {
int vectorSize = Integer.parseInt(size);

Collections.Distance distanceEnum = Collections.Distance.valueOf(distance);

Collections.VectorParams vectorParams = Collections.VectorParams.newBuilder()
.setSize(vectorSize)
.setDistance(distanceEnum)
.build();

exchange.getIn().setHeader(QdrantHeaders.ACTION, QdrantAction.CREATE_COLLECTION);
exchange.getIn().setBody(vectorParams);
}

public String getSize() {
return size;
}

public void setSize(String size) {
this.size = size;
}

public String getDistance() {
return distance;
}

public void setDistance(String distance) {
this.distance = distance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.qdrant.rag;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import io.qdrant.client.grpc.Points;
import org.apache.camel.Exchange;

public class RAGResultExtractor {

private String payloadKey = "content";

@SuppressWarnings("unchecked")
public List<Map<String, Object>> extract(Exchange exchange) {
List<Points.ScoredPoint> results = exchange.getIn().getBody(List.class);
List<Map<String, Object>> extracted = new ArrayList<>();
int rank = 1;
for (Points.ScoredPoint point : results) {
Map<String, Object> item = new LinkedHashMap<>();
item.put("rank", rank++);
item.put("content", point.getPayloadMap().get(payloadKey).getStringValue());
item.put("score", point.getScore());
extracted.add(item);
}
return extracted;
}

public String getPayloadKey() {
return payloadKey;
}

public void setPayloadKey(String payloadKey) {
this.payloadKey = payloadKey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.qdrant.rag;

import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

import io.qdrant.client.PointIdFactory;
import io.qdrant.client.ValueFactory;
import io.qdrant.client.VectorsFactory;
import io.qdrant.client.grpc.Points;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.qdrant.QdrantAction;
import org.apache.camel.component.qdrant.QdrantHeaders;

public class RAGUpsert implements Processor {

private String payloadKey = "content";
private String textVariable = "text";
private final AtomicLong pointIdCounter = new AtomicLong(1);

@SuppressWarnings("unchecked")
@Override
public void process(Exchange exchange) throws Exception {
List<Float> embedding = exchange.getIn().getBody(List.class);
String text = exchange.getVariable(textVariable, String.class);

Points.PointStruct point = Points.PointStruct.newBuilder()
.setId(PointIdFactory.id(pointIdCounter.getAndIncrement()))
.setVectors(VectorsFactory.vectors(embedding))
.putAllPayload(Map.of(payloadKey, ValueFactory.value(text)))
.build();

exchange.getIn().setBody(List.of(point));
exchange.getIn().setHeader(QdrantHeaders.ACTION, QdrantAction.UPSERT);
}

public String getPayloadKey() {
return payloadKey;
}

public void setPayloadKey(String payloadKey) {
this.payloadKey = payloadKey;
}

public String getTextVariable() {
return textVariable;
}

public void setTextVariable(String textVariable) {
this.textVariable = textVariable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
import io.qdrant.client.grpc.Collections;
import io.qdrant.client.grpc.Points;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.qdrant.QdrantAction;
import org.apache.camel.component.qdrant.QdrantActionException;
import org.apache.camel.component.qdrant.QdrantHeaders;
import org.apache.camel.component.qdrant.QdrantTestSupport;
import org.apache.camel.component.qdrant.rag.RAGCreateCollection;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand All @@ -45,6 +47,21 @@
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class QdrantComponentIT extends QdrantTestSupport {

@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
RAGCreateCollection createCollectionProcessor = new RAGCreateCollection();
createCollectionProcessor.setSize("2");

from("direct:createCollection")
.process(createCollectionProcessor)
.to("qdrant:testComponent");
}
};
}

@Test
@Order(0)
void collectionInfoNonExistent() {
Expand All @@ -69,12 +86,7 @@ void collectionInfoNonExistent() {
@Test
@Order(1)
void createCollection() {
Exchange result = fluentTemplate.to("qdrant:testComponent")
.withHeader(QdrantHeaders.ACTION, QdrantAction.CREATE_COLLECTION)
.withBody(
Collections.VectorParams.newBuilder()
.setSize(2)
.setDistance(Collections.Distance.Cosine).build())
Exchange result = fluentTemplate.to("direct:createCollection")
.request(Exchange.class);

assertThat(result).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import io.qdrant.client.grpc.Collections;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.qdrant.QdrantAction;
import org.apache.camel.component.qdrant.QdrantActionException;
import org.apache.camel.component.qdrant.QdrantEndpoint;
import org.apache.camel.component.qdrant.QdrantHeaders;
import org.apache.camel.component.qdrant.QdrantTestSupport;
import org.apache.camel.component.qdrant.rag.RAGCreateCollection;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand All @@ -38,15 +40,25 @@ class QdrantDeleteCollectionIT extends QdrantTestSupport {
@EndpointInject("qdrant:collectionForDeletion")
QdrantEndpoint qdrantEndpoint;

@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
RAGCreateCollection createCollectionProcessor = new RAGCreateCollection();
createCollectionProcessor.setSize("2");

from("direct:createCollection")
.process(createCollectionProcessor)
.to("qdrant:collectionForDeletion");
}
};
}

@Test
@Order(1)
void createCollection() {
Exchange result = fluentTemplate.to(qdrantEndpoint)
.withHeader(QdrantHeaders.ACTION, QdrantAction.CREATE_COLLECTION)
.withBody(
Collections.VectorParams.newBuilder()
.setSize(2)
.setDistance(Collections.Distance.Cosine).build())
Exchange result = fluentTemplate.to("direct:createCollection")
.request(Exchange.class);

assertThat(result).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
import io.qdrant.client.PointIdFactory;
import io.qdrant.client.ValueFactory;
import io.qdrant.client.VectorsFactory;
import io.qdrant.client.grpc.Collections;
import io.qdrant.client.grpc.Common;
import io.qdrant.client.grpc.Points;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.qdrant.QdrantAction;
import org.apache.camel.component.qdrant.QdrantHeaders;
import org.apache.camel.component.qdrant.QdrantTestSupport;
import org.apache.camel.component.qdrant.rag.RAGCreateCollection;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand All @@ -40,15 +41,26 @@

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class QdrantDeletePointsIT extends QdrantTestSupport {

@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
RAGCreateCollection createCollectionProcessor = new RAGCreateCollection();
createCollectionProcessor.setSize("2");

from("direct:createCollection")
.process(createCollectionProcessor)
.to("qdrant:testDelete");
}
};
}

@Test
@Order(1)
void createCollection() {
Exchange result = fluentTemplate.to("qdrant:testDelete")
.withHeader(QdrantHeaders.ACTION, QdrantAction.CREATE_COLLECTION)
.withBody(
Collections.VectorParams.newBuilder()
.setSize(2)
.setDistance(Collections.Distance.Cosine).build())
Exchange result = fluentTemplate.to("direct:createCollection")
.request(Exchange.class);

assertThat(result).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,18 @@ public String qdrantSize() {
public String qdrantPointId() {
return "CamelQdrantPointId";
}
/**
* The maximum number of results to return from a similarity search.
*
* The option is a: {@code int} type.
*
* Group: producer
*
* @return the name of the header {@code QdrantMaxResults}.
*/
public String qdrantMaxResults() {
return "CamelQdrantMaxResults";
}
}
static QdrantEndpointBuilder endpointBuilder(String componentName, String path) {
class QdrantEndpointBuilderImpl extends AbstractEndpointBuilder implements QdrantEndpointBuilder, AdvancedQdrantEndpointBuilder {
Expand Down