Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move semantic_text mappers to Inference plugin #105187

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/plugin/inference/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
requires org.apache.httpcomponents.httpasyncclient;
requires org.apache.httpcomponents.httpcore.nio;
requires org.apache.lucene.core;
requires org.elasticsearch.logging;

exports org.elasticsearch.xpack.inference.action;
exports org.elasticsearch.xpack.inference.registry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.indices.SystemIndexDescriptor;
import org.elasticsearch.inference.InferenceServiceExtension;
import org.elasticsearch.inference.InferenceServiceRegistry;
Expand All @@ -29,6 +31,7 @@
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.ExtensiblePlugin;
import org.elasticsearch.plugins.InferenceRegistryPlugin;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.SystemIndexPlugin;
import org.elasticsearch.rest.RestController;
Expand All @@ -52,6 +55,8 @@
import org.elasticsearch.xpack.inference.external.http.retry.RetrySettings;
import org.elasticsearch.xpack.inference.external.http.sender.HttpRequestSenderFactory;
import org.elasticsearch.xpack.inference.logging.ThrottlerManager;
import org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper;
import org.elasticsearch.xpack.inference.mapper.SemanticTextInferenceResultFieldMapper;
import org.elasticsearch.xpack.inference.registry.ModelRegistryImpl;
import org.elasticsearch.xpack.inference.rest.RestDeleteInferenceModelAction;
import org.elasticsearch.xpack.inference.rest.RestGetInferenceModelAction;
Expand All @@ -67,12 +72,19 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class InferencePlugin extends Plugin implements ActionPlugin, ExtensiblePlugin, SystemIndexPlugin, InferenceRegistryPlugin {
public class InferencePlugin extends Plugin
implements
ActionPlugin,
ExtensiblePlugin,
SystemIndexPlugin,
InferenceRegistryPlugin,
MapperPlugin {

public static final String NAME = "inference";
public static final String UTILITY_THREAD_POOL_NAME = "inference_utility";
Expand Down Expand Up @@ -254,4 +266,17 @@ public InferenceServiceRegistry getInferenceServiceRegistry() {
public ModelRegistry getModelRegistry() {
return modelRegistry.get();
}

@Override
public Map<String, Mapper.TypeParser> getMappers() {
if (SemanticTextFeature.isEnabled()) {
return Map.of(SemanticTextFieldMapper.CONTENT_TYPE, SemanticTextFieldMapper.PARSER);
}
return Map.of();
}

@Override
public Map<String, MetadataFieldMapper.TypeParser> getMetadataMappers() {
return Map.of(SemanticTextInferenceResultFieldMapper.NAME, SemanticTextInferenceResultFieldMapper.PARSER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

package org.elasticsearch.xpack.ml;
package org.elasticsearch.xpack.inference;

import org.elasticsearch.common.util.FeatureFlag;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

package org.elasticsearch.xpack.ml.mapper;
package org.elasticsearch.xpack.inference.mapper;

import org.apache.lucene.search.Query;
import org.elasticsearch.common.Strings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

package org.elasticsearch.xpack.ml.mapper;
package org.elasticsearch.xpack.inference.mapper;

import org.apache.lucene.search.Query;
import org.elasticsearch.common.Strings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@
import org.elasticsearch.cluster.service.ClusterStateTaskExecutorUtils;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.xpack.ml.MlSingleNodeTestCase;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.xpack.inference.InferencePlugin;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class SemanticTextClusterMetadataTests extends MlSingleNodeTestCase {
public class SemanticTextClusterMetadataTests extends ESSingleNodeTestCase {

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return List.of(InferencePlugin.class);
}

public void testCreateIndexWithSemanticTextField() {
final IndexService indexService = createIndex(
"test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

package org.elasticsearch.xpack.ml.mapper;
package org.elasticsearch.xpack.inference.mapper;

import org.apache.lucene.index.IndexableField;
import org.elasticsearch.common.Strings;
Expand All @@ -18,7 +18,7 @@
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xpack.ml.MachineLearning;
import org.elasticsearch.xpack.inference.InferencePlugin;
import org.junit.AssumptionViolatedException;

import java.io.IOException;
Expand Down Expand Up @@ -74,7 +74,7 @@ public void testUpdatesToModelIdNotSupported() throws IOException {

@Override
protected Collection<? extends Plugin> getPlugins() {
return singletonList(new MachineLearning(Settings.EMPTY));
return singletonList(new InferencePlugin(Settings.EMPTY));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

package org.elasticsearch.xpack.ml.mapper;
package org.elasticsearch.xpack.inference.mapper;

import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
Expand Down Expand Up @@ -37,7 +37,7 @@
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.inference.results.SparseEmbeddingResults;
import org.elasticsearch.xpack.ml.MachineLearning;
import org.elasticsearch.xpack.inference.InferencePlugin;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -78,7 +78,7 @@ protected boolean isConfigurable() {

@Override
protected boolean isSupportedOn(IndexVersion version) {
return version.onOrAfter(IndexVersions.ES_VERSION_8_13); // TODO: Switch to ES_VERSION_8_14 when available
return version.onOrAfter(IndexVersions.ES_VERSION_8_12_1); // TODO: Switch to ES_VERSION_8_14 when available
}

@Override
Expand All @@ -88,7 +88,7 @@ protected void registerParameters(ParameterChecker checker) throws IOException {

@Override
protected Collection<? extends Plugin> getPlugins() {
return List.of(new MachineLearning(Settings.EMPTY));
return List.of(new InferencePlugin(Settings.EMPTY));
}

public void testSuccessfulParse() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.index.analysis.CharFilterFactory;
import org.elasticsearch.index.analysis.TokenizerFactory;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.indices.AssociatedIndexDescriptor;
import org.elasticsearch.indices.SystemIndexDescriptor;
Expand All @@ -70,7 +68,6 @@
import org.elasticsearch.plugins.CircuitBreakerPlugin;
import org.elasticsearch.plugins.ExtensiblePlugin;
import org.elasticsearch.plugins.IngestPlugin;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.PersistentTaskPlugin;
import org.elasticsearch.plugins.Platforms;
import org.elasticsearch.plugins.Plugin;
Expand Down Expand Up @@ -366,8 +363,6 @@
import org.elasticsearch.xpack.ml.job.process.normalizer.NormalizerProcessFactory;
import org.elasticsearch.xpack.ml.job.snapshot.upgrader.SnapshotUpgradeTaskExecutor;
import org.elasticsearch.xpack.ml.job.task.OpenJobPersistentTasksExecutor;
import org.elasticsearch.xpack.ml.mapper.SemanticTextFieldMapper;
import org.elasticsearch.xpack.ml.mapper.SemanticTextInferenceResultFieldMapper;
import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor;
import org.elasticsearch.xpack.ml.notifications.DataFrameAnalyticsAuditor;
import org.elasticsearch.xpack.ml.notifications.InferenceAuditor;
Expand Down Expand Up @@ -487,8 +482,7 @@ public class MachineLearning extends Plugin
PersistentTaskPlugin,
SearchPlugin,
ShutdownAwarePlugin,
ExtensiblePlugin,
MapperPlugin {
ExtensiblePlugin {
public static final String NAME = "ml";
public static final String BASE_PATH = "/_ml/";
// Endpoints that were deprecated in 7.x can still be called in 8.x using the REST compatibility layer
Expand Down Expand Up @@ -2298,17 +2292,4 @@ public void signalShutdown(Collection<String> shutdownNodeIds) {
mlLifeCycleService.get().signalGracefulShutdown(shutdownNodeIds);
}
}

@Override
public Map<String, Mapper.TypeParser> getMappers() {
if (SemanticTextFeature.isEnabled()) {
return Map.of(SemanticTextFieldMapper.CONTENT_TYPE, SemanticTextFieldMapper.PARSER);
}
return Map.of();
}

@Override
public Map<String, MetadataFieldMapper.TypeParser> getMetadataMappers() {
return Map.of(SemanticTextInferenceResultFieldMapper.NAME, SemanticTextInferenceResultFieldMapper.PARSER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.analysis.CharFilterFactory;
import org.elasticsearch.index.analysis.TokenizerFactory;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.indices.analysis.AnalysisModule;
import org.elasticsearch.license.LicenseService;
import org.elasticsearch.license.XPackLicenseState;
Expand Down Expand Up @@ -103,11 +102,6 @@ public Map<String, AnalysisModule.AnalysisProvider<TokenizerFactory>> getTokeniz
return mlPlugin.getTokenizers();
}

@Override
public Map<String, Mapper.TypeParser> getMappers() {
return mlPlugin.getMappers();
}

/**
* This is only required as we now have to have the GetRollupIndexCapsAction as a valid action in our node.
* The MachineLearningLicenseTests attempt to create a datafeed referencing this LocalStateMachineLearning object.
Expand Down