Skip to content

Support sub query raw scores in Hybrid Search Response #1369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

owaiskazi19
Copy link
Member

@owaiskazi19 owaiskazi19 commented Jun 3, 2025

Description

Support sub query raw scores in Hybrid Search Response through getFetchSubPhases extension point.
Also, added a small improvement for RRF processors while working on this.

Flag to enable sub query scores while creating the pipeline

{
  "description": "Post processor for hybrid search",
  "phase_results_processors": [
    {
      "normalization-processor": {
        "normalization": {
          "technique": "z_score"
        },
        "sub-query-scores": true,
        "combination": {
          "technique": "arithmetic_mean",
          "parameters": {
            "weights": [
              0.3,
              0.4,
              0.3
            ]
          }
        }
      }
    }
  ]
}

Response

"hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": 0.016393442,
        "hits": [
            {
                "_index": "my-nlp-index1",
                "_id": "3",
                "_score": 0.016393442,
                "_source": {
                    "passage_text": "zoo keeper here",
                    "id": "s3"
                },
                "fields": {
                    "hybridization_sub_query_scores": [
                        0.0,
                        0.0,
                        0.26156494
                    ]
                }
            },
            {
                "_index": "my-nlp-index1",
                "_id": "1",
                "_score": 0.016393442,
                "_source": {
                    "passage_text": "hello hi what",
                    "id": "s1"
                },
                "fields": {
                    "hybridization_sub_query_scores": [
                        0.13076457,
                        0.0,
                        0.0
                    ]
                }
            }
        ]
    }
}

Related Issues

Resolves #1294, #1180 & #1419

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

) {
for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
float normalizedScore = calculateNormalizedScore(Arrays.asList(topDocs.scoreDocs).indexOf(scoreDoc));
Copy link
Member Author

Choose a reason for hiding this comment

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

This was causing O(N2), changed it to index based reference

@owaiskazi19 owaiskazi19 force-pushed the hybrid-scores branch 3 times, most recently from 07b39e7 to 2eb0d1f Compare June 11, 2025 08:34
@owaiskazi19 owaiskazi19 force-pushed the hybrid-scores branch 3 times, most recently from bc183c6 to 70ec7ec Compare June 23, 2025 17:05
@owaiskazi19 owaiskazi19 force-pushed the hybrid-scores branch 5 times, most recently from 63a54ff to 09664ab Compare July 1, 2025 22:03
@owaiskazi19 owaiskazi19 changed the title [DRAFT] Support sub query raw scores in Hybrid Search Response Support sub query raw scores in Hybrid Search Response Jul 2, 2025
@owaiskazi19 owaiskazi19 marked this pull request as ready for review July 2, 2025 20:26
Copy link
Member

@vibrantvarun vibrantvarun left a comment

Choose a reason for hiding this comment

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

Great job @owaiskazi19 on creating the logic for capturing subquery scores.

@@ -58,6 +59,10 @@ public static boolean isClusterOnOrAfterMinReqVersionForStatCategoryFiltering()
return NeuralSearchClusterUtil.instance().getClusterMinVersion().onOrAfter(MINIMAL_SUPPORTED_VERSION_STATS_CATEGORY_FILTERING);
}

public static boolean isClusterOnOrAfterMinReqVersionForSubQuerySupport() {
Copy link
Member

Choose a reason for hiding this comment

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

We need one BWC test to validate this condition does not break anything.

import java.util.Map;

/**
* Registry to store hybrid score for each search context
Copy link
Member

Choose a reason for hiding this comment

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

As per my understanding, there is only one searchcontext per search. Therefore, can we reframe this javadoc in a specific way like "Registry to store hybrid score for each document" ?

Copy link
Member

Choose a reason for hiding this comment

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

In the later part, I see we are using searchPhaseContext. SearchPhaseContext can be multiple like after the QP , then after the FP as well.

@Override
public FetchSubPhaseProcessor getProcessor(FetchContext fetchContext) throws IOException {
// Check if inner hits are present
boolean hasInnerHits = fetchContext.innerHits() != null && !fetchContext.innerHits().getInnerHits().isEmpty();
Copy link
Member

Choose a reason for hiding this comment

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

nit: Do we really need to check !fetchContext.innerHits().getInnerHits().isEmpty() as well?

Copy link
Member

Choose a reason for hiding this comment

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

I am assuming if fetchContext.innerHits is true then it should work?

Copy link
Member Author

Choose a reason for hiding this comment

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

fetchContext.innerHits() returns an InnerHitsContext object — which may be non-null, but contain no inner hits. Then hasInnerHits will be true even if there are no actual inner hits to process


if (subqueryScores != null) {
// Add it as a field rather than modifying _source
List<Object> hybridScores = new ArrayList<>(subqueryScores.length);
Copy link
Member

Choose a reason for hiding this comment

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

+1

// Check for all the conditions
boolean shouldAddHybridScores = subqueryScores != null
&& documentFields.containsKey(SUB_QUERY_SCORES_NAME) == false
&& isClusterOnOrAfterMinReqVersionForSubQuerySupport()
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this whole check should be wrapped under

if (isClusterOnOrAfterMinReqVersionForSubQuerySupport() && hasInnerHits ==false )

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't it the same thing checking condtion1 && condition2 and then condition3 && condition4 or all together like condtion1 && condition2 && condtion3 && condtion4 ?


// Check for all the conditions
boolean shouldAddHybridScores = subqueryScores != null
&& documentFields.containsKey(SUB_QUERY_SCORES_NAME) == false
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a BWC test when out of 3 nodes 1 node is running on newer version and other 2 are running older version. Then request for hybridization scores.

Copy link
Member

@martin-gaievski martin-gaievski left a comment

Choose a reason for hiding this comment

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

Added few comments after recently added commits

@owaiskazi19 owaiskazi19 force-pushed the hybrid-scores branch 4 times, most recently from d7173ec to 2ca0411 Compare July 17, 2025 22:08
@owaiskazi19 owaiskazi19 reopened this Jul 18, 2025
Copy link

codecov bot commented Jul 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (8c5fb57) to head (2ca0411).
Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #1369       +/-   ##
============================================
- Coverage     79.95%       0   -79.96%     
============================================
  Files           160       0      -160     
  Lines          8584       0     -8584     
  Branches       1396       0     -1396     
============================================
- Hits           6863       0     -6863     
+ Misses         1186       0     -1186     
+ Partials        535       0      -535     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@owaiskazi19
Copy link
Member Author

#1416 is failing most of the times

@heemin32
Copy link
Collaborator

I can help with retrying only failed tests.

@owaiskazi19
Copy link
Member Author

Will run benchmarking again after #1457 is merged

Signed-off-by: Owais <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Individual scores from queries in hybrid qery
6 participants