Skip to content
Open
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@
package org.apache.camel.component.langchain4j.embeddings;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import dev.langchain4j.model.embedding.onnx.allminilml6v2.AllMiniLmL6V2EmbeddingModel;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.data.model.WeaviateObject;
import io.weaviate.client.v1.schema.model.WeaviateClass;
import io.weaviate.client6.v1.api.collections.WeaviateObject;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.qdrant.QdrantAction;
import org.apache.camel.component.weaviate.WeaviateVectorDb;
import org.apache.camel.component.weaviate.WeaviateVectorDbAction;
import org.apache.camel.component.weaviate.WeaviateVectorDbComponent;
Expand All @@ -51,7 +48,7 @@
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class LangChain4jEmbeddingsComponentWeaviateTargetIT extends CamelTestSupport {
public static final long POINT_ID = 8;
public static final String WEAVIATE_URI = "weaviate:embeddings";
public static final String WEAVIATE_URI = "weaviate:Embeddings";
private static String CREATEID = null;

@RegisterExtension
Expand All @@ -63,7 +60,9 @@ protected CamelContext createCamelContext() throws Exception {

var qc = context.getComponent(WeaviateVectorDb.SCHEME, WeaviateVectorDbComponent.class);
qc.getConfiguration().setScheme("http");
qc.getConfiguration().setHost(WEAVIATE.getWeaviateEndpointUrl());
qc.getConfiguration().setHost(WEAVIATE.getWeaviateHost() + ":" + WEAVIATE.getWeaviatePort());
qc.getConfiguration().setGrpcHost(WEAVIATE.getWeaviateHost());
qc.getConfiguration().setGrpcPort(WEAVIATE.getWeaviateGrpcPort());
context.getRegistry().bind("embedding-model", new AllMiniLmL6V2EmbeddingModel());

return context;
Expand All @@ -73,9 +72,7 @@ protected CamelContext createCamelContext() throws Exception {
@Order(1)
public void createCollection() {
Exchange result = fluentTemplate.to(WEAVIATE_URI)
.withHeader(WeaviateVectorDbHeaders.ACTION, QdrantAction.CREATE_COLLECTION)
.withBody(
WeaviateClass.builder().className("embeddings").build())
.withHeader(WeaviateVectorDbHeaders.ACTION, WeaviateVectorDbAction.CREATE_COLLECTION)
.request(Exchange.class);

assertThat(result).isNotNull();
Expand All @@ -92,14 +89,14 @@ public void create() {
Exchange result = fluentTemplate.to("direct:in")
.withHeader(WeaviateVectorDbHeaders.ACTION, WeaviateVectorDbAction.CREATE)
.withBody("hi")
.withHeader(WeaviateVectorDbHeaders.COLLECTION_NAME, "embeddings")
.withHeader(WeaviateVectorDbHeaders.COLLECTION_NAME, "Embeddings")
.withHeader(WeaviateVectorDbHeaders.PROPERTIES, map)
.request(Exchange.class);

assertThat(result).isNotNull();
assertThat(result.getException()).isNull();
Result<WeaviateObject> res = (Result<WeaviateObject>) result.getIn().getBody();
CREATEID = res.getResult().getId();
WeaviateObject<Map<String, Object>> res = (WeaviateObject<Map<String, Object>>) result.getIn().getBody();
CREATEID = res.uuid();
}

@Test
Expand All @@ -113,7 +110,7 @@ public void updateById() {
.withHeader(WeaviateVectorDbHeaders.ACTION, WeaviateVectorDbAction.UPDATE_BY_ID)
.withBody("hi")
.withHeader(WeaviateVectorDbHeaders.INDEX_ID, CREATEID)
.withHeader(WeaviateVectorDbHeaders.COLLECTION_NAME, "embeddings")
.withHeader(WeaviateVectorDbHeaders.COLLECTION_NAME, "Embeddings")
.withHeader(WeaviateVectorDbHeaders.PROPERTIES, map)
.request(Exchange.class);

Expand All @@ -131,17 +128,16 @@ public void querybyid() {

assertThat(result).isNotNull();
assertThat(result.getException()).isNull();
Result<WeaviateObject> res = (Result<WeaviateObject>) result.getIn().getBody();
assertThat(res.hasErrors()).isFalse();

List<WeaviateObject> list = (List) res.getResult();
for (WeaviateObject wo : list) {
Optional<WeaviateObject<Map<String, Object>>> res
= (Optional<WeaviateObject<Map<String, Object>>>) result.getIn().getBody();
assertThat(res).isPresent();

Map<String, Object> map = wo.getProperties();
assertThat(map).containsKey("sky");
assertThat(map).containsKey("age");
assertThat(map).containsKey("dog");
}
WeaviateObject<Map<String, Object>> wo = res.get();
Map<String, Object> props = wo.properties();
assertThat(props).containsKey("sky");
assertThat(props).containsKey("age");
assertThat(props).containsKey("dog");
}

@Test
Expand Down
6 changes: 4 additions & 2 deletions components/camel-ai/camel-weaviate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<camel.surefire.parallel>true</camel.surefire.parallel>
<camel.surefire.parallel.factor>4</camel.surefire.parallel.factor>

<!-- Milvus is not available on these platforms -->
<!-- Weaviate is not available on these platforms -->
<skipITs.s390x>true</skipITs.s390x>
<skipTests.s390x>true</skipTests.s390x>
</properties>
Expand All @@ -52,10 +52,12 @@
<version>${langchain4j-version}</version>
</dependency>

<!-- classifier=all is required: without it, gRPC's ServiceLoader breaks in fat JARs -->
<dependency>
<groupId>io.weaviate</groupId>
<artifactId>client</artifactId>
<artifactId>client6</artifactId>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: The all classifier produces a shaded/uber JAR that bundles gRPC, Netty, protobuf, etc. In a large framework like Camel where many components share these transitive dependencies, is there a risk of classpath conflicts? The comment explains why it's needed (gRPC ServiceLoader), but it would be good to confirm no version collisions occur with other components.

<version>${weaviate-client-version}</version>
<classifier>all</classifier>
</dependency>

<!-- test infra -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "autowiredenabled":
case "autowiredEnabled": target.setAutowiredEnabled(property(camelContext, boolean.class, value)); return true;
case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.weaviate.WeaviateVectorDbConfiguration.class, value)); return true;
case "grpchost":
case "grpcHost": getOrCreateConfiguration(target).setGrpcHost(property(camelContext, java.lang.String.class, value)); return true;
case "grpcport":
case "grpcPort": getOrCreateConfiguration(target).setGrpcPort(property(camelContext, java.lang.Integer.class, value)); return true;
case "host": getOrCreateConfiguration(target).setHost(property(camelContext, java.lang.String.class, value)); return true;
case "lazystartproducer":
case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
Expand All @@ -57,6 +61,10 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
case "autowiredenabled":
case "autowiredEnabled": return boolean.class;
case "configuration": return org.apache.camel.component.weaviate.WeaviateVectorDbConfiguration.class;
case "grpchost":
case "grpcHost": return java.lang.String.class;
case "grpcport":
case "grpcPort": return java.lang.Integer.class;
case "host": return java.lang.String.class;
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
Expand All @@ -80,6 +88,10 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "autowiredenabled":
case "autowiredEnabled": return target.isAutowiredEnabled();
case "configuration": return target.getConfiguration();
case "grpchost":
case "grpcHost": return getOrCreateConfiguration(target).getGrpcHost();
case "grpcport":
case "grpcPort": return getOrCreateConfiguration(target).getGrpcPort();
case "host": return getOrCreateConfiguration(target).getHost();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
switch (ignoreCase ? name.toLowerCase() : name) {
case "apikey":
case "apiKey": target.setApiKey(property(camelContext, java.lang.String.class, value)); return true;
case "client": target.setClient(property(camelContext, io.weaviate.client.WeaviateClient.class, value)); return true;
case "client": target.setClient(property(camelContext, io.weaviate.client6.v1.api.WeaviateClient.class, value)); return true;
case "grpchost":
case "grpcHost": target.setGrpcHost(property(camelContext, java.lang.String.class, value)); return true;
case "grpcport":
case "grpcPort": target.setGrpcPort(property(camelContext, java.lang.Integer.class, value)); return true;
case "host": target.setHost(property(camelContext, java.lang.String.class, value)); return true;
case "proxyhost":
case "proxyHost": target.setProxyHost(property(camelContext, java.lang.String.class, value)); return true;
Expand All @@ -43,7 +47,11 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
case "apikey":
case "apiKey": return java.lang.String.class;
case "client": return io.weaviate.client.WeaviateClient.class;
case "client": return io.weaviate.client6.v1.api.WeaviateClient.class;
case "grpchost":
case "grpcHost": return java.lang.String.class;
case "grpcport":
case "grpcPort": return java.lang.Integer.class;
case "host": return java.lang.String.class;
case "proxyhost":
case "proxyHost": return java.lang.String.class;
Expand All @@ -63,6 +71,10 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "apikey":
case "apiKey": return target.getApiKey();
case "client": return target.getClient();
case "grpchost":
case "grpcHost": return target.getGrpcHost();
case "grpcport":
case "grpcPort": return target.getGrpcPort();
case "host": return target.getHost();
case "proxyhost":
case "proxyHost": return target.getProxyHost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
switch (ignoreCase ? name.toLowerCase() : name) {
case "apikey":
case "apiKey": target.getConfiguration().setApiKey(property(camelContext, java.lang.String.class, value)); return true;
case "grpchost":
case "grpcHost": target.getConfiguration().setGrpcHost(property(camelContext, java.lang.String.class, value)); return true;
case "grpcport":
case "grpcPort": target.getConfiguration().setGrpcPort(property(camelContext, java.lang.Integer.class, value)); return true;
case "host": target.getConfiguration().setHost(property(camelContext, java.lang.String.class, value)); return true;
case "lazystartproducer":
case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
Expand All @@ -44,6 +48,10 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
case "apikey":
case "apiKey": return java.lang.String.class;
case "grpchost":
case "grpcHost": return java.lang.String.class;
case "grpcport":
case "grpcPort": return java.lang.Integer.class;
case "host": return java.lang.String.class;
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
Expand All @@ -64,6 +72,10 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
case "apikey":
case "apiKey": return target.getConfiguration().getApiKey();
case "grpchost":
case "grpcHost": return target.getConfiguration().getGrpcHost();
case "grpcport":
case "grpcPort": return target.getConfiguration().getGrpcPort();
case "host": return target.getConfiguration().getHost();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public class WeaviateVectorDbEndpointUriFactory extends org.apache.camel.support
private static final Set<String> ENDPOINT_IDENTITY_PROPERTY_NAMES;
private static final Map<String, String> MULTI_VALUE_PREFIXES;
static {
Set<String> props = new HashSet<>(8);
Set<String> props = new HashSet<>(10);
props.add("apiKey");
props.add("collection");
props.add("grpcHost");
props.add("grpcPort");
props.add("host");
props.add("lazyStartProducer");
props.add("proxyHost");
Expand Down
Loading