From 64a3304435dc3823ac0ea4958ea83fc57fae704c Mon Sep 17 00:00:00 2001 From: Geir Storli Date: Fri, 13 Jan 2023 14:49:43 +0000 Subject: Allow hnsw index for tensors with 1 mapped and 1 indexed dimension. --- .../yahoo/schema/processing/TensorFieldTestCase.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'config-model/src/test/java/com/yahoo/schema/processing') diff --git a/config-model/src/test/java/com/yahoo/schema/processing/TensorFieldTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/TensorFieldTestCase.java index 60e1e35fb2e..b7817900dac 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/TensorFieldTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/TensorFieldTestCase.java @@ -35,7 +35,7 @@ public class TensorFieldTestCase { } catch (IllegalArgumentException e) { assertEquals("For schema 'test', field 'f1': A tensor of type 'tensor(x{})' does not support having an 'index'. " + - "Currently, only tensors with 1 indexed dimension supports that.", + "Currently, only tensors with 1 indexed dimension or 1 mapped + 1 indexed dimension support that.", e.getMessage()); } } @@ -85,6 +85,12 @@ public class TensorFieldTestCase { assertHnswIndexParams("index: hnsw", 16, 200); } + @Test + void tensor_with_one_mapped_and_one_indexed_dimension_can_have_hnsw_index() throws ParseException { + assertHnswIndexParams("tensor(x{},y[64])", "", 16, 200); + assertHnswIndexParams("tensor(x[64],y{})", "", 16, 200); + } + @Test void hnsw_index_parameters_can_be_specified() throws ParseException { assertHnswIndexParams("index { hnsw { max-links-per-node: 32 } }", 32, 200); @@ -157,7 +163,11 @@ public class TensorFieldTestCase { } private void assertHnswIndexParams(String indexSpec, int maxLinksPerNode, int neighborsToExploreAtInsert) throws ParseException { - var sd = getSdWithIndexSpec(indexSpec); + assertHnswIndexParams("tensor(x[64])", indexSpec, maxLinksPerNode, neighborsToExploreAtInsert); + } + + private void assertHnswIndexParams(String tensorType, String indexSpec, int maxLinksPerNode, int neighborsToExploreAtInsert) throws ParseException { + var sd = getSdWithIndexSpec(tensorType, indexSpec); var search = createFromString(sd).getSchema(); var attr = search.getAttribute("t1"); var params = attr.hnswIndexParams(); @@ -166,8 +176,8 @@ public class TensorFieldTestCase { assertEquals(neighborsToExploreAtInsert, params.get().neighborsToExploreAtInsert()); } - private String getSdWithIndexSpec(String indexSpec) { - return getSd(joinLines("field t1 type tensor(x[64]) {", + private String getSdWithIndexSpec(String tensorType, String indexSpec) { + return getSd(joinLines("field t1 type " + tensorType + " {", " indexing: attribute | index", " " + indexSpec, "}")); -- cgit v1.2.3