diff options
author | Jon Bratseth <bratseth@vespa.ai> | 2024-02-15 23:23:47 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@vespa.ai> | 2024-02-15 23:23:47 +0100 |
commit | e2d3146b777bd7b0c09df68cd0e1335ee2046313 (patch) | |
tree | 648b77f1ce6793979ae4bcf0f5b0c8e8a79311fb /container-search | |
parent | 4a3f24577249443b6fdaeea36b7b8110da107f06 (diff) |
Pass context when resolving properties
Diffstat (limited to 'container-search')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/query/profile/types/ConversionContext.java | 10 | ||||
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/schema/internal/TensorConverter.java | 24 |
2 files changed, 21 insertions, 13 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/ConversionContext.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/ConversionContext.java index 9bb770cf527..3183359e342 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/types/ConversionContext.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/ConversionContext.java @@ -33,8 +33,14 @@ public class ConversionContext { this.destination = destination; this.registry = registry; this.embedders = embedders; - this.language = context.containsKey("language") ? Language.fromLanguageTag(context.get("language")) - : Language.UNKNOWN; + + // If this was set in the request it may not be in this properties instance, which may be just the query profile + // properties, which are below the queryProperties in the chain ... + Object language = context.get("language"); // set in the request + if (language == null) + language = properties.get("language", context); + this.language = language != null ? Language.fromLanguageTag(language.toString()) : Language.UNKNOWN; + this.contextValues = context; this.properties = properties; } diff --git a/container-search/src/main/java/com/yahoo/search/schema/internal/TensorConverter.java b/container-search/src/main/java/com/yahoo/search/schema/internal/TensorConverter.java index b1d6dbd5859..4f1fa44b982 100644 --- a/container-search/src/main/java/com/yahoo/search/schema/internal/TensorConverter.java +++ b/container-search/src/main/java/com/yahoo/search/schema/internal/TensorConverter.java @@ -31,17 +31,18 @@ public class TensorConverter { public Tensor convertTo(TensorType type, String key, Object value, Language language, Map<String, String> contextValues, Properties properties) { - var context = new Embedder.Context(key).setLanguage(language).setContextValues(contextValues); - Tensor tensor = toTensor(type, value, context, properties); + var context = new Embedder.Context(key).setLanguage(language); + Tensor tensor = toTensor(type, value, context, contextValues, properties); if (tensor == null) return null; if (! tensor.type().isAssignableTo(type)) throw new IllegalArgumentException("Require a tensor of type " + type); return tensor; } - private Tensor toTensor(TensorType type, Object value, Embedder.Context context, Properties properties) { + private Tensor toTensor(TensorType type, Object value, Embedder.Context context, Map<String, String> contextValues, + Properties properties) { if (value instanceof Tensor) return (Tensor)value; - if (value instanceof String && isEmbed((String)value)) return embed((String)value, type, context, properties); + if (value instanceof String && isEmbed((String)value)) return embed((String)value, type, context, contextValues, properties); if (value instanceof String) return Tensor.from(type, (String)value); return null; } @@ -50,7 +51,8 @@ public class TensorConverter { return value.startsWith("embed("); } - private Tensor embed(String s, TensorType type, Embedder.Context embedderContext, Properties properties) { + private Tensor embed(String s, TensorType type, Embedder.Context embedderContext, Map<String, String> contextValues, + Properties properties) { if ( ! s.endsWith(")")) throw new IllegalArgumentException("Expected any string enclosed in embed(), but the argument does not end by ')'"); String argument = s.substring("embed(".length(), s.length() - 1); @@ -77,7 +79,7 @@ public class TensorConverter { embedderId = entry.getKey(); embedder = entry.getValue(); } - return embedder.embed(resolve(argument, properties), embedderContext.copy().setEmbedderId(embedderId), type); + return embedder.embed(resolve(argument, contextValues, properties), embedderContext.copy().setEmbedderId(embedderId), type); } private Embedder requireEmbedder(String embedderId) { @@ -87,23 +89,23 @@ public class TensorConverter { return embedders.get(embedderId); } - private static String resolve(String s, Properties properties) { + private static String resolve(String s, Map<String, String> contextValues, Properties properties) { if (s.startsWith("'") && s.endsWith("'")) return s.substring(1, s.length() - 1); if (s.startsWith("\"") && s.endsWith("\"")) return s.substring(1, s.length() - 1); if (s.startsWith("@")) - return resolveReference(s, properties); + return resolveReference(s, contextValues, properties); return s; } - private static String resolveReference(String s, Properties properties) { + private static String resolveReference(String s, Map<String, String> contextValues, Properties properties) { String referenceKey = s.substring(1); - String referencedValue = properties.getString(referenceKey); + Object referencedValue = properties.get(referenceKey, contextValues); if (referencedValue == null) throw new IllegalArgumentException("Could not resolve query parameter reference '" + referenceKey + "' used in an embed() argument"); - return referencedValue; + return referencedValue.toString(); } private static String validEmbedders(Map<String, Embedder> embedders) { |