Skip to content

Commit 6d9c9c8

Browse files
authored
Add token pruning to clients for text expansion query (#2370)
* Add pruning config to text_expansion query * Add weighted tokens query * Linting * PR feedback - float to int * PR feedback - omit value * Revise comment * PR feedback, remove additional property * Linting
1 parent 5c8fed5 commit 6d9c9c8

File tree

6 files changed

+257
-9
lines changed

6 files changed

+257
-9
lines changed

output/schema/schema.json

Lines changed: 163 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/typescript/types.ts

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specification/_types/query_dsl/TextExpansionQuery.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@
1717
* under the License.
1818
*/
1919

20+
import { TokenPruningConfig } from './TokenPruningConfig'
2021
import { QueryBase } from './abstractions'
2122

2223
export class TextExpansionQuery extends QueryBase {
2324
/** The text expansion NLP model to use */
2425
model_id: string
2526
/** The query text */
2627
model_text: string
28+
/** Token pruning configurations
29+
* @availability stack since=8.13.0 stability=experimental
30+
* @availability serverless stability=experimental
31+
*/
32+
pruning_config?: TokenPruningConfig
2733
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { float, integer } from '@_types/Numeric'
21+
22+
export class TokenPruningConfig {
23+
/** Tokens whose frequency is more than this threshold times the average frequency of all tokens in the specified field are considered outliers and pruned.
24+
* @server_default 5
25+
*/
26+
tokens_freq_ratio_threshold?: integer
27+
/** Tokens whose weight is less than this threshold are considered nonsignificant and pruned.
28+
* @server_default 0.4
29+
*/
30+
tokens_weight_threshold?: float
31+
/** Whether to only score pruned tokens, vs only scoring kept tokens.
32+
* @server_default false
33+
*/
34+
only_score_pruned_tokens?: boolean
35+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { AdditionalProperty } from '@spec_utils/behaviors'
21+
import { TokenPruningConfig } from './TokenPruningConfig'
22+
import { QueryBase } from './abstractions'
23+
import { Field, FieldValue } from '@_types/common'
24+
import { Dictionary } from '@spec_utils/Dictionary'
25+
import { float } from '@_types/Numeric'
26+
27+
export class WeightedTokensQuery extends QueryBase {
28+
/** The tokens representing this query */
29+
tokens: Dictionary<string, float>
30+
/** Token pruning configurations */
31+
pruning_config?: TokenPruningConfig
32+
}

0 commit comments

Comments
 (0)