cpoerschke commented on code in PR #2809:
URL: https://github.com/apache/solr/pull/2809#discussion_r1832784911


##########
solr/modules/llm/src/java/org/apache/solr/llm/embedding/SolrEmbeddingModel.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.embedding;
+
+import dev.langchain4j.data.embedding.Embedding;
+import dev.langchain4j.model.embedding.DimensionAwareEmbeddingModel;
+import dev.langchain4j.model.embedding.EmbeddingModel;
+import java.time.Duration;
+import java.util.Map;
+import java.util.Objects;
+import org.apache.lucene.util.Accountable;
+import org.apache.lucene.util.RamUsageEstimator;
+import org.apache.solr.llm.store.EmbeddingModelException;
+
+public class SolrEmbeddingModel implements Accountable {
+  private static final long BASE_RAM_BYTES =
+      RamUsageEstimator.shallowSizeOfInstance(SolrEmbeddingModel.class);
+  public static final String TIMEOUT_PARAM = "timeout";
+  public static final String LOG_REQUESTS_PARAM = "logRequests";
+  public static final String LOG_RESPONSES_PARAM = "logResponses";
+  public static final String MAX_SEGMENTS_PER_BATCH_PARAM = 
"maxSegmentsPerBatch";
+  public static final String MAX_RETRIES_PARAM = "maxRetries";
+
+  protected final String name;
+  private final Map<String, Object> params;
+  private EmbeddingModel embedder;
+  private Integer hashCode;
+
+  public static SolrEmbeddingModel getInstance(
+      String className, String name, Map<String, Object> params) throws 
EmbeddingModelException {
+    try {
+      EmbeddingModel embedder;
+      Class<?> modelClass = Class.forName(className);
+      var builder = modelClass.getMethod("builder").invoke(null);
+      if (params != null) {
+        for (String paramName : params.keySet()) {
+          switch (paramName) {
+            case TIMEOUT_PARAM:
+              Duration timeOut = Duration.ofSeconds((Long) 
params.get(paramName));
+              builder.getClass().getMethod(paramName, 
Duration.class).invoke(builder, timeOut);
+              break;
+            case LOG_REQUESTS_PARAM:
+              builder
+                  .getClass()
+                  .getMethod(paramName, Boolean.class)
+                  .invoke(builder, params.get(paramName));
+              break;
+            case LOG_RESPONSES_PARAM:
+              builder
+                  .getClass()
+                  .getMethod(paramName, Boolean.class)
+                  .invoke(builder, params.get(paramName));
+              break;

Review Comment:
   2/2 This could be removed -- e.g. 
https://github.com/SeaseLtd/solr/pull/5/commits/62a134e3e62b11af70dbcbc8c4bff2d62f86f9e4
 -- if we make the `default` handling more suitable for use with non-String 
parameters also -- e.g. 
https://github.com/SeaseLtd/solr/pull/5/commits/465383748b0f35847cbebbd024bd082cc8e23ab5
 adds a non-String parameter to the dummy model.
   



-- 
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