Skip to content

Commit b85abda

Browse files
fix for sparse vector query boost
1 parent 370931d commit b85abda

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/queries/SemanticSparseVectorQueryRewriteInterceptor.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,21 @@ protected QueryBuilder buildCombinedInferenceAndNonInferenceQuery(
101101
private QueryBuilder buildNestedQueryFromSparseVectorQuery(QueryBuilder queryBuilder, String searchInferenceId) {
102102
assert (queryBuilder instanceof SparseVectorQueryBuilder);
103103
SparseVectorQueryBuilder sparseVectorQueryBuilder = (SparseVectorQueryBuilder) queryBuilder;
104+
SparseVectorQueryBuilder newSparseVectorQueryBuilder = new SparseVectorQueryBuilder(
105+
SemanticTextField.getEmbeddingsFieldName(sparseVectorQueryBuilder.getFieldName()),
106+
sparseVectorQueryBuilder.getQueryVectors(),
107+
(sparseVectorQueryBuilder.getInferenceId() == null && sparseVectorQueryBuilder.getQuery() != null)
108+
? searchInferenceId
109+
: sparseVectorQueryBuilder.getInferenceId(),
110+
sparseVectorQueryBuilder.getQuery(),
111+
sparseVectorQueryBuilder.shouldPruneTokens(),
112+
sparseVectorQueryBuilder.getTokenPruningConfig()
113+
);
114+
newSparseVectorQueryBuilder.boost(sparseVectorQueryBuilder.boost());
115+
newSparseVectorQueryBuilder.queryName(sparseVectorQueryBuilder.queryName());
104116
return QueryBuilders.nestedQuery(
105117
SemanticTextField.getChunksFieldName(sparseVectorQueryBuilder.getFieldName()),
106-
new SparseVectorQueryBuilder(
107-
SemanticTextField.getEmbeddingsFieldName(sparseVectorQueryBuilder.getFieldName()),
108-
sparseVectorQueryBuilder.getQueryVectors(),
109-
(sparseVectorQueryBuilder.getInferenceId() == null && sparseVectorQueryBuilder.getQuery() != null)
110-
? searchInferenceId
111-
: sparseVectorQueryBuilder.getInferenceId(),
112-
sparseVectorQueryBuilder.getQuery(),
113-
sparseVectorQueryBuilder.shouldPruneTokens(),
114-
sparseVectorQueryBuilder.getTokenPruningConfig()
115-
),
118+
newSparseVectorQueryBuilder,
116119
ScoreMode.Max
117120
);
118121
}

0 commit comments

Comments
 (0)