opensearch-java
opensearch-java copied to clipboard
[FEATURE] Support Boosting for Neural Query
Is your feature request related to a problem?
A clear and concise description of what the problem is, e.g. I'm always frustrated when [...]. Currently, when using semantic search I have an issue where it perform poorly over exact keyword search with boosting for situations where I would like to artificially boost certain indices due to businees goals.
Sample Output:
{
"took": 29,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 28,
"relation": "eq"
},
"max_score": 0.66891545,
"hits": [
{
"_index": "A",
"_id": "A-hjHkg4JVoxyrjVaY1T1fC",
"_score": 0.66891545,
},
{
"_index": "A",
"_id": "A-4IIkZsGqs6AAGNJBPxFG2q",
"_score": 0.66891545,
},
{
"_index": "A",
"_id": "A-PrFcKYXMGHTF6DSZ15zxw",
"_score": 0.6600258,
},
{
"_index": "B",
"_id": "B-ppZ_YYBf08C9I8emn4W",
"_score": 0.6593717,
},
{
"_index": "A",
"_id": "A-55mffVK1TqNteVpb6mri5d",
"_score": 0.659091,
}
]
}
}
In this scenario I would like to apply a constant boost of 0.1
to the _score
of index B
.
I tried doing it within the Java Client like so:
NeuralQuery neuralQuery = new NeuralQuery.Builder()
.field(...)
.queryText(...)
.modelId(MODEL_ID)
.k(KNN_TOP_K)
.build();
Query query = new Query.Builder()
.neural(neuralQuery)
.build();
List<Map<String, Double>> indicesToBoost = List.of(Map.of(
"B", 0.1
));
var searchResponse = openSearchJavaClient.search(
s -> s.index(UniversalSearchCategory.SEMANTIC_OFFERS.getIndexName())
.from(param.getOffset())
.size(param.getLimit())
.sort(sortOptions)
.query(query)
.source(sourceConfig)
.indicesBoost(indicesToBoost)
, Object.class
);
But the scores do not get boosted at all.
What solution would you like?
A clear and concise description of what you want to happen.
I would like to see the score of the index B
increase by 0.1
.
{
"_index": "B",
"_id": "B-ppZ_YYBf08C9I8emn4W",
"_score": 0.7593717,
}
What alternatives have you considered?
A clear and concise description of any alternative solutions or features you've considered.
Do you have any additional context?
Add any other context or screenshots about the feature request here.