summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2023-11-16 14:52:47 +0000
committerArne Juul <arnej@yahooinc.com>2023-11-16 19:01:17 +0000
commit16ab76c8e668b90177438c1e793a253f48eb55f0 (patch)
treeab767179bf346ab49853bcfcc2ab2ab264c1e11f
parentacd4ebf2718a4d80998b87a57c4b046e56f8e3e0 (diff)
always process with SerializationContext (needed by unpack_bits)
-rw-r--r--config-model/src/main/java/com/yahoo/schema/derived/RawRankProfile.java10
-rw-r--r--config-model/src/test/derived/globalphase_onnx_inside/rank-profiles.cfg2
-rw-r--r--config-model/src/test/derived/tensor/rank-profiles.cfg21
-rw-r--r--config-model/src/test/derived/tensor/tensor.sd10
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/RankingExpression.java3
-rwxr-xr-xsearchlib/src/test/java/com/yahoo/searchlib/rankingexpression/RankingExpressionTestCase.java6
6 files changed, 43 insertions, 9 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/derived/RawRankProfile.java b/config-model/src/main/java/com/yahoo/schema/derived/RawRankProfile.java
index 87b79ddcdc3..8606599f530 100644
--- a/config-model/src/main/java/com/yahoo/schema/derived/RawRankProfile.java
+++ b/config-model/src/main/java/com/yahoo/schema/derived/RawRankProfile.java
@@ -186,6 +186,7 @@ public class RawRankProfile implements RankProfilesConfig.Producer {
private RankingExpression secondPhaseRanking;
private RankingExpression globalPhaseRanking;
private final int globalPhaseRerankCount;
+ private final SerializationContext functionSerializationContext;
/**
* Creates a raw rank profile from the given rank profile
@@ -225,7 +226,7 @@ public class RawRankProfile implements RankProfilesConfig.Producer {
List<ExpressionFunction> functionExpressions = functions.values().stream().map(RankProfile.RankingExpressionFunction::function).toList();
Map<String, String> functionProperties = new LinkedHashMap<>();
var typeContext = compiled.typeContext(queryProfiles);
- SerializationContext functionSerializationContext = new SerializationContext(functionExpressions, Map.of(), typeContext);
+ this.functionSerializationContext = new SerializationContext(functionExpressions, Map.of(), typeContext);
if (firstPhaseRanking != null) {
functionProperties.putAll(firstPhaseRanking.getRankProperties(functionSerializationContext));
}
@@ -265,8 +266,6 @@ public class RawRankProfile implements RankProfilesConfig.Producer {
private void derivePropertiesAndFeaturesFromFunctions(Map<String, RankProfile.RankingExpressionFunction> functions,
Map<String, String> functionProperties,
SerializationContext functionContext) {
- if (functions.isEmpty()) return;
-
replaceFunctionFeatures(summaryFeatures, functionContext);
replaceFunctionFeatures(matchFeatures, functionContext);
@@ -556,11 +555,12 @@ public class RawRankProfile implements RankProfilesConfig.Producer {
if ("".equals(name))
name = phase;
+ String expressionAsString = expression.getRoot().toString(functionSerializationContext).toString();
if (expression.getRoot() instanceof ReferenceNode) {
- properties.add(new Pair<>("vespa.rank." + phase, expression.getRoot().toString()));
+ properties.add(new Pair<>("vespa.rank." + phase, expressionAsString));
} else {
properties.add(new Pair<>("vespa.rank." + phase, wrapInRankingExpression(name)));
- properties.add(new Pair<>(RankingExpression.propertyName(name), expression.getRoot().toString()));
+ properties.add(new Pair<>(RankingExpression.propertyName(name), expressionAsString));
}
return properties;
}
diff --git a/config-model/src/test/derived/globalphase_onnx_inside/rank-profiles.cfg b/config-model/src/test/derived/globalphase_onnx_inside/rank-profiles.cfg
index 4600884b615..b62d7fd239c 100644
--- a/config-model/src/test/derived/globalphase_onnx_inside/rank-profiles.cfg
+++ b/config-model/src/test/derived/globalphase_onnx_inside/rank-profiles.cfg
@@ -17,6 +17,8 @@ rankprofile[].fef.property[].value "true"
rankprofile[].fef.property[].name "vespa.type.attribute.aa"
rankprofile[].fef.property[].value "tensor(d1[3])"
rankprofile[].name "simple"
+rankprofile[].fef.property[].name "vespa.type.feature.attribute(aa)"
+rankprofile[].fef.property[].value "tensor(d1[3])"
rankprofile[].fef.property[].name "vespa.rank.firstphase"
rankprofile[].fef.property[].value "rankingExpression(firstphase)"
rankprofile[].fef.property[].name "rankingExpression(firstphase).rankingScript"
diff --git a/config-model/src/test/derived/tensor/rank-profiles.cfg b/config-model/src/test/derived/tensor/rank-profiles.cfg
index cd8375cb68d..a72e9dc27cd 100644
--- a/config-model/src/test/derived/tensor/rank-profiles.cfg
+++ b/config-model/src/test/derived/tensor/rank-profiles.cfg
@@ -47,7 +47,7 @@ rankprofile[].name "profile2"
rankprofile[].fef.property[].name "vespa.rank.firstphase"
rankprofile[].fef.property[].value "rankingExpression(firstphase)"
rankprofile[].fef.property[].name "rankingExpression(firstphase).rankingScript"
-rankprofile[].fef.property[].value "reduce(reduce(join(attribute(f4), tensor(x[10],y[10],z[3])((x==y)*(y==z)), f(a,b)(a * b)), sum, x), sum)"
+rankprofile[].fef.property[].value "reduce(reduce(join(attribute(f4), tensor(x[10],y[10],z[3])(((x == y) * (y == z))), f(a,b)(a * b)), sum, x), sum)"
rankprofile[].fef.property[].name "vespa.type.attribute.f7"
rankprofile[].fef.property[].value "tensor<int8>(p{},x[5])"
rankprofile[].fef.property[].name "vespa.type.attribute.f2"
@@ -206,3 +206,22 @@ rankprofile[].fef.property[].name "vespa.type.query.para"
rankprofile[].fef.property[].value "tensor<float>(p{})"
rankprofile[].fef.property[].name "vespa.type.query.qvec"
rankprofile[].fef.property[].value "tensor<float>(x[40])"
+rankprofile[].name "with-just-unpack"
+rankprofile[].fef.property[].name "vespa.rank.firstphase"
+rankprofile[].fef.property[].value "rankingExpression(firstphase)"
+rankprofile[].fef.property[].name "rankingExpression(firstphase).rankingScript"
+rankprofile[].fef.property[].value "reduce(query(para) * map_subspaces(attribute(f7), f(denseSubspaceInput)(tensor(x[40])((bit(denseSubspaceInput{x:(x / 8)},(x % 8)))))) * query(qvec), sum)"
+rankprofile[].fef.property[].name "vespa.type.attribute.f7"
+rankprofile[].fef.property[].value "tensor<int8>(p{},x[5])"
+rankprofile[].fef.property[].name "vespa.type.attribute.f2"
+rankprofile[].fef.property[].value "tensor<float>(x[2],y[1])"
+rankprofile[].fef.property[].name "vespa.type.attribute.f3"
+rankprofile[].fef.property[].value "tensor(x{})"
+rankprofile[].fef.property[].name "vespa.type.attribute.f4"
+rankprofile[].fef.property[].value "tensor(x[10],y[10])"
+rankprofile[].fef.property[].name "vespa.type.attribute.f5"
+rankprofile[].fef.property[].value "tensor<float>(x[10])"
+rankprofile[].fef.property[].name "vespa.type.query.para"
+rankprofile[].fef.property[].value "tensor(p{})"
+rankprofile[].fef.property[].name "vespa.type.query.qvec"
+rankprofile[].fef.property[].value "tensor(x[40])"
diff --git a/config-model/src/test/derived/tensor/tensor.sd b/config-model/src/test/derived/tensor/tensor.sd
index 3a5fda3ac5d..a0f5cd92c56 100644
--- a/config-model/src/test/derived/tensor/tensor.sd
+++ b/config-model/src/test/derived/tensor/tensor.sd
@@ -135,4 +135,14 @@ schema tensor {
}
}
+ rank-profile with-just-unpack {
+ inputs {
+ query(para) tensor<double>(p{})
+ query(qvec) tensor<double>(x[40])
+ }
+ first-phase {
+ expression: sum(query(para)*unpack_bits(attribute(f7), double, little)*query(qvec))
+ }
+ }
+
}
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/RankingExpression.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/RankingExpression.java
index a7b45feb043..c0dfc0e1d29 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/RankingExpression.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/RankingExpression.java
@@ -257,6 +257,9 @@ public class RankingExpression implements Serializable {
* @return a list of named rank properties required to implement this expression
*/
public Map<String, String> getRankProperties(SerializationContext context) {
+ if ("".equals(name)) {
+ return Map.of();
+ }
Deque<String> path = new LinkedList<>();
String serializedRoot = root.toString(new StringBuilder(), context, path, null).toString();
Map<String, String> serializedExpressions = context.serializedFunctions();
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/RankingExpressionTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/RankingExpressionTestCase.java
index 8af77ec1cdd..8d60f893c7c 100755
--- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/RankingExpressionTestCase.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/RankingExpressionTestCase.java
@@ -364,7 +364,7 @@ public class RankingExpressionTestCase {
private void assertSerialization(String expectedSerialization, String expressionString) {
String serializedExpression;
try {
- RankingExpression expression = new RankingExpression(expressionString);
+ RankingExpression expression = new RankingExpression("secondphase", expressionString);
// No functions -> expect one rank property
serializedExpression = expression.getRankProperties(new SerializationContext()).values().iterator().next();
assertEquals(expectedSerialization, serializedExpression);
@@ -376,7 +376,7 @@ public class RankingExpressionTestCase {
try {
// No functions -> output should be parseable to a ranking expression
// (but not the same one due to primitivization)
- RankingExpression reparsedExpression = new RankingExpression(serializedExpression);
+ RankingExpression reparsedExpression = new RankingExpression("secondphase", serializedExpression);
// Serializing the primitivized expression should yield the same expression again
String reserializedExpression =
reparsedExpression.getRankProperties(new SerializationContext()).values().iterator().next();
@@ -399,7 +399,7 @@ public class RankingExpressionTestCase {
if (print)
System.out.println("Parsing expression '" + expressionString + "':");
- RankingExpression expression = new RankingExpression(expressionString);
+ RankingExpression expression = new RankingExpression("secondphase", expressionString);
Map<String, String> rankProperties = expression.getRankProperties(new SerializationContext(functions,
Optional.empty()));
if (print) {