summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2023-05-05 15:22:26 +0000
committerGeir Storli <geirst@yahooinc.com>2023-05-05 15:22:26 +0000
commit36ac8ebea478d02dfbd4e914e85e4f56d3e11cf2 (patch)
tree869f68f84614bd90307b57a3bf24299e56efa8ae /config-model
parente0ed2a2f68f470a4348b6ee19c77b4d22eded8de (diff)
Make it possible to configure dotproduct distance metric.
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/schema/document/Attribute.java2
-rw-r--r--config-model/src/test/java/com/yahoo/schema/AttributeSettingsTestCase.java33
2 files changed, 34 insertions, 1 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/document/Attribute.java b/config-model/src/main/java/com/yahoo/schema/document/Attribute.java
index 9e7f14a3d85..7b798e66567 100644
--- a/config-model/src/main/java/com/yahoo/schema/document/Attribute.java
+++ b/config-model/src/main/java/com/yahoo/schema/document/Attribute.java
@@ -39,7 +39,7 @@ import java.util.Set;
*/
public final class Attribute implements Cloneable, Serializable {
- public enum DistanceMetric { EUCLIDEAN, ANGULAR, GEODEGREES, INNERPRODUCT, HAMMING, PRENORMALIZED_ANGULAR }
+ public enum DistanceMetric { EUCLIDEAN, ANGULAR, GEODEGREES, INNERPRODUCT, HAMMING, PRENORMALIZED_ANGULAR, DOTPRODUCT }
// Remember to change hashCode and equals when you add new fields
diff --git a/config-model/src/test/java/com/yahoo/schema/AttributeSettingsTestCase.java b/config-model/src/test/java/com/yahoo/schema/AttributeSettingsTestCase.java
index 64f3bda4ac4..3ca182e18c2 100644
--- a/config-model/src/test/java/com/yahoo/schema/AttributeSettingsTestCase.java
+++ b/config-model/src/test/java/com/yahoo/schema/AttributeSettingsTestCase.java
@@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Optional;
+import static com.yahoo.config.model.test.TestUtil.joinLines;
import static org.junit.jupiter.api.Assertions.*;
/**
@@ -334,4 +335,36 @@ public class AttributeSettingsTestCase extends AbstractSchemaTestCase {
assertSame(single.getAliases(), array.getAliases());
}
+ @Test
+ void distance_metric_is_propagated_to_attributes_config() throws ParseException {
+ assertDerivedDistanceMetric(AttributesConfig.Attribute.Distancemetric.ANGULAR, "angular");
+ assertDerivedDistanceMetric(AttributesConfig.Attribute.Distancemetric.EUCLIDEAN, "euclidean");
+ assertDerivedDistanceMetric(AttributesConfig.Attribute.Distancemetric.HAMMING, "hamming");
+ assertDerivedDistanceMetric(AttributesConfig.Attribute.Distancemetric.GEODEGREES, "geodegrees");
+ // TODO Vespa 9: Remove 'innerproduct' as alias for 'prenormalized-angular'.
+ assertDerivedDistanceMetric(AttributesConfig.Attribute.Distancemetric.INNERPRODUCT, "innerproduct");
+ assertDerivedDistanceMetric(AttributesConfig.Attribute.Distancemetric.PRENORMALIZED_ANGULAR, "prenormalized-angular");
+ }
+
+ private void assertDerivedDistanceMetric(AttributesConfig.Attribute.Distancemetric.Enum expDistanceMetric,
+ String schemaDistanceMetric) throws ParseException {
+ var attrs = new AttributeFields(getSchemaWithDistanceMetric(schemaDistanceMetric));
+ var builder = new AttributesConfig.Builder();
+ attrs.getConfig(builder, AttributeFields.FieldSet.ALL, 100);
+ var cfg = builder.build();
+ assertEquals(expDistanceMetric, cfg.attribute(0).distancemetric());
+ }
+
+ private Schema getSchemaWithDistanceMetric(String distanceMetric) throws ParseException {
+ return getSchema(joinLines("search test {",
+ " document test {",
+ " field t type tensor(x[2]) {",
+ " indexing: attribute",
+ " attribute { distance-metric: " + distanceMetric + "}",
+ " }",
+ " }",
+ "}"));
+ }
+
+
}