summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/types/ConversionContext.java10
-rw-r--r--container-search/src/main/java/com/yahoo/search/schema/internal/TensorConverter.java24
-rw-r--r--linguistics/src/main/java/com/yahoo/language/process/Embedder.java9
3 files changed, 21 insertions, 22 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) {
diff --git a/linguistics/src/main/java/com/yahoo/language/process/Embedder.java b/linguistics/src/main/java/com/yahoo/language/process/Embedder.java
index f6fdb86d01f..c46c3ca690c 100644
--- a/linguistics/src/main/java/com/yahoo/language/process/Embedder.java
+++ b/linguistics/src/main/java/com/yahoo/language/process/Embedder.java
@@ -88,7 +88,6 @@ public interface Embedder {
private Language language = Language.UNKNOWN;
private String destination;
private String embedderId = "unknown";
- private Map<String, String> contextValues;
public Context(String destination) {
this.destination = destination;
@@ -140,14 +139,6 @@ public interface Embedder {
return this;
}
- /** Returns a read-only map of context key-values which can be looked up during conversion. */
- public Map<String, String> getContextValues() { return contextValues; }
-
- public Context setContextValues(Map<String, String> contextValues) {
- this.contextValues = contextValues;
- return this;
- }
-
}
class FailingEmbedder implements Embedder {