summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/ranking/RankProfilesEvaluator.java
blob: ccb9b9837feaf4073848f8c1e6e449e2f0233381 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

package com.yahoo.search.ranking;

import ai.vespa.models.evaluation.FunctionEvaluator;
import ai.vespa.models.evaluation.Model;
import ai.vespa.models.evaluation.ModelsEvaluator;
import com.yahoo.api.annotations.Beta;
import com.yahoo.component.AbstractComponent;
import com.yahoo.component.annotation.Inject;
import com.yahoo.filedistribution.fileacquirer.FileAcquirer;
import com.yahoo.vespa.config.search.RankProfilesConfig;
import com.yahoo.vespa.config.search.core.OnnxModelsConfig;
import com.yahoo.vespa.config.search.core.RankingConstantsConfig;
import com.yahoo.vespa.config.search.core.RankingExpressionsConfig;

/**
 * proxy for model-evaluation components
 * @author arnej
 */
@Beta
public class RankProfilesEvaluator extends AbstractComponent {

    private final ModelsEvaluator evaluator;

    @Inject
    public RankProfilesEvaluator(
            RankProfilesConfig rankProfilesConfig,
            RankingConstantsConfig constantsConfig,
            RankingExpressionsConfig expressionsConfig,
            OnnxModelsConfig onnxModelsConfig,
            FileAcquirer fileAcquirer)
    {
        this.evaluator = new ModelsEvaluator(
                rankProfilesConfig,
                constantsConfig,
                expressionsConfig,
                onnxModelsConfig,
                fileAcquirer);
    }

    public Model modelForRankProfile(String rankProfile) {
        var m = evaluator.models().get(rankProfile);
        if (m == null) {
            throw new IllegalArgumentException("unknown rankprofile: " + rankProfile);
        }
        return m;
    }

    public FunctionEvaluator evaluatorForFunction(String rankProfile, String functionName) {
        return modelForRankProfile(rankProfile).evaluatorOf(functionName);
    }
}