From 635201edea2f24171e2f0ac8e106d0fb61934138 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Fri, 6 Mar 2020 15:13:13 +0100 Subject: Add a test --- .../nearestneighbor/query-profiles/default.xml | 1 + .../nearestneighbor/query-profiles/types/root.xml | 3 ++ .../src/test/derived/nearestneighbor/test.sd | 27 ++++++++++++++++ .../derived/NearestNeighborTestCase.java | 37 ++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 config-model/src/test/derived/nearestneighbor/query-profiles/default.xml create mode 100644 config-model/src/test/derived/nearestneighbor/query-profiles/types/root.xml create mode 100644 config-model/src/test/derived/nearestneighbor/test.sd create mode 100644 config-model/src/test/java/com/yahoo/searchdefinition/derived/NearestNeighborTestCase.java 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 @@ + 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 @@ + + + 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(x[5]) { + indexing: attribute | summary + } + field vec_hnsw type tensor(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()); + } + } + +} -- cgit v1.2.3