Skip to content

Default new semantic_text fields to use BBQ when models are compatible #126629

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
merged 14 commits into from
Apr 17, 2025

Conversation

kderusso
Copy link
Member

While dense_vector fields default to int8_hnsw for now, we have demonstrated significantly better performance in text embedding models with bbq_hnsw. As this is the primary use case for semantic_text, we are making this the default quantization method for semantic_text fields using text embedding models. Models that are incompatible with BBQ due to dimention count or element type will continue to use the dense_vector quantization defaults.

@kderusso kderusso added >enhancement auto-backport Automatically create backport pull requests when merged :SearchOrg/Relevance Label for the Search (solution/org) Relevance team v8.19.0 v9.1.0 labels Apr 10, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-eng (Team:SearchOrg)

@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

@kderusso kderusso added the :Search Relevance/Search Catch all for Search Relevance label Apr 10, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@kderusso kderusso requested review from jimczi and a team April 10, 2025 17:33
Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

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

I appreciate that we're keeping index options as an implementation detail of the semantic text field. That said, with this change, existing semantic text fields will start using BBQ immediately. I'm in favor of this behavior (rather than reserving this change for only new indices), but I wanted to explicitly call it out for awareness before we proceed with the merge since that's not exactly what we discussed.

Copy link
Contributor

@Mikep86 Mikep86 left a comment

Choose a reason for hiding this comment

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

I think updating existing semantic text fields to use BBQ could cause major problems. For example, take a look at the Int8 HNSW update logic. It only allows updates to Int4 HNSW. The end effect of this change is that every semantic text field using Int8 HNSW could start failing on document ingest.

@jimczi
Copy link
Contributor

jimczi commented Apr 11, 2025

Yep, that was too good to be true, @Mikep86.
Let’s go ahead and apply the logic under a new index version for now.
@elastic/es-search-relevance moving from int8 to BBQ, is that something we could eventually apply to a live index as well?

@kderusso
Copy link
Member Author

Good catch @Mikep86 - Added a gate on IndexVersion.

@kderusso kderusso requested a review from Mikep86 April 11, 2025 12:54
@kderusso kderusso requested a review from Mikep86 April 15, 2025 15:09
Copy link
Contributor

@Mikep86 Mikep86 left a comment

Choose a reason for hiding this comment

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

Nice index version solution in SemanticTextFieldMapperTests, I believe that covers our needs and we can revert changes to getRandomCompatibleIndexVersion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice solution here that both constrains the index versions and maintains randomness 🙌 !

@@ -114,18 +117,18 @@ public MappedFieldType getMappedFieldType() {
}

static IndexVersion getRandomCompatibleIndexVersion(boolean useLegacyFormat) {
return getRandomCompatibleIndexVersion(useLegacyFormat, IndexVersion.current());
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on your changes in SemanticTextFieldMapperTests, I don't think we need any changes to getRandomCompatibleIndexVersion? These changes create some usability challenges:

  • maxVersion is only selectively used, which could be confusing to future devs.
  • What if maxVersion is less than IndexVersions.UPGRADE_TO_LUCENE_10_0_0 or IndexVersions.INFERENCE_METADATA_FIELDS? This will result in an error, and one that is thrown based on a randomization factor as well, which will be very confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

We need this because otherwise one of the cases in SemanticInferenceMetadataFieldMapperTests#isEnabled will fail as it depends on the old, less inclusive legacy format logic. You can see the modifications to the test for this here: 6cfe39a

I could have removed the test, but that didn't feel right. I think this is OK, if we need to extend it later for additional tests we can do so as needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I'm confused about is why reverting changes to both getRandomCompatibleIndexVersion and testIsEnabled isn't an option. This should work fine as this is the state of the test before this PR, no?

And that approach should work with your changes in SemanticTextFieldMapperTests, so I see it as the best path for the moment.

Copy link
Member Author

Choose a reason for hiding this comment

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

We already have some followup work on this test, why don't we roll that into the scope?

IndexVersions.INFERENCE_METADATA_FIELDS,
IndexVersionUtils.getPreviousVersion(IndexVersions.SEMANTIC_TEXT_DEFAULTS_TO_BBQ)
);
assertSemanticTextField(mapperService, "field", true, null, SemanticTextFieldMapper.defaultSemanticDenseIndexOptions());
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this should be defaultDenseVectorIndexOptions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Updated the test, though it's failing right now. It's picking up the correct index options, but in the debugger it's not getting passed in to the mapper. Troubleshooting this now.

Copy link
Member Author

Choose a reason for hiding this comment

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

So in SemanticTextFieldMapperTests#createMapperService, we set the index version created as a setting, and then create the mapping with those specified settings here.

In the MapperServiceTestCase, this calls getVersion(), which always returns IndexVersion.current().

I fixed this, so we ensure that we can pass in the actual version we want to create. This makes this test do the right thing and pass, but there’s a side effect in that a few different existing tests fail due to things like created on a 7.17 index, not having an indexed field, etc. To be clear I believe this is a test error and not an error with semantic_text code.

For this PR, just to get it in and over the line, I hacked in a fix that will not propagate the correct index version, so the tests work the same as they always have. We should make some time to address it. Commit here: 4a7fad9

@kderusso kderusso requested a review from Mikep86 April 16, 2025 20:43
Copy link
Contributor

@Mikep86 Mikep86 left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the (many) iterations here!

@kderusso kderusso merged commit a72883e into elastic:main Apr 17, 2025
17 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 126629

kderusso added a commit to kderusso/elasticsearch that referenced this pull request Apr 17, 2025
elastic#126629)

* Default new semantic_text fields to use BBQ when models are compatible

* Update docs/changelog/126629.yaml

* Gate default BBQ by IndexVersion

* Cleanup from PR feedback

* PR feedback

* Fix test

* Fix test

* PR feedback

* Update test to test correct options

* Hack alert: Fix issue where mapper service was always being created with current index version

(cherry picked from commit a72883e)

# Conflicts:
#	server/src/main/java/org/elasticsearch/index/IndexVersions.java
#	server/src/main/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapper.java
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticInferenceMetadataFieldsMapperTests.java
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java
@kderusso
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.x

Questions ?

Please refer to the Backport tool documentation

@kderusso kderusso removed the v8.19.0 label Apr 17, 2025
@kderusso
Copy link
Member Author

Note: #124581 was not backported, so I have not backported this to 8.x. This means that unless the previous PR is backported, this change will only be in 9.1+.

We can revisit this decision later on, but for now I've made the appropriate label changes on this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged backport pending >enhancement :Search Relevance/Search Catch all for Search Relevance :SearchOrg/Relevance Label for the Search (solution/org) Relevance team v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants