diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2020-03-06 15:13:13 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2020-03-06 15:13:13 +0100 |
commit | 635201edea2f24171e2f0ac8e106d0fb61934138 (patch) | |
tree | bb0c0099421b18555b8e1063e2a4d1cad9d0b294 | |
parent | cb866b015287901b7e11bbc6b4114f6c03f70aca (diff) |
Add a test
4 files changed, 68 insertions, 0 deletions
diff --git a/config-model/src/test/derived/nearestneighbor/query-profiles/default.xml b/config-model/src/test/derived/nearestneighbor/query-profiles/default.xml new file mode 100644 index 00000000000..b8140f34617 --- /dev/null +++ b/config-model/src/test/derived/nearestneighbor/query-profiles/default.xml @@ -0,0 +1 @@ +<query-profile id="default" type="root" /> diff --git a/config-model/src/test/derived/nearestneighbor/query-profiles/types/root.xml b/config-model/src/test/derived/nearestneighbor/query-profiles/types/root.xml new file mode 100644 index 00000000000..895e0663181 --- /dev/null +++ b/config-model/src/test/derived/nearestneighbor/query-profiles/types/root.xml @@ -0,0 +1,3 @@ +<query-profile-type id="root" inherits="native"> + <field name="ranking.features.query(q_vec)" type="tensor<float>(x[5])" /> +</query-profile-type> diff --git a/config-model/src/test/derived/nearestneighbor/test.sd b/config-model/src/test/derived/nearestneighbor/test.sd new file mode 100644 index 00000000000..ab5f6d85448 --- /dev/null +++ b/config-model/src/test/derived/nearestneighbor/test.sd @@ -0,0 +1,27 @@ +search test { + document test { + field id type int { + indexing: attribute | summary + } + field vec type tensor<float>(x[5]) { + indexing: attribute | summary + } + field vec_hnsw type tensor<float>(x[5]) { + indexing: attribute | index | summary + index { + hnsw { + max-links-per-node: 16 + neighbors-to-explore-at-insert: 200 + } + } + } + } + rank-profile default { + first-phase { + expression: 10000 - itemRawScore(nns) + } + } + document-summary minimal { + summary id type int {} + } +} diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/NearestNeighborTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/NearestNeighborTestCase.java new file mode 100644 index 00000000000..ead4e586d9f --- /dev/null +++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/NearestNeighborTestCase.java @@ -0,0 +1,37 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.derived; + +import com.yahoo.component.ComponentId; +import com.yahoo.prelude.query.QueryException; +import com.yahoo.search.Query; +import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry; +import com.yahoo.search.query.profile.config.QueryProfileConfigurer; +import com.yahoo.searchdefinition.parser.ParseException; +import com.yahoo.vespa.model.container.search.QueryProfiles; +import org.junit.Test; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class NearestNeighborTestCase extends AbstractExportingTestCase { + + @Test + public void testNearestNeighbor() throws IOException, ParseException { + try { + ComponentId.resetGlobalCountersForTests(); + DerivedConfiguration c = assertCorrectDeriving("nearestneighbor"); + + CompiledQueryProfileRegistry queryProfiles = + QueryProfileConfigurer.createFromConfig(new QueryProfiles(c.getQueryProfiles(), (level, message) -> {}).getConfig()).compile(); + Query q = new Query("?ranking.features.query(q_vec)=[1,2,3,4,5,6]", // length is 6, not 5 + queryProfiles.getComponent("default")); + fail("This should fail when q_vec is parsed as a tensor"); + } catch (QueryException e) { + // success + assertEquals("Invalid request parameter", e.getMessage()); + } + } + +} |