Skip to content

Update semantic text to use BFLOAT16 by default - #144236

Merged
Mikep86 merged 49 commits into
elastic:mainfrom
Mikep86:semantic-text_default-to-bfloat16
Apr 1, 2026
Merged

Mikep86 merged 49 commits into
elastic:mainfrom
Mikep86:semantic-text_default-to-bfloat16

Conversation

@Mikep86

@Mikep86 Mikep86 commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

Updates the semantic_text field to use the BFLOAT16 element type by default for all inference services that use FLOAT.

This change minorly impacts knn query scoring due to the reduced precision of BFLOAT16. This won't matter for 99% of users, but since this may be a problem for some, this PR also adds a way to override the element type used so that these users can continue using FLOAT. An element_type parameter has been added to the dense vector index options:

PUT semantic-embeddings
{
  "mappings": {
    "properties": {
      "content": {
        "type": "semantic_text",
        "inference_id": "my-inference-endpoint",
        "index_options": {
          "dense_vector": {
            "element_type": "float",
            "type": "bbq_disk"
          }
        }
      }
    }
  }
}

Since element_type is not part of standard dense vector index options (and it doesn't make sense to add it there, since element_type is a top-level param for dense_vector), this param was added by extending dense vector index options only for semantic_text. This creates some new scenarios for us to handle:

  • Allowing the user to set only the element_type without setting type
  • Requiring type only when params other than element_type are set
  • Throwing an error when the element_type set in index_options is incompatible with the model element type
  • Serializing element_type when include_defaults is true and we defaulted to BFLOAT16

@Mikep86
Mikep86 requested review from a team, jimczi and tballison March 13, 2026 16:57
@Mikep86 Mikep86 added >enhancement :Search Foundations/Mapping Index mappings, including merging and defining field types :Search Relevance/Vectors Vector search v9.4.0 labels Mar 13, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Hi @Mikep86, I've created a changelog YAML for you.

@Mikep86

Mikep86 commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

@elasticmachine update branch

@Mikep86

Mikep86 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

I found a couple bugs while working on this:

Cannot get semantic_text field mapping with defaults when inference service does not exist - Fixed this for 9.4 in this PR, since I was already modifying the code that would need to change anyways. It should be easy to apply the necessary changes to earlier branches via a manual backport.

Unhandled edge cases when setting semantic_text index options - I left the failure modes the same so we can address this in a separate PR.

if (includeDefaults || isConfigured()) {
if (value == null) {
// Default value, serialize resolved defaults
MinimalServiceSettings resolvedModelSettings = getResolvedModelSettings(null, false);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix for #145136. getResolvedModelSettings must return null when the inference service can't be found.

Comment on lines -574 to 610
if (resolved != null && settings.canMergeWith(resolved) == false) {
throw new IllegalArgumentException(
"Mismatch between provided and registered inference model settings. "
+ "Provided: ["
+ settings
+ "], Expected: ["
+ resolved
+ "]."
+ modelSettings.taskType().name()
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimczi I removed this because this check was ineffective. It was only ever called when both settings and resolved the same instance, set via modelSettings.get().

Comment on lines +160 to +173
public void testGetDefaultIndexOptionsBeforeInferenceServiceExists() throws Exception {
final String inferenceId = randomIdentifier();
final String inferenceFieldName = "inference_field";

// Create the index before the inference endpoint exists. Default index options cannot be determined yet.
assertAcked(safeGet(prepareCreate(INDEX_NAME).setMapping(generateMapping(inferenceFieldName, inferenceId, null)).execute()));
Map<String, Object> actualFieldMappings = getFieldMappings(inferenceFieldName, true);

Map<String, Object> inferenceFieldMappings = XContentMapValues.nodeMapValue(
actualFieldMappings.get(inferenceFieldName),
inferenceFieldName
);
assertThat(inferenceFieldMappings.containsKey("index_options"), is(true));
assertThat(inferenceFieldMappings.get("index_options"), nullValue());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the test that validates the fix for #145136

@Mikep86
Mikep86 marked this pull request as ready for review March 27, 2026 21:30
@elasticsearchmachine elasticsearchmachine added Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch labels Mar 27, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@kkharbas kkharbas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Except one nit comment

@Mikep86
Mikep86 enabled auto-merge (squash) April 1, 2026 15:02
@Mikep86
Mikep86 merged commit dbc9098 into elastic:main Apr 1, 2026
31 of 35 checks passed
mromaios pushed a commit to mromaios/elasticsearch that referenced this pull request Apr 9, 2026
Updates the semantic_text field to use the BFLOAT16 element type by default for all inference services that use FLOAT.

This change minorly impacts knn query scoring due to the reduced precision of BFLOAT16. This won't matter for 99% of users, but since this may be a problem for some, this PR also adds a way to override the element type used so that these users can continue using FLOAT. An element_type parameter has been added to the dense vector index options.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :Search Foundations/Mapping Index mappings, including merging and defining field types :Search Relevance/Vectors Vector search Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants