Skip to content
11 changes: 11 additions & 0 deletions docs/changelog/128854.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pr: 128854
summary: Mark token pruning for sparse vector as GA
area: Machine Learning
type: feature
issues: []
highlight:
title: Mark Token Pruning for Sparse Vector as GA
body: |-
Token pruning for sparse_vector queries has been live since 8.13 as tech preview.
As of 8.19.0 and 9.1.0, this is now generally available.
notable: true
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,36 @@ GET _search
`query_vector`
: (Optional, dictionary) A dictionary of token-weight pairs representing the precomputed query vector to search. Searching using this query vector will bypass additional inference. Only one of `inference_id` and `query_vector` is allowed.

`prune`
: (Optional, boolean) [preview] Whether to perform pruning, omitting the non-significant tokens from the query to improve query performance. If `prune` is true but the `pruning_config` is not specified, pruning will occur but default values will be used. Default: false.
`prune` {applies_to}`stack: preview 9.0, ga 9.1`
Copy link
Member

Choose a reason for hiding this comment

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

Wait, we're not shipping this to 9.0.x right? This seems wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this tag just makes sure to specify that this was in preview for 9.0.x, but now GA for 9.1... @leemthompo - this was your suggestion from earlier - is my understanding correct? Or should the preview 9.0 part just be removed?

Copy link
Member

@kderusso kderusso Jun 23, 2025

Choose a reason for hiding this comment

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

But then it would be when it was released which was prior to 9.0? Or since these docs are 9.0+ only? This is really confusing as a docs structure, sorry :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question - I'll defer to @leemthompo as he suggested that tag ;)

Copy link
Contributor

@leemthompo leemthompo Jun 24, 2025

Choose a reason for hiding this comment

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

Or since these docs are 9.0+ only? This is really confusing as a docs structure, sorry :(

Yup the the 9.x docs don't talk about 8.x and below in the applies_to metadata. So yeah it doesn't mean "this feature was added in 9.0 in tech preview", it just means "This feature was tech preview in 9.0".

The actual output on the page will have more helpful tooltips and stuff in the future, but yeah the raw metadata is a bit ambiguous. It's also hard to get used to the "cumulative docs" paradigm but we need it because this page applies to both 9.0 and 9.1 (and beyond as time goes on), so in order to specify when something went GA in 9.1, we need to also be able to specify it was preview in 9.0. Because there's no 9.0 page to switch back to.

: (Optional, boolean) Whether to perform pruning, omitting the non-significant tokens from the query to improve query performance. If `prune` is true but the `pruning_config` is not specified, pruning will occur but default values will be used. Default: false.

`pruning_config`
: (Optional, object) [preview] Optional pruning configuration. If enabled, this will omit non-significant tokens from the query in order to improve query performance. This is only used if `prune` is set to `true`. If `prune` is set to `true` but `pruning_config` is not specified, default values will be used.
`pruning_config` {applies_to}`stack: preview 9.0, ga 9.1`
: (Optional, object) Optional pruning configuration. If enabled, this will omit non-significant tokens from the query in order to improve query performance. This is only used if `prune` is set to `true`. If `prune` is set to `true` but `pruning_config` is not specified, default values will be used.

Parameters for `pruning_config` are:

`tokens_freq_ratio_threshold`
: (Optional, integer) [preview] Tokens whose frequency is more than `tokens_freq_ratio_threshold` times the average frequency of all tokens in the specified field are considered outliers and pruned. This value must between 1 and 100. Default: `5`.
: (Optional, integer) Tokens whose frequency is more than `tokens_freq_ratio_threshold` times the average frequency of all tokens in the specified field are considered outliers and pruned. This value must between 1 and 100. Default: `5`.

`tokens_weight_threshold`
: (Optional, float) [preview] Tokens whose weight is less than `tokens_weight_threshold` are considered insignificant and pruned. This value must be between 0 and 1. Default: `0.4`.
: (Optional, float) Tokens whose weight is less than `tokens_weight_threshold` are considered insignificant and pruned. This value must be between 0 and 1. Default: `0.4`.

`only_score_pruned_tokens`
: (Optional, boolean) [preview] If `true` we only input pruned tokens into scoring, and discard non-pruned tokens. It is strongly recommended to set this to `false` for the main query, but this can be set to `true` for a rescore query to get more relevant results. Default: `false`.
: (Optional, boolean) If `true` we only input pruned tokens into scoring, and discard non-pruned tokens. It is strongly recommended to set this to `false` for the main query, but this can be set to `true` for a rescore query to get more relevant results. Default: `false`.

::::{note}
The default values for `tokens_freq_ratio_threshold` and `tokens_weight_threshold` were chosen based on tests using ELSERv2 that provided the most optimal results.
::::

When token pruning is applied, non-significant tokens will be pruned from the query.
Non-significant tokens can be defined as tokens that meet both of the following criteria:
* The token appears much more frequently than most tokens, indicating that it is a very common word and may not benefit the overall search results much.
* The weight/score is so low that the token is likely not very relevant to the original term

Both the token frequency threshold and weight threshold must show the token is non-significant in order for the token to be pruned.
This ensures that:
* The tokens that are kept are frequent enough and have significant scoring.
* Very infrequent tokens that may not have as high of a score are removed.

## Example ELSER query [sparse-vector-query-example]

Expand Down Expand Up @@ -198,7 +206,7 @@ GET my-index/_search

## Example ELSER query with pruning configuration and rescore [sparse-vector-query-with-pruning-config-and-rescore-example]

The following is an extension to the above example that adds a [preview] pruning configuration to the `sparse_vector` query. The pruning configuration identifies non-significant tokens to prune from the query in order to improve query performance.
The following is an extension to the above example that adds a pruning configuration to the `sparse_vector` query. The pruning configuration identifies non-significant tokens to prune from the query in order to improve query performance.

Token pruning happens at the shard level. While this should result in the same tokens being labeled as insignificant across shards, this is not guaranteed based on the composition of each shard. Therefore, if you are running `sparse_vector` with a `pruning_config` on a multi-shard index, we strongly recommend adding a [Rescore filtered search results](/reference/elasticsearch/rest-apis/filter-search-results.md#rescore) function with the tokens that were originally pruned from the query. This will help mitigate any shard-level inconsistency with pruned tokens and provide better relevance overall.

Expand Down
Loading