Skip to content

Commit

Permalink
Merge pull request #29052 from vespa-engine/arnej/unit-test-configura…
Browse files Browse the repository at this point in the history
…tion-with-normalizers

extend unit test with various normalizers
  • Loading branch information
havardpe authored Oct 23, 2023
2 parents c5f0cae + c86ed3e commit 0c603b5
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,67 @@ RankProfilesConfig readConfig(String subDir) {
assertEquals(Tensor.from("tensor(v[3]):[2,0.25,1.5]"), setup.defaultValues.get("query(v_has_def)"));
}

@Test void withNormalizers() {
RankProfilesConfig rpCfg = readConfig("with_normalizers");
assertEquals(1, rpCfg.rankprofile().size());
RankProfilesEvaluator rpEvaluator = createEvaluator(rpCfg);
var setup = GlobalPhaseSetup.maybeMakeSetup(rpCfg.rankprofile().get(0), rpEvaluator);
assertNotNull(setup);
var nList = setup.normalizers;
assertEquals(7, nList.size());
nList.sort((a,b) -> a.name().compareTo(b.name()));

var n = nList.get(0);
assertEquals("normalize@2974853441@linear", n.name());
assertEquals(0, n.inputEvalSpec().fromQuery().size());
assertEquals(1, n.inputEvalSpec().fromMF().size());
assertEquals("funmf", n.inputEvalSpec().fromMF().get(0));
assertEquals("linear", n.supplier().get().normalizing());

n = nList.get(1);
assertEquals("normalize@3414032797@rrank", n.name());
assertEquals(0, n.inputEvalSpec().fromQuery().size());
assertEquals(1, n.inputEvalSpec().fromMF().size());
assertEquals("attribute(year)", n.inputEvalSpec().fromMF().get(0));
assertEquals("reciprocal-rank{k:60.0}", n.supplier().get().normalizing());

n = nList.get(2);
assertEquals("normalize@3551296680@linear", n.name());
assertEquals(0, n.inputEvalSpec().fromQuery().size());
assertEquals(1, n.inputEvalSpec().fromMF().size());
assertEquals("nativeRank", n.inputEvalSpec().fromMF().get(0));
assertEquals("linear", n.supplier().get().normalizing());

n = nList.get(3);
assertEquals("normalize@4280591309@rrank", n.name());
assertEquals(0, n.inputEvalSpec().fromQuery().size());
assertEquals(1, n.inputEvalSpec().fromMF().size());
assertEquals("bm25(myabstract)", n.inputEvalSpec().fromMF().get(0));
assertEquals("reciprocal-rank{k:42.0}", n.supplier().get().normalizing());

n = nList.get(4);
assertEquals("normalize@4370385022@linear", n.name());
assertEquals(1, n.inputEvalSpec().fromQuery().size());
assertEquals("myweight", n.inputEvalSpec().fromQuery().get(0));
assertEquals(1, n.inputEvalSpec().fromMF().size());
assertEquals("attribute(foo1)", n.inputEvalSpec().fromMF().get(0));
assertEquals("linear", n.supplier().get().normalizing());

n = nList.get(5);
assertEquals("normalize@4640646880@linear", n.name());
assertEquals(0, n.inputEvalSpec().fromQuery().size());
assertEquals(1, n.inputEvalSpec().fromMF().size());
assertEquals("attribute(foo1)", n.inputEvalSpec().fromMF().get(0));
assertEquals("linear", n.supplier().get().normalizing());

n = nList.get(6);
assertEquals("normalize@6283155534@linear", n.name());
assertEquals(0, n.inputEvalSpec().fromQuery().size());
assertEquals(1, n.inputEvalSpec().fromMF().size());
assertEquals("bm25(mytitle)", n.inputEvalSpec().fromMF().get(0));
assertEquals("linear", n.supplier().get().normalizing());
}

private RankProfilesEvaluator createEvaluator(RankProfilesConfig config) {
RankingConstantsConfig constantsConfig = new RankingConstantsConfig.Builder().build();
RankingExpressionsConfig expressionsConfig = new RankingExpressionsConfig.Builder().build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
rankprofile[0].name "with_normalizers"
rankprofile[0].fef.property[0].name "rankingExpression(funmf).rankingScript"
rankprofile[0].fef.property[0].value "attribute(foo1) * attribute(year)"
rankprofile[0].fef.property[1].name "rankingExpression(simplefun).rankingScript"
rankprofile[0].fef.property[1].value "attribute(foo1) * query(myweight)"
rankprofile[0].fef.property[2].name "rankingExpression(bm25two).rankingScript"
rankprofile[0].fef.property[2].value "bm25(mytitle) + bm25(myabstract)"
rankprofile[0].fef.property[3].name "rankingExpression(notused).rankingScript"
rankprofile[0].fef.property[3].value "normalize@5969841192@linear"
rankprofile[0].fef.property[4].name "vespa.rank.firstphase"
rankprofile[0].fef.property[4].value "rankingExpression(firstphase)"
rankprofile[0].fef.property[5].name "rankingExpression(firstphase).rankingScript"
rankprofile[0].fef.property[5].value "attribute(foo1) + bm25(mytitle) + bm25(myabstract)"
rankprofile[0].fef.property[6].name "vespa.rank.globalphase"
rankprofile[0].fef.property[6].value "rankingExpression(globalphase)"
rankprofile[0].fef.property[7].name "rankingExpression(globalphase).rankingScript"
rankprofile[0].fef.property[7].value "normalize@3551296680@linear + normalize@4640646880@linear + normalize@4370385022@linear + normalize@2974853441@linear + normalize@6283155534@linear + normalize@3414032797@rrank + normalize@4280591309@rrank"
rankprofile[0].fef.property[8].name "vespa.match.feature"
rankprofile[0].fef.property[8].value "nativeRank"
rankprofile[0].fef.property[9].name "vespa.match.feature"
rankprofile[0].fef.property[9].value "attribute(foo1)"
rankprofile[0].fef.property[10].name "vespa.match.feature"
rankprofile[0].fef.property[10].value "attribute(year)"
rankprofile[0].fef.property[11].name "vespa.match.feature"
rankprofile[0].fef.property[11].value "bm25(mytitle)"
rankprofile[0].fef.property[12].name "vespa.match.feature"
rankprofile[0].fef.property[12].value "bm25(myabstract)"
rankprofile[0].fef.property[13].name "vespa.match.feature"
rankprofile[0].fef.property[13].value "rankingExpression(funmf)"
rankprofile[0].fef.property[14].name "vespa.feature.rename"
rankprofile[0].fef.property[14].value "rankingExpression(funmf)"
rankprofile[0].fef.property[15].name "vespa.feature.rename"
rankprofile[0].fef.property[15].value "funmf"
rankprofile[0].fef.property[16].name "vespa.type.attribute.t1"
rankprofile[0].fef.property[16].value "tensor(m{},v[3])"
rankprofile[0].normalizer[0].name "normalize@3551296680@linear"
rankprofile[0].normalizer[0].input "nativeRank"
rankprofile[0].normalizer[0].algo LINEAR
rankprofile[0].normalizer[0].kparam 0.0
rankprofile[0].normalizer[1].name "normalize@4640646880@linear"
rankprofile[0].normalizer[1].input "attribute(foo1)"
rankprofile[0].normalizer[1].algo LINEAR
rankprofile[0].normalizer[1].kparam 0.0
rankprofile[0].normalizer[2].name "normalize@4370385022@linear"
rankprofile[0].normalizer[2].input "simplefun"
rankprofile[0].normalizer[2].algo LINEAR
rankprofile[0].normalizer[2].kparam 0.0
rankprofile[0].normalizer[3].name "normalize@2974853441@linear"
rankprofile[0].normalizer[3].input "funmf"
rankprofile[0].normalizer[3].algo LINEAR
rankprofile[0].normalizer[3].kparam 0.0
rankprofile[0].normalizer[4].name "normalize@6283155534@linear"
rankprofile[0].normalizer[4].input "bm25(mytitle)"
rankprofile[0].normalizer[4].algo LINEAR
rankprofile[0].normalizer[4].kparam 0.0
rankprofile[0].normalizer[5].name "normalize@3414032797@rrank"
rankprofile[0].normalizer[5].input "attribute(year)"
rankprofile[0].normalizer[5].algo RRANK
rankprofile[0].normalizer[5].kparam 60.0
rankprofile[0].normalizer[6].name "normalize@4280591309@rrank"
rankprofile[0].normalizer[6].input "bm25(myabstract)"
rankprofile[0].normalizer[6].algo RRANK
rankprofile[0].normalizer[6].kparam 42.0
rankprofile[0].normalizer[7].name "normalize@5969841192@linear"
rankprofile[0].normalizer[7].input "firstPhase"
rankprofile[0].normalizer[7].algo LINEAR
rankprofile[0].normalizer[7].kparam 0.0

0 comments on commit 0c603b5

Please sign in to comment.