aboutsummaryrefslogtreecommitdiffstats
path: root/model-evaluation/src/test/java/ai/vespa/models/evaluation/RankProfileImportingTest.java
blob: 1a6f6925caf3b8a04f78f1d6beac26f0e6cb0e9b (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.models.evaluation;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * @author bratseth
 */
public class RankProfileImportingTest {

    @Test
    public void testImportingRankExpressions() {
        ModelTester tester = new ModelTester("src/test/resources/config/rankexpression/");

        assertEquals(18, tester.models().size());

        Model macros = tester.models().get("macros");
        assertEquals("macros", macros.name());
        assertEquals(4, macros.functions().size());
        tester.assertFunction("fourtimessum", "4 * (var1 + var2)", macros);
        tester.assertFunction("firstphase", "match + fieldMatch(title) + rankingExpression(myfeature)", macros);
        tester.assertFunction("secondphase", "rankingExpression(fourtimessum@5cf279212355b980.67f1e87166cfef86)", macros);
        tester.assertFunction("myfeature",
                              "70 * fieldMatch(title).completeness * pow(0 - fieldMatch(title).earliness,2) + " +
                              "30 * pow(0 - fieldMatch(description).earliness,2)",
                              macros);
        assertEquals(4, macros.referencedFunctions().size());
        tester.assertBoundFunction("rankingExpression(fourtimessum@5cf279212355b980.67f1e87166cfef86)",
                                   "4 * (match + rankBoost)", macros);
    }

    @Test
    public void testImportingSimpleGlobalPhase() {
        ModelTester tester = new ModelTester("src/test/resources/config/dotproduct/");
        assertEquals(1, tester.models().size());
        Model m = tester.models().get("default");
        assertEquals("default", m.name());
        assertEquals(1, m.functions().size());
        tester.assertFunction("globalphase", "reduce(attribute(aa) * query(zz), sum)", m);
        var f = m.functions().get(0);
        assertEquals("globalphase", f.getName());
        assertEquals(2, f.arguments().size());
        assertEquals("tensor(d0[3])", f.getArgumentType("query(zz)").toString());
        assertEquals("tensor(d0[3])", f.getArgumentType("attribute(aa)").toString());
        var rt = f.returnType();
        assertEquals(true, rt.isPresent());
        assertEquals("tensor()", rt.get().toString());
    }

}