summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/config
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-04-27 13:45:41 +0200
committerJon Bratseth <bratseth@gmail.com>2022-04-27 13:45:41 +0200
commit66c9edce7bbe11cb99c636e433feb2085f8d2e8a (patch)
treec47eb08e387a8dda2a6d5748ccdb5eb8c083997f /container-search/src/main/java/com/yahoo/search/config
parent1c38c6e29a59eff80396f4a367245d6694f87168 (diff)
Use an already exported package
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/config')
-rw-r--r--container-search/src/main/java/com/yahoo/search/config/RankProfile.java94
-rw-r--r--container-search/src/main/java/com/yahoo/search/config/Schema.java71
-rw-r--r--container-search/src/main/java/com/yahoo/search/config/SchemaInfo.java147
-rw-r--r--container-search/src/main/java/com/yahoo/search/config/SchemaInfoConfigurer.java50
-rw-r--r--container-search/src/main/java/com/yahoo/search/config/internal/TensorConverter.java95
-rw-r--r--container-search/src/main/java/com/yahoo/search/config/package-info.java11
6 files changed, 0 insertions, 468 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/config/RankProfile.java b/container-search/src/main/java/com/yahoo/search/config/RankProfile.java
deleted file mode 100644
index 944a23f2964..00000000000
--- a/container-search/src/main/java/com/yahoo/search/config/RankProfile.java
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.config;
-
-import com.yahoo.tensor.TensorType;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Information about a rank profile
- *
- * @author bratseth
- */
-public class RankProfile {
-
- private final String name;
- private final boolean hasSummaryFeatures;
- private final boolean hasRankFeatures;
- private final Map<String, TensorType> inputs;
-
- private RankProfile(Builder builder) {
- this.name = builder.name;
- this.hasSummaryFeatures = builder.hasSummaryFeatures;
- this.hasRankFeatures = builder.hasRankFeatures;
- this.inputs = Map.copyOf(builder.inputs);
- }
-
- public String name() { return name; }
-
- /** Returns true if this rank profile has summary features. */
- public boolean hasSummaryFeatures() { return hasSummaryFeatures; }
-
- /** Returns true if this rank profile has rank features. */
- public boolean hasRankFeatures() { return hasRankFeatures; }
-
- /** Returns the inputs explicitly declared in this rank profile. */
- public Map<String, TensorType> inputs() { return inputs; }
-
- @Override
- public boolean equals(Object o) {
- if (o == this) return true;
- if ( ! (o instanceof RankProfile)) return false;
- RankProfile other = (RankProfile)o;
- if ( ! other.name.equals(this.name)) return false;
- if ( other.hasSummaryFeatures != this.hasSummaryFeatures) return false;
- if ( other.hasRankFeatures != this.hasRankFeatures) return false;
- if ( ! other.inputs.equals(this.inputs)) return false;
- return true;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, hasSummaryFeatures, hasRankFeatures, inputs);
- }
-
- @Override
- public String toString() {
- return "rank profile '" + name + "'";
- }
-
- public static class Builder {
-
- private final String name;
- private boolean hasSummaryFeatures = true;
- private boolean hasRankFeatures = true;
- private final Map<String, TensorType> inputs = new HashMap<>();
-
- public Builder(String name) {
- this.name = Objects.requireNonNull(name);
- }
-
- public Builder setHasSummaryFeatures(boolean hasSummaryFeatures) {
- this.hasSummaryFeatures = hasSummaryFeatures;
- return this;
- }
-
- public Builder setHasRankFeatures(boolean hasRankFeatures) {
- this.hasRankFeatures = hasRankFeatures;
- return this;
- }
-
- public Builder addInput(String name, TensorType type) {
- inputs.put(name, type);
- return this;
- }
-
- public RankProfile build() {
- return new RankProfile(this);
- }
-
- }
-
-}
diff --git a/container-search/src/main/java/com/yahoo/search/config/Schema.java b/container-search/src/main/java/com/yahoo/search/config/Schema.java
deleted file mode 100644
index 57712c731f4..00000000000
--- a/container-search/src/main/java/com/yahoo/search/config/Schema.java
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.config;
-
-import com.yahoo.api.annotations.Beta;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Information about a schema which is part of the application running this.
- *
- * This is immutable.
- *
- * @author bratseth
- */
-@Beta
-public class Schema {
-
- private final String name;
- private final Map<String, RankProfile> rankProfiles;
-
- private Schema(Builder builder) {
- this.name = builder.name;
- this.rankProfiles = Map.copyOf(builder.rankProfiles);
- }
-
- public String name() { return name; }
- public Map<String, RankProfile> rankProfiles() { return rankProfiles; }
-
- @Override
- public boolean equals(Object o) {
- if (o == this) return true;
- if ( ! (o instanceof Schema)) return false;
- Schema other = (Schema)o;
- if ( ! other.name.equals(this.name)) return false;
- if ( ! other.rankProfiles.equals(this.rankProfiles)) return false;
- return true;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, rankProfiles);
- }
-
- @Override
- public String toString() {
- return "schema '" + name + "'";
- }
-
- public static class Builder {
-
- private final String name;
- private final Map<String, RankProfile> rankProfiles = new HashMap<>();
-
- public Builder(String name) {
- this.name = Objects.requireNonNull(name);
- }
-
- public Builder add(RankProfile profile) {
- rankProfiles.put(profile.name(), Objects.requireNonNull(profile));
- return this;
- }
-
- public Schema build() {
- return new Schema(this);
- }
-
- }
-
-}
diff --git a/container-search/src/main/java/com/yahoo/search/config/SchemaInfo.java b/container-search/src/main/java/com/yahoo/search/config/SchemaInfo.java
deleted file mode 100644
index 4a8ec83c847..00000000000
--- a/container-search/src/main/java/com/yahoo/search/config/SchemaInfo.java
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.config;
-
-import com.yahoo.api.annotations.Beta;
-import com.yahoo.container.QrSearchersConfig;
-import com.yahoo.container.search.SchemaInfoConfig;
-import com.yahoo.search.Query;
-import com.yahoo.tensor.TensorType;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-/**
- * Information about all the schemas configured in the application this container is a part of.
- *
- * Usage:
- * <code>
- * SchemaInfo.Session session = schemaInfo.newSession(query); // once when starting to process a query
- * session.get(...) // access information about the schema(s) relevant to the query
- * </code>
- *
- * This is immutable.
- *
- * @author bratseth
- */
-// NOTES:
-// This should replace IndexFacts, and probably DocumentDatabase.
-// It replicates the schema resolution mechanism in IndexFacts, but does not yet contain any field information.
-// To replace IndexFacts, this must accept IndexInfo and expose that information, as well as consolidation
-// given a set of possible schemas: The session mechanism is present here to make that efficient when added
-// (resolving schema subsets for every field lookup is too expensive).
-@Beta
-public class SchemaInfo {
-
- private static final SchemaInfo empty = new SchemaInfo(List.of(), Map.of());
-
- private final List<Schema> schemas;
-
- /** The schemas contained in each content cluster indexed by cluster name */
- private final Map<String, List<String>> clusters;
-
- public SchemaInfo(IndexInfoConfig indexInfo, // will be used in the future
- SchemaInfoConfig schemaInfoConfig,
- QrSearchersConfig qrSearchersConfig) {
- this(SchemaInfoConfigurer.toSchemas(schemaInfoConfig), SchemaInfoConfigurer.toClusters(qrSearchersConfig));
- }
-
- public SchemaInfo(List<Schema> schemas, Map<String, List<String>> clusters) {
- this.schemas = List.copyOf(schemas);
- this.clusters = Map.copyOf(clusters);
- }
-
- public Session newSession(Query query) {
- return new Session(query.getModel().getSources(), query.getModel().getRestrict(), clusters, schemas);
- }
-
- public static SchemaInfo empty() { return empty; }
-
- @Override
- public boolean equals(Object o) {
- if (o == this) return true;
- if ( ! (o instanceof SchemaInfo)) return false;
- SchemaInfo other = (SchemaInfo)o;
- if ( ! other.schemas.equals(this.schemas)) return false;
- if ( ! other.clusters.equals(this.clusters)) return false;
- return true;
- }
-
- @Override
- public int hashCode() { return Objects.hash(schemas, clusters); }
-
- /** The schema information resolved to be relevant to this session. */
- public static class Session {
-
- private final List<Schema> schemas;
-
- private Session(Set<String> sources,
- Set<String> restrict,
- Map<String, List<String>> clusters,
- List<Schema> candidates) {
- this.schemas = resolveSchemas(sources, restrict, clusters, candidates);
- }
-
- /**
- * Given a search list which is a mixture of schemas and cluster
- * names, and a restrict list which is a list of schemas, return a
- * set of all valid schemas for this combination.
- *
- * @return the possibly empty list of schemas matching the arguments
- */
- private static List<Schema> resolveSchemas(Set<String> sources,
- Set<String> restrict,
- Map<String, List<String>> clusters,
- List<Schema> candidates) {
- if (sources.isEmpty())
- return restrict.isEmpty() ? candidates : keep(restrict, candidates);
-
- Set<String> schemaNames = new HashSet<>();
- for (String source : sources) {
- if (clusters.containsKey(source)) // source is a cluster
- schemaNames.addAll(clusters.get(source));
- else // source is a schema
- schemaNames.add(source);
- }
- candidates = keep(schemaNames, candidates);
- return restrict.isEmpty() ? candidates : keep(restrict, candidates);
- }
-
- private static List<Schema> keep(Set<String> names, List<Schema> schemas) {
- return schemas.stream().filter(schema -> names.contains(schema.name())).collect(Collectors.toList());
- }
-
- /**
- * Returns the type of the given rank feature name in the given profile,
- * if it can be uniquely determined.
- *
- * @param rankFeature the rank feature name, a string on the form "query(name)"
- * @param rankProfile the name of the rank profile in which to locate the input declaration
- * @return the type of the declared input, or null if it is not declared or the rank profile is not found
- * @throws IllegalArgumentException if the feature is declared in this rank profile in multiple schemas
- * of this session with conflicting types
- */
- public TensorType rankProfileInput(String rankFeature, String rankProfile) {
- TensorType foundType = null;
- Schema declaringSchema = null;
- for (Schema schema : schemas) {
- RankProfile profile = schema.rankProfiles().get(rankProfile);
- if (profile == null) continue;
- TensorType newlyFoundType = profile.inputs().get(rankFeature);
- if (newlyFoundType == null) continue;
- if (foundType != null && ! newlyFoundType.equals(foundType))
- throw new IllegalArgumentException("Conflicting input type declarations for '" + rankFeature + "': " +
- "Declared as " + foundType + " in " + profile + " in " + declaringSchema +
- ", and as " + newlyFoundType + " in " + profile + " in " + schema);
- foundType = newlyFoundType;
- declaringSchema = schema;
- }
- return foundType;
- }
-
- }
-
-}
diff --git a/container-search/src/main/java/com/yahoo/search/config/SchemaInfoConfigurer.java b/container-search/src/main/java/com/yahoo/search/config/SchemaInfoConfigurer.java
deleted file mode 100644
index 49acf589ba3..00000000000
--- a/container-search/src/main/java/com/yahoo/search/config/SchemaInfoConfigurer.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.config;
-
-import com.yahoo.container.QrSearchersConfig;
-import com.yahoo.container.search.SchemaInfoConfig;
-import com.yahoo.tensor.TensorType;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-/**
- * Translation between schema info configuration and schema objects.
- *
- * @author bratseth
- */
-class SchemaInfoConfigurer {
-
- static List<Schema> toSchemas(SchemaInfoConfig documentdbInfoConfig) {
- return documentdbInfoConfig.schema().stream().map(config -> toSchema(config)).collect(Collectors.toList());
- }
-
- static Schema toSchema(SchemaInfoConfig.Schema schemaInfoConfig) {
- Schema.Builder builder = new Schema.Builder(schemaInfoConfig.name());
- for (var profileConfig : schemaInfoConfig.rankprofile()) {
- RankProfile.Builder profileBuilder = new RankProfile.Builder(profileConfig.name());
- profileBuilder.setHasSummaryFeatures(profileConfig.hasSummaryFeatures());
- profileBuilder.setHasRankFeatures(profileConfig.hasRankFeatures());
- for (var inputConfig : profileConfig.input())
- profileBuilder.addInput(inputConfig.name(), TensorType.fromSpec(inputConfig.type()));
- builder.add(profileBuilder.build());
- }
- return builder.build();
- }
-
- static Map<String, List<String>> toClusters(QrSearchersConfig config) {
- Map<String, List<String>> clusters = new HashMap<>();
- for (int i = 0; i < config.searchcluster().size(); ++i) {
- List<String> schemas = new ArrayList<>();
- String clusterName = config.searchcluster(i).name();
- for (int j = 0; j < config.searchcluster(i).searchdef().size(); ++j)
- schemas.add(config.searchcluster(i).searchdef(j));
- clusters.put(clusterName, schemas);
- }
- return clusters;
- }
-
-}
diff --git a/container-search/src/main/java/com/yahoo/search/config/internal/TensorConverter.java b/container-search/src/main/java/com/yahoo/search/config/internal/TensorConverter.java
deleted file mode 100644
index fbe2ffb8984..00000000000
--- a/container-search/src/main/java/com/yahoo/search/config/internal/TensorConverter.java
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.config.internal;
-
-import com.yahoo.language.Language;
-import com.yahoo.language.process.Embedder;
-import com.yahoo.tensor.Tensor;
-import com.yahoo.tensor.TensorType;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * A class which knows how to convert an Object value to a tensor of a given type.
- *
- * @author bratseth
- */
-public class TensorConverter {
-
- private static final Pattern embedderArgumentRegexp = Pattern.compile("^([A-Za-z0-9_\\-.]+),\\s*([\"'].*[\"'])");
-
- private final Map<String, Embedder> embedders;
-
- public TensorConverter(Map<String, Embedder> embedders) {
- this.embedders = embedders;
- }
-
- public Tensor convertTo(TensorType type, String key, Object value, Language language) {
- var context = new Embedder.Context(key).setLanguage(language);
- Tensor tensor = toTensor(type, value, context);
- 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) {
- if (value instanceof Tensor) return (Tensor)value;
- if (value instanceof String && isEmbed((String)value)) return embed((String)value, type, context);
- if (value instanceof String) return Tensor.from(type, (String)value);
- return null;
- }
-
- static boolean isEmbed(String value) {
- return value.startsWith("embed(");
- }
-
- private Tensor embed(String s, TensorType type, Embedder.Context embedderContext) {
- 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);
- Embedder embedder;
-
- // Check if arguments specifies an embedder with the format embed(embedder, "text to encode")
- Matcher matcher = embedderArgumentRegexp.matcher(argument);
- if (matcher.matches()) {
- String embedderId = matcher.group(1);
- argument = matcher.group(2);
- if ( ! embedders.containsKey(embedderId)) {
- throw new IllegalArgumentException("Can't find embedder '" + embedderId + "'. " +
- "Valid embedders are " + validEmbedders(embedders));
- }
- embedder = embedders.get(embedderId);
- } else if (embedders.size() == 0) {
- throw new IllegalStateException("No embedders provided"); // should never happen
- } else if (embedders.size() > 1) {
- throw new IllegalArgumentException("Multiple embedders are provided but no embedder id is given. " +
- "Valid embedders are " + validEmbedders(embedders));
- } else {
- embedder = embedders.entrySet().stream().findFirst().get().getValue();
- }
-
- return embedder.embed(removeQuotes(argument), embedderContext, type);
- }
-
- private static String removeQuotes(String s) {
- if (s.startsWith("'") && s.endsWith("'")) {
- return s.substring(1, s.length() - 1);
- }
- if (s.startsWith("\"") && s.endsWith("\"")) {
- return s.substring(1, s.length() - 1);
- }
- return s;
- }
-
- private static String validEmbedders(Map<String, Embedder> embedders) {
- List<String> embedderIds = new ArrayList<>();
- embedders.forEach((key, value) -> embedderIds.add(key));
- embedderIds.sort(null);
- return String.join(",", embedderIds);
- }
-
-}
diff --git a/container-search/src/main/java/com/yahoo/search/config/package-info.java b/container-search/src/main/java/com/yahoo/search/config/package-info.java
deleted file mode 100644
index dd9c7bfcf04..00000000000
--- a/container-search/src/main/java/com/yahoo/search/config/package-info.java
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-@ExportPackage
-@PublicApi
-package com.yahoo.search.config;
-
-import com.yahoo.api.annotations.PublicApi;
-import com.yahoo.osgi.annotation.ExportPackage;
-
-/**
- * Information about the current configuration this is running as a part of.
- */ \ No newline at end of file