orpiske commented on code in PR #17697: URL: https://github.com/apache/camel/pull/17697#discussion_r2034533256
########## components/camel-ai/camel-weaviate/src/main/java/org/apache/camel/component/weaviate/WeaviateVectorDbProducer.java: ########## @@ -0,0 +1,282 @@ +/* + * 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.weaviate; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutorService; + +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.data.model.WeaviateObject; +import io.weaviate.client.v1.graphql.model.GraphQLResponse; +import io.weaviate.client.v1.graphql.query.argument.NearVectorArgument; +import io.weaviate.client.v1.graphql.query.builder.GetBuilder; +import io.weaviate.client.v1.graphql.query.fields.Field; +import io.weaviate.client.v1.graphql.query.fields.Fields; +import io.weaviate.client.v1.schema.model.WeaviateClass; +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.NoSuchHeaderException; +import org.apache.camel.support.DefaultProducer; + +public class WeaviateVectorDbProducer extends DefaultProducer { + private WeaviateClient client; + private ExecutorService executor; + + public WeaviateVectorDbProducer(WeaviateVectorDbEndpoint endpoint) { + super(endpoint); + } + + @Override + public WeaviateVectorDbEndpoint getEndpoint() { + return (WeaviateVectorDbEndpoint) super.getEndpoint(); + } + + @Override + public void doStart() throws Exception { + super.doStart(); + + this.client = getEndpoint().getClient(); + } + + @Override + public void process(Exchange exchange) { + final Message in = exchange.getMessage(); + final WeaviateVectorDbAction action = in.getHeader(WeaviateVectorDb.Headers.ACTION, WeaviateVectorDbAction.class); + + try { + if (action == null) { + throw new NoSuchHeaderException("The action is a required header", exchange, WeaviateVectorDb.Headers.ACTION); + } Review Comment: A bit of nitpick on my part, but you could do `ExchangeHelper.getMandatoryHeader()` and cut a bit of the code. ########## components/camel-ai/camel-weaviate/src/test/java/org/apache/camel/component/weaviate/WeaviateComponentConfigurationTest.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.weaviate; + +import java.io.IOException; +import java.util.Map; +import java.util.Properties; + +import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.camel.test.junit5.TestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class WeaviateComponentConfigurationTest extends CamelTestSupport { + + public Properties loadWeaviatePropertiesFile() throws IOException { + final String fileName = "weaviate.properties"; + return TestSupport.loadExternalProperties(WeaviateComponentConfigurationTest.class.getClassLoader(), fileName); + } + + @Test + void createEndpointWithMinimalConfiguration() throws Exception { + WeaviateVectorDbComponent component = context.getComponent("weaviate", WeaviateVectorDbComponent.class); + WeaviateVectorDbEndpoint endpoint = (WeaviateVectorDbEndpoint) component + .createEndpoint( + "pinecone://test-collection?host=localhost:7979&scheme=http&proxyHost=localhost&proxyPort=7777&proxyScheme=https&apiKey=foobar123"); Review Comment: I'm a bit lost here ... shouldn't we use `weviate` instead of `pinecone` ? ########## components/camel-ai/camel-weaviate/src/main/java/org/apache/camel/component/weaviate/WeaviateVectorDbProducer.java: ########## @@ -0,0 +1,282 @@ +/* + * 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.weaviate; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutorService; + +import io.weaviate.client.WeaviateClient; +import io.weaviate.client.base.Result; +import io.weaviate.client.v1.data.model.WeaviateObject; +import io.weaviate.client.v1.graphql.model.GraphQLResponse; +import io.weaviate.client.v1.graphql.query.argument.NearVectorArgument; +import io.weaviate.client.v1.graphql.query.builder.GetBuilder; +import io.weaviate.client.v1.graphql.query.fields.Field; +import io.weaviate.client.v1.graphql.query.fields.Fields; +import io.weaviate.client.v1.schema.model.WeaviateClass; +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.NoSuchHeaderException; +import org.apache.camel.support.DefaultProducer; + +public class WeaviateVectorDbProducer extends DefaultProducer { + private WeaviateClient client; + private ExecutorService executor; + + public WeaviateVectorDbProducer(WeaviateVectorDbEndpoint endpoint) { + super(endpoint); + } + + @Override + public WeaviateVectorDbEndpoint getEndpoint() { + return (WeaviateVectorDbEndpoint) super.getEndpoint(); + } + + @Override + public void doStart() throws Exception { + super.doStart(); + + this.client = getEndpoint().getClient(); + } + + @Override + public void process(Exchange exchange) { + final Message in = exchange.getMessage(); + final WeaviateVectorDbAction action = in.getHeader(WeaviateVectorDb.Headers.ACTION, WeaviateVectorDbAction.class); + + try { + if (action == null) { + throw new NoSuchHeaderException("The action is a required header", exchange, WeaviateVectorDb.Headers.ACTION); + } + + switch (action) { + case CREATE_COLLECTION: + createCollection(exchange); + break; + case CREATE: + create(exchange); + break; + case UPDATE_BY_ID: + updateById(exchange); + break; + case DELETE_BY_ID: + deleteById(exchange); + break; + case DELETE_COLLECTION: + deleteCollection(exchange); + break; + case QUERY: + query(exchange); + break; + case QUERY_BY_ID: + queryById(exchange); + break; + default: + throw new UnsupportedOperationException("Unsupported action: " + action.name()); + } + } catch (Exception e) { + exchange.setException(e); + } + } + + // *************************************** + // + // Actions + // + // *************************************** + + private void createCollection(Exchange exchange) throws Exception { + final Message in = exchange.getMessage(); + String collectionName = in.getHeader(WeaviateVectorDb.Headers.COLLECTION_NAME, String.class); Review Comment: Looks like a mandatory header. I guess we should check it as well. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
