diff options
author | MariusArhaug <mariusarhaug@hotmail.com> | 2024-04-04 16:04:46 +0200 |
---|---|---|
committer | MariusArhaug <mariusarhaug@hotmail.com> | 2024-04-04 16:18:35 +0200 |
commit | 218205b80900f85167ec028e5cc55bbe98702dbd (patch) | |
tree | fa6d3091fae88926b5ffd289c50ab768baaba17f /config-model/src/main/java | |
parent | 626c886af679c06616a928b3ebbc5e840dd68d8e (diff) |
add significance config model registry
Diffstat (limited to 'config-model/src/main/java')
3 files changed, 85 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/component/SignificanceModelRegistry.java b/config-model/src/main/java/com/yahoo/vespa/model/container/component/SignificanceModelRegistry.java new file mode 100644 index 00000000000..fafa846d64d --- /dev/null +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/component/SignificanceModelRegistry.java @@ -0,0 +1,73 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.model.container.component; + +import com.yahoo.config.ModelReference; +import com.yahoo.config.model.deploy.DeployState; +import com.yahoo.container.bundle.BundleInstantiationSpecification; +import com.yahoo.osgi.provider.model.ComponentModel; +import com.yahoo.search.significance.config.SignificanceConfig; +import com.yahoo.text.XML; +import org.w3c.dom.Element; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import static com.yahoo.vespa.model.container.xml.ModelIdResolver.SIGNIFICANCE_MODEL; + +/** + * A registry for significance models. + * + * @author MariusArhaug + * + */ +public class SignificanceModelRegistry extends SimpleComponent implements SignificanceConfig.Producer { + + private static final String CLASS = "com.yahoo.search.significance.DefaultSignificanceModelRegistry"; + private static final String BUNDLE = "linguistics"; + + private final List<SignificanceModelConfig> configList; + + public SignificanceModelRegistry(DeployState deployState, Element spec) { + super(new ComponentModel(BundleInstantiationSpecification.fromStrings(CLASS, CLASS, BUNDLE))); + configList = new ArrayList<>(); + + for (Element modelElement : XML.getChildren(spec, "model")) { + addConfig( + modelElement.getAttribute("language"), + Model.fromXml(deployState, modelElement, Set.of(SIGNIFICANCE_MODEL)).modelReference()); + } + } + + + public void addConfig(String language, ModelReference path) { + configList.add( + new SignificanceModelConfig(language, path) + ); + } + + + @Override + public void getConfig(SignificanceConfig.Builder builder) { + builder.model( + configList.stream() + .map(config -> new SignificanceConfig.Model.Builder() + .language(config.language) + .path(config.path) + ).toList() + ); + } + + + class SignificanceModelConfig { + private final String language; + private final ModelReference path; + + public SignificanceModelConfig(String language, ModelReference path) { + this.language = language; + this.path = path; + } + + } +} + diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java index eac03531b86..400d86aa67a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java @@ -83,6 +83,7 @@ import com.yahoo.vespa.model.container.component.Handler; import com.yahoo.vespa.model.container.component.SimpleComponent; import com.yahoo.vespa.model.container.component.SystemBindingPattern; import com.yahoo.vespa.model.container.component.UserBindingPattern; +import com.yahoo.vespa.model.container.component.SignificanceModelRegistry; import com.yahoo.vespa.model.container.docproc.ContainerDocproc; import com.yahoo.vespa.model.container.docproc.DocprocChains; import com.yahoo.vespa.model.container.http.AccessControl; @@ -212,6 +213,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { addProcessing(deployState, spec, cluster, context); addSearch(deployState, spec, cluster, context); + addSignificance(deployState, spec, cluster); addDocproc(deployState, spec, cluster); addDocumentApi(deployState, spec, cluster, context); // NOTE: Must be done after addSearch @@ -767,6 +769,15 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { validateAndAddConfiguredComponents(deployState, cluster, searchElement, "renderer", ContainerModelBuilder::validateRendererElement); } + private void addSignificance(DeployState deployState, Element spec, ApplicationContainerCluster cluster) { + Element significanceElement = XML.getChild(spec, "significance"); + if (significanceElement == null) return; + + SignificanceModelRegistry significanceModelRegistry = new SignificanceModelRegistry(deployState, significanceElement); + cluster.addComponent(significanceModelRegistry); + + } + private void addModelEvaluation(Element spec, ApplicationContainerCluster cluster, ConfigModelContext context) { Element modelEvaluationElement = XML.getChild(spec, "model-evaluation"); if (modelEvaluationElement == null) return; diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ModelIdResolver.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ModelIdResolver.java index 9ff9344edcb..f9993b770e5 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ModelIdResolver.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ModelIdResolver.java @@ -25,6 +25,7 @@ public class ModelIdResolver { public static final String HF_TOKENIZER = "huggingface-tokenizer"; public static final String ONNX_MODEL = "onnx-model"; public static final String BERT_VOCAB = "bert-vocabulary"; + public static final String SIGNIFICANCE_MODEL = "significance-model"; private static Map<String, ProvidedModel> setupProvidedModels() { var m = new HashMap<String, ProvidedModel>(); |