- 
                Notifications
    You must be signed in to change notification settings 
- Fork 25.6k
Add enterprise license check to inference action for semantic text fields #122293
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
          
     Merged
      
      
            dan-rubinstein
  merged 8 commits into
  elastic:main
from
dan-rubinstein:semantic-text-license-check
  
      
      
   
  Feb 20, 2025 
      
    
  
     Merged
                    Changes from 4 commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      31af555
              
                Add enterprise license check to inference action for semantic text fi…
              
              
                dan-rubinstein b207231
              
                Update docs/changelog/122293.yaml
              
              
                dan-rubinstein 5ce7e42
              
                Set license to trial in ShardBulkInferenceActionFilterIT
              
              
                dan-rubinstein 7604667
              
                Move license check to only block semantic_text fields that require in…
              
              
                dan-rubinstein af3f1e9
              
                Cleaning up tests
              
              
                dan-rubinstein 0473574
              
                Add parameterization on useLegacyFormat back in ShardBulkInferenceAct…
              
              
                dan-rubinstein 2eda011
              
                Merge branch 'main' into semantic-text-license-check
              
              
                elasticmachine e0e8c0c
              
                Merge branch 'main' into semantic-text-license-check
              
              
                elasticmachine File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 122293 | ||
| summary: Add enterprise license check to inference action for semantic text fields | ||
| area: Machine Learning | ||
| type: bug | ||
| issues: [] | 
        
          
          
            138 changes: 138 additions & 0 deletions
          
          138 
        
  ...ticsearch/xpack/inference/action/filter/ShardBulkInferenceActionFilterBasicLicenseIT.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|  | ||
| package org.elasticsearch.xpack.inference.action.filter; | ||
|  | ||
| import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; | ||
|  | ||
| import org.elasticsearch.ElasticsearchSecurityException; | ||
| import org.elasticsearch.action.bulk.BulkItemResponse; | ||
| import org.elasticsearch.action.bulk.BulkRequestBuilder; | ||
| import org.elasticsearch.action.bulk.BulkResponse; | ||
| import org.elasticsearch.action.index.IndexRequestBuilder; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.index.IndexSettings; | ||
| import org.elasticsearch.index.mapper.InferenceMetadataFieldsMapper; | ||
| import org.elasticsearch.index.mapper.SourceFieldMapper; | ||
| import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper; | ||
| import org.elasticsearch.inference.SimilarityMeasure; | ||
| import org.elasticsearch.license.LicenseSettings; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
| import org.elasticsearch.xpack.inference.LocalStateInferencePlugin; | ||
| import org.elasticsearch.xpack.inference.Utils; | ||
| import org.elasticsearch.xpack.inference.mock.TestDenseInferenceServiceExtension; | ||
| import org.elasticsearch.xpack.inference.mock.TestSparseInferenceServiceExtension; | ||
| import org.junit.Before; | ||
|  | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
|  | ||
| import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.randomSemanticTextInput; | ||
| import static org.hamcrest.Matchers.instanceOf; | ||
|  | ||
| public class ShardBulkInferenceActionFilterBasicLicenseIT extends ESIntegTestCase { | ||
| public static final String INDEX_NAME = "test-index"; | ||
|  | ||
| private final boolean useLegacyFormat; | ||
| private final boolean useSyntheticSource; | ||
|  | ||
| public ShardBulkInferenceActionFilterBasicLicenseIT(boolean useLegacyFormat, boolean useSyntheticSource) { | ||
| this.useLegacyFormat = useLegacyFormat; | ||
| this.useSyntheticSource = useSyntheticSource; | ||
| } | ||
|         
                  dan-rubinstein marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| @ParametersFactory | ||
| public static Iterable<Object[]> parameters() throws Exception { | ||
| return List.of( | ||
| new Object[] { true, false }, | ||
| new Object[] { true, true }, | ||
| new Object[] { false, false }, | ||
| new Object[] { false, true } | ||
| ); | ||
| } | ||
|  | ||
| @Before | ||
| public void setup() throws Exception { | ||
| Utils.storeSparseModel(client()); | ||
| Utils.storeDenseModel( | ||
| client(), | ||
| randomIntBetween(1, 100), | ||
| // dot product means that we need normalized vectors; it's not worth doing that in this test | ||
| randomValueOtherThan(SimilarityMeasure.DOT_PRODUCT, () -> randomFrom(SimilarityMeasure.values())), | ||
| // TODO: Allow element type BIT once TestDenseInferenceServiceExtension supports it | ||
| randomValueOtherThan(DenseVectorFieldMapper.ElementType.BIT, () -> randomFrom(DenseVectorFieldMapper.ElementType.values())) | ||
| ); | ||
| } | ||
|  | ||
| @Override | ||
| protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) { | ||
| return Settings.builder().put(LicenseSettings.SELF_GENERATED_LICENSE_TYPE.getKey(), "basic").build(); | ||
| } | ||
|  | ||
| @Override | ||
| protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
| return Arrays.asList(LocalStateInferencePlugin.class); | ||
| } | ||
|  | ||
| @Override | ||
| public Settings indexSettings() { | ||
| var builder = Settings.builder() | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10)) | ||
| .put(InferenceMetadataFieldsMapper.USE_LEGACY_SEMANTIC_TEXT_FORMAT.getKey(), useLegacyFormat); | ||
| if (useSyntheticSource) { | ||
| builder.put(IndexSettings.RECOVERY_USE_SYNTHETIC_SOURCE_SETTING.getKey(), true); | ||
| builder.put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.SYNTHETIC.name()); | ||
| } | ||
| return builder.build(); | ||
| } | ||
|  | ||
| public void testLicenseInvalidForInference() { | ||
| prepareCreate(INDEX_NAME).setMapping( | ||
| String.format( | ||
| Locale.ROOT, | ||
| """ | ||
| { | ||
| "properties": { | ||
| "sparse_field": { | ||
| "type": "semantic_text", | ||
| "inference_id": "%s" | ||
| }, | ||
| "dense_field": { | ||
| "type": "semantic_text", | ||
| "inference_id": "%s" | ||
| } | ||
| } | ||
| } | ||
| """, | ||
| TestSparseInferenceServiceExtension.TestInferenceService.NAME, | ||
| TestDenseInferenceServiceExtension.TestInferenceService.NAME | ||
| ) | ||
| ).get(); | ||
|  | ||
| BulkRequestBuilder bulkRequest = client().prepareBulk(); | ||
| int totalBulkReqs = randomIntBetween(2, 100); | ||
|         
                  dan-rubinstein marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| for (int i = 0; i < totalBulkReqs; i++) { | ||
| Map<String, Object> source = new HashMap<>(); | ||
| source.put("sparse_field", rarely() ? null : randomSemanticTextInput()); | ||
| source.put("dense_field", rarely() ? null : randomSemanticTextInput()); | ||
|         
                  dan-rubinstein marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| bulkRequest.add(new IndexRequestBuilder(client()).setIndex(INDEX_NAME).setId(Long.toString(i)).setSource(source)); | ||
| } | ||
|  | ||
| BulkResponse bulkResponse = bulkRequest.get(); | ||
| for (BulkItemResponse itemResponse : bulkResponse) { | ||
| assertTrue(itemResponse.isFailed()); | ||
| assertThat(itemResponse.getFailure().getCause(), instanceOf(ElasticsearchSecurityException.class)); | ||
| } | ||
|         
                  dan-rubinstein marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.