dsmiley commented on code in PR #3151:
URL: https://github.com/apache/solr/pull/3151#discussion_r1944799990


##########
solr/modules/llm/src/java/org/apache/solr/llm/textvectorisation/update/processor/TextToVectorUpdateProcessorFactory.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.solr.llm.textvectorisation.update.processor;
+
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.RequiredSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.llm.textvectorisation.model.SolrTextToVectorModel;
+import 
org.apache.solr.llm.textvectorisation.store.rest.ManagedTextToVectorModelStore;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.schema.DenseVectorField;
+import org.apache.solr.schema.FieldType;
+import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.schema.SchemaField;
+import org.apache.solr.update.processor.UpdateRequestProcessor;
+import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
+
+/**
+ * This class implements an UpdateProcessorFactory for the Text To Vector 
Update Processor.
+ */
+public class TextToVectorUpdateProcessorFactory extends 
UpdateRequestProcessorFactory {
+    private static final String INPUT_FIELD_PARAM = "inputField";
+    private static final String OUTPUT_FIELD_PARAM = "outputField";
+    private static final String MODEL_NAME = "model";
+
+    private String inputField;
+    private String outputField;
+    private String modelName;
+    private SolrParams params;
+
+
+    @Override
+    public void init(final NamedList<?> args) {
+        params = args.toSolrParams();
+        RequiredSolrParams required = params.required();
+        inputField = required.get(INPUT_FIELD_PARAM);
+        outputField = required.get(OUTPUT_FIELD_PARAM);
+        modelName = required.get(MODEL_NAME);
+    }
+
+    @Override
+    public UpdateRequestProcessor getInstance(SolrQueryRequest req, 
SolrQueryResponse rsp, UpdateRequestProcessor next) {
+        IndexSchema latestSchema = req.getCore().getLatestSchema();
+        if(!latestSchema.hasExplicitField(inputField)){
+            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, 
"undefined field: \"" + inputField + "\"");
+        }
+        if(!latestSchema.hasExplicitField(outputField)){
+            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, 
"undefined field: \"" + outputField + "\"");
+        }
+       
+        final SchemaField outputFieldSchema = 
latestSchema.getField(outputField);
+        assertIsDenseVectorField(outputFieldSchema);
+
+        ManagedTextToVectorModelStore modelStore = 
ManagedTextToVectorModelStore.getManagedModelStore(req.getCore());
+        SolrTextToVectorModel textToVector = modelStore.getModel(modelName);

Review Comment:
   I presume looking up the model is fast/cached if it already exists?



##########
solr/modules/llm/src/test/org/apache/solr/llm/textvectorisation/search/TextToVectorQParserTest.java:
##########
@@ -29,6 +30,11 @@ public static void init() throws Exception {
     loadModel("dummy-model.json");
   }
 
+  @AfterClass
+  public static void cleanup() throws Exception {
+    afterTest();
+  }

Review Comment:
   weird; why?  Weird to see a test cleanup also be a suite cleanup.
   (same for TestModelManager)



##########
solr/modules/llm/src/test/org/apache/solr/llm/textvectorisation/update/processor/TextToVectorUpdateProcessorFactoryTest.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.solr.llm.textvectorisation.update.processor;
+
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.MultiMapSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.llm.TestLlmBase;
+import org.apache.solr.request.SolrQueryRequestBase;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class TextToVectorUpdateProcessorFactoryTest extends TestLlmBase {
+  private TextToVectorUpdateProcessorFactory factoryToTest =
+      new TextToVectorUpdateProcessorFactory();
+  private NamedList<String> args = new NamedList<>();
+  
+  @BeforeClass
+  public static void initArgs() throws Exception {
+    setupTest("solrconfig-llm.xml", "schema.xml", false, false);
+  }
+
+  @AfterClass
+  public static void after() throws Exception {
+    afterTest();
+  }
+
+  @Test
+  public void init_fullArgs_shouldInitAllParams() {
+    args.add("inputField", "_text_");
+    args.add("outputField", "vector");
+    args.add("model", "model1");
+    factoryToTest.init(args);
+
+    assertEquals("_text_", factoryToTest.getInputField());
+    assertEquals("vector", factoryToTest.getOutputField());
+    assertEquals("model1", factoryToTest.getModelName());
+  }
+
+  @Test
+  public void init_nullInputField_shouldThrowExceptionWithDetailedMessage() {
+    args.add("outputField", "vector");
+    args.add("model", "model1");
+    
+    SolrException e = assertThrows(SolrException.class, () -> 
factoryToTest.init(args));
+    assertEquals("Missing required parameter: inputField", e.getMessage());
+  }
+
+  @Test
+  public void init_nullOutputField_shouldThrowExceptionWithDetailedMessage() {
+    args.add("inputField", "_text_");
+    args.add("model", "model1");
+    
+    SolrException e = assertThrows(SolrException.class, () -> 
factoryToTest.init(args));
+    assertEquals("Missing required parameter: outputField", e.getMessage());
+  }
+  
+  @Test
+  public void init_nullModel_shouldThrowExceptionWithDetailedMessage() {
+    args.add("inputField", "_text_");
+    args.add("outputField", "vector");
+    
+    SolrException e = assertThrows(SolrException.class, () -> 
factoryToTest.init(args));
+    assertEquals("Missing required parameter: model", e.getMessage());
+  }
+
+  /* Following tests depends on a real solr schema */
+  @Test
+  public void 
init_notExistentOutputField_shouldThrowExceptionWithDetailedMessage() throws 
Exception {
+    args.add("inputField", "_text_");
+    args.add("outputField", "notExistentOutput");
+    args.add("model", "model1");
+
+    Map<String, String[]> params = new HashMap<>();
+    MultiMapSolrParams mmparams = new MultiMapSolrParams(params);

Review Comment:
   This is more complex than needed; just create a ModifiableSolrParams (one 
line).  Soon after I merge a PR up for review, you would do `SolrParams.of()`.



##########
solr/modules/llm/src/test/org/apache/solr/llm/textvectorisation/update/processor/TextToVectorUpdateProcessorFactoryTest.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.solr.llm.textvectorisation.update.processor;
+
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.MultiMapSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.llm.TestLlmBase;
+import org.apache.solr.request.SolrQueryRequestBase;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class TextToVectorUpdateProcessorFactoryTest extends TestLlmBase {
+  private TextToVectorUpdateProcessorFactory factoryToTest =
+      new TextToVectorUpdateProcessorFactory();
+  private NamedList<String> args = new NamedList<>();

Review Comment:
   I think it's awkward to have this as a field, as you need to tend to its 
lifecycle by cleaning.  It's a lightweight trivial object so why not have the 
test classes initialize them?



-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to