aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2019-11-20 11:15:58 +0000
committerArne Juul <arnej@verizonmedia.com>2019-11-20 11:50:09 +0000
commitd67eae3b41eda7e90ad5b31255b8d3c7b12eec48 (patch)
tree7ab6d95b3384564c5c3ee82476bbbae7d8ae12f5 /container-search/src/main
parent7d8c0ced9bbb71d00a9a6eae2f070ba685f20164 (diff)
add unit test + minor fixes for ValidateNearestNeighborSearcher
Diffstat (limited to 'container-search/src/main')
-rw-r--r--container-search/src/main/java/com/yahoo/search/searchers/ValidateNearestNeighborSearcher.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/searchers/ValidateNearestNeighborSearcher.java b/container-search/src/main/java/com/yahoo/search/searchers/ValidateNearestNeighborSearcher.java
index dfd8205cd05..25c65783821 100644
--- a/container-search/src/main/java/com/yahoo/search/searchers/ValidateNearestNeighborSearcher.java
+++ b/container-search/src/main/java/com/yahoo/search/searchers/ValidateNearestNeighborSearcher.java
@@ -7,6 +7,7 @@ import com.google.common.annotations.Beta;
import com.yahoo.container.QrSearchersConfig;
import com.yahoo.prelude.query.Item;
import com.yahoo.prelude.query.NearestNeighborItem;
+import com.yahoo.prelude.query.QueryCanonicalizer;
import com.yahoo.prelude.query.ToolBox;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
@@ -17,12 +18,17 @@ import com.yahoo.search.searchchain.Execution;
import com.yahoo.tensor.Tensor;
import com.yahoo.tensor.TensorType;
import com.yahoo.vespa.config.search.AttributesConfig;
+import com.yahoo.yolean.chain.After;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+// This depends on tensors in query.getRanking which are moved to rank.properties during query.prepare()
+// Query.prepare is done at the same time as canonicalization (by GroupingExecutor), so use that constraint.
+@After(QueryCanonicalizer.queryCanonicalization)
+
/**
* Validates any NearestNeighborItem query items.
*
@@ -79,6 +85,15 @@ public class ValidateNearestNeighborSearcher extends Searcher {
errorMessage = Optional.of(ErrorMessage.createIllegalQuery(description));
}
+ private static boolean isDenseVector(TensorType tt) {
+ List<TensorType.Dimension> dims = tt.dimensions();
+ if (dims.size() != 1) return false;
+ for (var d : dims) {
+ if (d.type() != TensorType.Dimension.Type.indexedBound) return false;
+ }
+ return true;
+ }
+
private void validate(NearestNeighborItem item) {
int target = item.getTargetNumHits();
if (target < 1) {
@@ -88,16 +103,17 @@ public class ValidateNearestNeighborSearcher extends Searcher {
String qprop = item.getQueryTensorName();
List<Object> rankPropValList = rankProperties.asMap().get(qprop);
if (rankPropValList == null) {
- setError(item.toString() + " query property not found");
+ setError(item.toString() + " query tensor not found");
return;
}
if (rankPropValList.size() != 1) {
- setError(item.toString() + " query property does not have a single value");
+ setError(item.toString() + " query tensor does not have a single value");
return;
}
Object rankPropValue = rankPropValList.get(0);
if (! (rankPropValue instanceof Tensor)) {
- setError(item.toString() + " query property should be a tensor, was: "+rankPropValue);
+ setError(item.toString() + " query tensor should be a tensor, was: "+
+ (rankPropValue == null ? "null" : rankPropValue.getClass().toString()));
return;
}
Tensor qTensor = (Tensor)rankPropValue;
@@ -111,7 +127,11 @@ public class ValidateNearestNeighborSearcher extends Searcher {
return;
}
if (! fTensorType.equals(qTensorType)) {
- setError(item.toString() + " field type "+fTensorType+" does not match query property type "+qTensorType);
+ setError(item.toString() + " field type "+fTensorType+" does not match query tensor type "+qTensorType);
+ return;
+ }
+ if (! isDenseVector(fTensorType)) {
+ setError(item.toString() + " tensor type "+fTensorType+" is not a dense vector");
return;
}
} else {