From 3285cbaa39bb3fc054ae6c95be275cc455ac4f82 Mon Sep 17 00:00:00 2001 From: Magnus Eide-Fredriksen Date: Thu, 7 Nov 2024 13:46:05 +0100 Subject: [PATCH 1/3] fix: overriding/extending rank-profile default in schema LS --- .../resolvers/InheritanceResolver.java | 17 +++++----- .../ai/vespa/schemals/SchemaParserTest.java | 1 + .../src/test/sdfiles/single/defaultdefault.sd | 32 +++++++++++++++++++ 3 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 integration/schema-language-server/language-server/src/test/sdfiles/single/defaultdefault.sd diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/InheritanceResolver.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/InheritanceResolver.java index c0df7f3f08f8..073d66423466 100644 --- a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/InheritanceResolver.java +++ b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/InheritanceResolver.java @@ -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 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; } diff --git a/integration/schema-language-server/language-server/src/test/java/ai/vespa/schemals/SchemaParserTest.java b/integration/schema-language-server/language-server/src/test/java/ai/vespa/schemals/SchemaParserTest.java index c7907cd8ece5..03da9451ced1 100644 --- a/integration/schema-language-server/language-server/src/test/java/ai/vespa/schemals/SchemaParserTest.java +++ b/integration/schema-language-server/language-server/src/test/java/ai/vespa/schemals/SchemaParserTest.java @@ -262,6 +262,7 @@ Stream generateGoodFileTests() { * */ "src/test/sdfiles/single/structinfieldset.sd", "src/test/sdfiles/single/attributeposition.sd", + "src/test/sdfiles/single/defaultdefault.sd", }; return Arrays.stream(filePaths) diff --git a/integration/schema-language-server/language-server/src/test/sdfiles/single/defaultdefault.sd b/integration/schema-language-server/language-server/src/test/sdfiles/single/defaultdefault.sd new file mode 100644 index 000000000000..37cc57d71d82 --- /dev/null +++ b/integration/schema-language-server/language-server/src/test/sdfiles/single/defaultdefault.sd @@ -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(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() + } + + } +} From a4a251d29a744632f9d1901325554dbc78c8ccb5 Mon Sep 17 00:00:00 2001 From: Magnus Eide-Fredriksen Date: Thu, 7 Nov 2024 13:50:58 +0100 Subject: [PATCH 2/3] fix: typo in lightgbm --- .../resolvers/RankExpression/BuiltInFunctions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/RankExpression/BuiltInFunctions.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/RankExpression/BuiltInFunctions.java index b986499f1a77..21a1290cf642 100644 --- a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/RankExpression/BuiltInFunctions.java +++ b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/RankExpression/BuiltInFunctions.java @@ -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\"")))); }}; From 9efbf284f035f5db8b44d52c502178a9933ae49b Mon Sep 17 00:00:00 2001 From: Magnus Eide-Fredriksen Date: Thu, 7 Nov 2024 13:56:43 +0100 Subject: [PATCH 3/3] chore: update lightgbm test --- .../language-server/src/test/sdfiles/single/onnxmodel.sd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/schema-language-server/language-server/src/test/sdfiles/single/onnxmodel.sd b/integration/schema-language-server/language-server/src/test/sdfiles/single/onnxmodel.sd index c25c84431b6f..dd54d1fb889a 100644 --- a/integration/schema-language-server/language-server/src/test/sdfiles/single/onnxmodel.sd +++ b/integration/schema-language-server/language-server/src/test/sdfiles/single/onnxmodel.sd @@ -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")) } } }