Skip to content

Commit

Permalink
Merge pull request #32807 from vespa-engine/interns/magnus/rank-profi…
Browse files Browse the repository at this point in the history
…le-default

fix: overriding/extending rank-profile default in schema LS
  • Loading branch information
Mangern authored Nov 7, 2024
2 parents e1d85ac + 9efbf28 commit f8145a2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,17 @@ private static void resolveRankProfileInheritance(SchemaNode inheritanceNode, Pa
if (myRankProfileDefinitionNode == null) return;
if (!myRankProfileDefinitionNode.hasSymbol() || myRankProfileDefinitionNode.getSymbol().getStatus() != SymbolStatus.DEFINITION) return;

if (inheritedIdentifier.equals("default")) {
inheritanceNode.setSymbolStatus(SymbolStatus.BUILTIN_REFERENCE);
return;
}


List<Symbol> parentSymbols = context.schemaIndex().findSymbols(inheritanceNode.getSymbol());

if (parentSymbols.isEmpty()) {
// Handled in resolve symbol ref
if (parentSymbols.isEmpty() ||
// prevents rank-profile default inherits default from causing cyclic inheritance
(inheritedIdentifier.equals("default") && myRankProfileDefinitionNode.getSymbol().getShortIdentifier().equals("default"))
) {
if (inheritedIdentifier.equals("default")) {
inheritanceNode.setSymbolStatus(SymbolStatus.BUILTIN_REFERENCE);
return;
}
// Otherwise handled in resolve symbol ref
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public class BuiltInFunctions {
// === ML Model features ===
put("onnx", new GenericFunction("onnx", new FunctionSignature(new SymbolArgument(SymbolType.ONNX_MODEL, "onnx-model"))));
put("onnxModel", new GenericFunction("onnxModel", new FunctionSignature(new SymbolArgument(SymbolType.ONNX_MODEL, "onnx-model"))));
put("lightbgm", new GenericFunction("lightbgm", new FunctionSignature(new StringArgument("\"/path/to/lightbgm-model.json\""))));
put("lightgbm", new GenericFunction("lightgbm", new FunctionSignature(new StringArgument("\"/path/to/lightgbm-model.json\""))));
put("xgboost", new GenericFunction("xgboost", new FunctionSignature(new StringArgument("\"/path/to/xgboost-model.json\""))));
}};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ Stream<DynamicTest> generateGoodFileTests() {
* */
"src/test/sdfiles/single/structinfieldset.sd",
"src/test/sdfiles/single/attributeposition.sd",
"src/test/sdfiles/single/defaultdefault.sd",
};

return Arrays.stream(filePaths)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file tests if overriding/extending the rank-profile default works
schema defaultdefault {
document defaultdefault {
field title type string {
indexing: index | summary
}

field chunk type string {
indexing: index | summary
}
}

field embedding type tensor<bfloat16>(x[384]) {
indexing: (input title || "") . " " . (input chunk || "") | embed e5 | attribute | index
attribute {
distance-metric: angular
}
}

rank-profile default inherits default {
function cos_sim() {
expression: cos(distance(field, embedding))
}
}

rank-profile custom inherits default {
function foo() {
expression: cos_sim()
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ schema onnxmodel {
}

function func_b() {
expression: sum(lightbgm("/path/to/lightbgm-model.json"))
expression: sum(lightgbm("/path/to/lightbgm-model.json"))
}
}
}

0 comments on commit f8145a2

Please sign in to comment.