Skip to content

Conversation

@dimitris-athanasiou
Copy link
Contributor

This change enhances usage reporting for the inference plugin to account for usage of semantic_text fields.

Usage is bucketed by service and task_type. For each bucket this adds a semantic_text object that contains:

  • field_count: the number of semantic_text fields that use an inference endpoint of that service/task_type.
  • indices_count: the number of indices that contain at least one semantic_field referencing an inference endpoint of that service/task_type.
  • inference_id_count: the number of distinct inference endpoints of that service/task_type used by semantic_text fields.

In addition, this change adds two new kinds of buckets that facalitate getting aggregate usage information:

  • _all buckets are added by task_type. These allow summation of usage info for all inference endpoints of a particular task_type.
  • default model buckets are added. Those contain usage info for models that are included by default.

@dimitris-athanasiou dimitris-athanasiou added >enhancement :ml Machine learning :Search Relevance/Search Catch all for Search Relevance v9.2.0 labels Sep 23, 2025
@elasticsearchmachine elasticsearchmachine added Team:ML Meta label for the ML team Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch labels Sep 23, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Hi @dimitris-athanasiou, I've created a changelog YAML for you.

@@ -0,0 +1,5 @@
pr: 135262
summary: Add usage stats for `semantic_text` fields
area: "Search"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if the area should be Search or Machine Learning

Copy link
Contributor

Choose a reason for hiding this comment

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

"Vector Search" is my vote

@kderusso kderusso added the :SearchOrg/Relevance Label for the Search (solution/org) Relevance team label Sep 23, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Search - Relevance The Search organization Search Relevance team label Sep 23, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@dimitris-athanasiou dimitris-athanasiou added :Search Foundations/Search Catch all for Search Foundations and removed :Search Relevance/Search Catch all for Search Relevance labels Sep 23, 2025
@elasticsearchmachine elasticsearchmachine added Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch and removed Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch labels Sep 23, 2025
@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

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

Nice work! Are there any existing yaml tests that we could update here too?

@dimitris-athanasiou
Copy link
Contributor Author

I have added YAML tests as per your suggestion @kderusso

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.

Great work! I left some comments, but they're almost all nits. Per our offline discussion, I think we need to figure out if we want to filter out all hidden indices (i.e. those that start with .). Other than that, this PR is in good shape 🚀

@@ -0,0 +1,5 @@
pr: 135262
summary: Add usage stats for `semantic_text` fields
area: "Search"
Copy link
Contributor

Choose a reason for hiding this comment

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

"Vector Search" is my vote

type: semantic_text
field_2:
type: semantic_text
inference_id: .multilingual-e5-small-elasticsearch
Copy link
Contributor

Choose a reason for hiding this comment

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

A note on default endpoint usage in CI: We have noticed flakiness when we actually use them to generate embeddings due to deployment timeouts and failures. This reference should be fine because it's not actually triggering deployment of the E5 model, but something to be aware of in general.

@dimitris-athanasiou
Copy link
Contributor Author

dimitris-athanasiou commented Sep 25, 2025

@Mikep86 Regarding hidden indices. I have excluded them too for now. They are probably of little value telemetry-wise. However, if we want to collect them in the future we can easily have a separate section for them by adding a SemanticTextStats object as a member of SemanticTextStats. We could then gather system/hidden field stats in there. Had an offline chat with @jimczi about this solution and we're on the same page.

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 really good, thanks for the changes! Functionality looks solid. I left a few comments for one more round of small changes, then I think we're good to merge!

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.

LGTM! I have some minor comments in my previous review, but none of them are blocking.

This change enhances usage reporting for the inference plugin
to account for usage of `semantic_text` fields.

Usage is bucketed by service and task_type. For each bucket
this adds a `semantic_text` object that contains:

- `field_count`: the number of `semantic_text` fields that use
an inference endpoint of that service/task_type.
- `indices_count`: the number of indices that contain at least
one `semantic_field` referencing an inference endpoint of that service/task_type.
- `inference_id_count`: the number of distinct inference endpoints
of that service/task_type used by `semantic_text` fields.

In addition, this change adds two new kinds of buckets that facalitate
getting aggregate usage information:

- `_all` buckets are added by `task_type`. These allow summation of usage
info for all inference endpoints of a particular `task_type`.
- default model buckets are added. Those contain usage info for models
that are included by default.
@dimitris-athanasiou
Copy link
Contributor Author

dimitris-athanasiou commented Sep 29, 2025

@Mikep86 Thank you for the additional review! I have addressed those points in 3d4f273

Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

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

Nice work!

Map<String, ModelStats> endpointStats
) {
for (TaskType taskType : TaskType.values()) {
if (taskType == TaskType.ANY) {
Copy link
Member

Choose a reason for hiding this comment

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

The RERANK, COMPLETION and CHAT_COMPLETION task types will never appear in a semantic text field and also can be skipped here.

Add a static function TaskType [] semanticTextTaskTypes( return SPARSE + TEXT) to TaskType and just iterate those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point we are adding top level _all stats buckets. Even though we won't have semantic_text_stats for those tasks, we can still have top level buckets for count and for the consistency/symmetry with what we do for the semantic_text supporting tasks. What do you reckon?

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 have some suggestions about how to simplify the implementation

Comment on lines 55 to 59
private final boolean isCompatibleWithSemanticText;

TaskType(boolean isCompatibleWithSemanticText) {
this.isCompatibleWithSemanticText = isCompatibleWithSemanticText;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I personally wouldn't modify TaskType directly to add this metadata. We only need it in TransportInferenceUsageAction, I would build a set of task types that need semantic text stats in that class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 632b7cb

}

public ModelStats(String service, TaskType taskType, long count) {
this(service, taskType, count, taskType.isCompatibleWithSemanticText() ? new SemanticTextStats() : null);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be simpler to always set semanticTextStats to null by default. Code paths in TransportInferenceUsageAction can pass in a non-null instance as necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 632b7cb

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.

LGTM! Thanks for the continued iterations on this :)

Copy link
Member

@davidkyle davidkyle left a comment

Choose a reason for hiding this comment

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

LGTM

@dimitris-athanasiou dimitris-athanasiou merged commit 2c20c49 into elastic:main Sep 30, 2025
34 checks passed
@dimitris-athanasiou dimitris-athanasiou deleted the usage-for-semantic-text branch September 30, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :ml Machine learning :Search Foundations/Search Catch all for Search Foundations :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:ML Meta label for the ML team Team:Search - Relevance The Search organization Search Relevance team Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants