77
88package org .elasticsearch .xpack .inference .mapper ;
99
10- import org .apache .logging .log4j .LogManager ;
11- import org .apache .logging .log4j .Logger ;
1210import org .apache .lucene .index .FieldInfos ;
1311import org .apache .lucene .index .LeafReaderContext ;
1412import org .apache .lucene .search .DocIdSetIterator ;
2018import org .apache .lucene .search .join .BitSetProducer ;
2119import org .apache .lucene .search .join .ScoreMode ;
2220import org .apache .lucene .util .BitSet ;
23- import org .elasticsearch .ResourceNotFoundException ;
2421import org .elasticsearch .cluster .metadata .InferenceFieldMetadata ;
2522import org .elasticsearch .common .Strings ;
2623import org .elasticsearch .common .bytes .BytesReference ;
7875import org .elasticsearch .xpack .core .ml .inference .results .TextExpansionResults ;
7976import org .elasticsearch .xpack .core .ml .search .SparseVectorQueryBuilder ;
8077import org .elasticsearch .xpack .inference .highlight .SemanticTextHighlighter ;
81- import org .elasticsearch .xpack .inference .registry .ModelRegistry ;
8278
8379import java .io .IOException ;
8480import java .io .UncheckedIOException ;
9389import java .util .Set ;
9490import java .util .function .BiConsumer ;
9591import java .util .function .Function ;
96- import java .util .function .Supplier ;
9792
9893import static org .elasticsearch .inference .TaskType .SPARSE_EMBEDDING ;
9994import static org .elasticsearch .inference .TaskType .TEXT_EMBEDDING ;
117112 * A {@link FieldMapper} for semantic text fields.
118113 */
119114public class SemanticTextFieldMapper extends FieldMapper implements InferenceFieldMapper {
120- private static final Logger logger = LogManager .getLogger (SemanticTextFieldMapper .class );
121115 public static final NodeFeature SEMANTIC_TEXT_IN_OBJECT_FIELD_FIX = new NodeFeature ("semantic_text.in_object_field_fix" );
122116 public static final NodeFeature SEMANTIC_TEXT_SINGLE_FIELD_UPDATE_FIX = new NodeFeature ("semantic_text.single_field_update_fix" );
123117 public static final NodeFeature SEMANTIC_TEXT_DELETE_FIX = new NodeFeature ("semantic_text.delete_fix" );
@@ -133,12 +127,10 @@ public class SemanticTextFieldMapper extends FieldMapper implements InferenceFie
133127 public static final String CONTENT_TYPE = "semantic_text" ;
134128 public static final String DEFAULT_ELSER_2_INFERENCE_ID = DEFAULT_ELSER_ID ;
135129
136- public static final TypeParser parser (Supplier <ModelRegistry > modelRegistry ) {
137- return new TypeParser (
138- (n , c ) -> new Builder (n , c ::bitSetProducer , c .getIndexSettings (), modelRegistry .get ()),
139- List .of (validateParserContext (CONTENT_TYPE ))
140- );
141- }
130+ public static final TypeParser PARSER = new TypeParser (
131+ (n , c ) -> new Builder (n , c ::bitSetProducer , c .getIndexSettings ()),
132+ List .of (validateParserContext (CONTENT_TYPE ))
133+ );
142134
143135 public static BiConsumer <String , MappingParserContext > validateParserContext (String type ) {
144136 return (n , c ) -> {
@@ -150,7 +142,6 @@ public static BiConsumer<String, MappingParserContext> validateParserContext(Str
150142 }
151143
152144 public static class Builder extends FieldMapper .Builder {
153- private final ModelRegistry modelRegistry ;
154145 private final boolean useLegacyFormat ;
155146
156147 private final Parameter <String > inferenceId = Parameter .stringParam (
@@ -208,21 +199,14 @@ public static Builder from(SemanticTextFieldMapper mapper) {
208199 Builder builder = new Builder (
209200 mapper .leafName (),
210201 mapper .fieldType ().getChunksField ().bitsetProducer (),
211- mapper .fieldType ().getChunksField ().indexSettings (),
212- mapper .modelRegistry
202+ mapper .fieldType ().getChunksField ().indexSettings ()
213203 );
214204 builder .init (mapper );
215205 return builder ;
216206 }
217207
218- public Builder (
219- String name ,
220- Function <Query , BitSetProducer > bitSetProducer ,
221- IndexSettings indexSettings ,
222- ModelRegistry modelRegistry
223- ) {
208+ public Builder (String name , Function <Query , BitSetProducer > bitSetProducer , IndexSettings indexSettings ) {
224209 super (name );
225- this .modelRegistry = modelRegistry ;
226210 this .useLegacyFormat = InferenceMetadataFieldsMapper .isEnabled (indexSettings .getSettings ()) == false ;
227211 this .inferenceFieldBuilder = c -> createInferenceField (
228212 c ,
@@ -280,32 +264,9 @@ public SemanticTextFieldMapper build(MapperBuilderContext context) {
280264 if (useLegacyFormat && multiFieldsBuilder .hasMultiFields ()) {
281265 throw new IllegalArgumentException (CONTENT_TYPE + " field [" + leafName () + "] does not support multi-fields" );
282266 }
283-
284- if (modelSettings .get () == null ) {
285- try {
286- var resolvedModelSettings = modelRegistry .getMinimalServiceSettings (inferenceId .get ());
287- if (resolvedModelSettings != null ) {
288- modelSettings .setValue (resolvedModelSettings );
289- }
290- } catch (ResourceNotFoundException exc ) {
291- // We allow the inference ID to be unregistered at this point.
292- // This will delay the creation of sub-fields, so indexing and querying for this field won't work
293- // until the corresponding inference endpoint is created.
294- }
295- }
296-
297267 if (modelSettings .get () != null ) {
298268 validateServiceSettings (modelSettings .get ());
299- } else {
300- logger .warn (
301- "The field [{}] references an unknown inference ID [{}]. "
302- + "Indexing and querying this field will not work correctly until the corresponding "
303- + "inference endpoint is created." ,
304- leafName (),
305- inferenceId .get ()
306- );
307269 }
308-
309270 final String fullName = context .buildFullName (leafName ());
310271
311272 if (context .isInNestedContext ()) {
@@ -326,8 +287,7 @@ public SemanticTextFieldMapper build(MapperBuilderContext context) {
326287 useLegacyFormat ,
327288 meta .getValue ()
328289 ),
329- builderParams (this , context ),
330- modelRegistry
290+ builderParams (this , context )
331291 );
332292 }
333293
@@ -368,17 +328,9 @@ private SemanticTextFieldMapper copySettings(SemanticTextFieldMapper mapper, Map
368328 }
369329 }
370330
371- private final ModelRegistry modelRegistry ;
372-
373- private SemanticTextFieldMapper (
374- String simpleName ,
375- MappedFieldType mappedFieldType ,
376- BuilderParams builderParams ,
377- ModelRegistry modelRegistry
378- ) {
331+ private SemanticTextFieldMapper (String simpleName , MappedFieldType mappedFieldType , BuilderParams builderParams ) {
379332 super (simpleName , mappedFieldType , builderParams );
380333 ensureMultiFields (builderParams .multiFields ().iterator ());
381- this .modelRegistry = modelRegistry ;
382334 }
383335
384336 private void ensureMultiFields (Iterator <FieldMapper > mappers ) {
0 commit comments