Skip to content

Commit

Permalink
Return the original all token query if there has no low score token.
Browse files Browse the repository at this point in the history
Signed-off-by: conggguan <[email protected]>
  • Loading branch information
conggguan committed Apr 23, 2024
1 parent 0ac9245 commit 1d28441
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static NeuralSparseQueryBuilder fromXContent(XContentParser parser) throw
throw new IllegalArgumentException(
String.format(
Locale.ROOT,
"[%s] %s field value must be in range (0,1]",
"[%s] %s field value must be in range [0,1]",
NeuralSparseTwoPhaseParameters.NAME.getPreferredName(),
NeuralSparseTwoPhaseParameters.PRUNING_RATIO.getPreferredName()
)
Expand All @@ -266,7 +266,6 @@ public static NeuralSparseQueryBuilder fromXContent(XContentParser parser) throw
)
);
}

return sparseEncodingQueryBuilder;
}

Expand Down Expand Up @@ -346,10 +345,18 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
}
// in the last step we make sure neuralSparseTwoPhaseParameters is not null
float ratio = neuralSparseTwoPhaseParameters.pruning_ratio();
Query allTokenQuery = buildFeatureFieldQueryFromTokens(getAllTokens(), fieldName);
Map<String,Float> lowScoreTokens = getLowScoreTokens(ratio);
// if all token are valid score that we don't need the two-phase optimize, return allTokenQuery.
if (lowScoreTokens.isEmpty()) {
return allTokenQuery;
}
Query highScoreTokenQuery = buildFeatureFieldQueryFromTokens(getHighScoreTokens(ratio), fieldName);
Query lowScoreTokenQuery = buildFeatureFieldQueryFromTokens(lowScoreTokens, fieldName);
return new NeuralSparseQuery(
buildFeatureFieldQueryFromTokens(getAllTokens(), fieldName),
buildFeatureFieldQueryFromTokens(getHighScoreTokens(ratio), fieldName),
buildFeatureFieldQueryFromTokens(getLowScoreTokens(ratio), fieldName),
allTokenQuery,
highScoreTokenQuery,
lowScoreTokenQuery,
neuralSparseTwoPhaseParameters.window_size_expansion()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public final class NeuralSearchSettings {
public static final Setting<Integer> NEURAL_SPARSE_TWO_PHASE_MAX_WINDOW_SIZE = Setting.intSetting(
"plugins.neural_search.neural_sparse.two_phase.max_window_size",
10000,
0,
50,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);
Expand Down

0 comments on commit 1d28441

Please sign in to comment.