Skip to content

Conversation

atris
Copy link
Contributor

@atris atris commented Jul 22, 2025

Resolves #17593

Problem

Plugins implementing hybrid queries and neural search currently rely on AggregationProcessor workarounds to inject custom CollectorManager implementations. This approach is fragile and breaks when the aggregation system changes.

Solution

Add extension points directly in QueryPhase around the actual score collection operation:

  • QueryPhaseExtension interface with beforeScoreCollection() and afterScoreCollection() methods
  • Extension registration via QueryPhaseSearcher.queryPhaseExtensions()
  • Execution in DefaultQueryPhaseSearcher with proper error isolation

Implementation

New interface:

@PublicApi(since = "3.0.0")
public interface QueryPhaseExtension {
    void beforeScoreCollection(SearchContext searchContext);
    void afterScoreCollection(SearchContext searchContext);
}

Extension points placed around:
searcher.search(query, collector) // <- actual score collection

Features:
- Extensions execute before and after score collection in try/finally blocks
- Individual extension failures are logged but don't break search
- Default implementations return empty extension lists (backward compatible)
- Zero overhead when no extensions are registered

Usage

public class HybridQueryPhaseSearcher extends DefaultQueryPhaseSearcher {
    @Override
    public List<QueryPhaseExtension> queryPhaseExtensions() {
        return List.of(new HybridQueryExtension(), new NeuralSearchExtension());
    }
}

Testing

Unit tests verify:

  • Interface functionality
  • Extension registration
  • Integration with search execution
  • Error handling and isolation

No existing functionality affected.

@github-actions github-actions bot added enhancement Enhancement or improvement to existing feature or request Search Search query, autocomplete ...etc labels Jul 22, 2025
@atris
Copy link
Contributor Author

atris commented Jul 22, 2025

@getsaurabh02

Copy link
Contributor

❌ Gradle check result for da66380: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@owaiskazi19
Copy link
Member

@atris now that we have a way to inject QueryCollectorContext in core, would that solve your need? #18278

Copy link
Contributor

❌ Gradle check result for 0a0f121: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Atri Sharma <[email protected]>
@atris atris closed this Jul 31, 2025
@atris atris reopened this Jul 31, 2025
Copy link
Contributor

✅ Gradle check result for 76fd57b: SUCCESS

@owaiskazi19
Copy link
Member

owaiskazi19 commented Jul 31, 2025

@bugmakerrrrrr can you take another look and we can get this in?

Signed-off-by: Atri Sharma <[email protected]>
@atris
Copy link
Contributor Author

atris commented Aug 1, 2025

@bugmakerrrrrr Updated, please see and let me know

Signed-off-by: Atri Sharma <[email protected]>
Copy link
Contributor

github-actions bot commented Aug 1, 2025

❌ Gradle check result for bfad37b: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Atri Sharma <[email protected]>
@atris
Copy link
Contributor Author

atris commented Aug 1, 2025

@bugmakerrrrrr Please review.

Copy link
Contributor

@bugmakerrrrrr bugmakerrrrrr left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @atris

Copy link
Contributor

github-actions bot commented Aug 1, 2025

✅ Gradle check result for d4a5007: SUCCESS

@andrross andrross merged commit eda3a48 into opensearch-project:main Aug 1, 2025
30 of 31 checks passed
sunqijun1 pushed a commit to sunqijun1/OpenSearch that referenced this pull request Aug 4, 2025
…tion of Scores in QueryPhase (opensearch-project#18814)

Signed-off-by: Atri Sharma <[email protected]>
Signed-off-by: sunqijun.jun <[email protected]>
tandonks pushed a commit to tandonks/OpenSearch that referenced this pull request Aug 5, 2025
vinaykpud pushed a commit to vinaykpud/OpenSearch that referenced this pull request Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement or improvement to existing feature or request Search Search query, autocomplete ...etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Add extension points for pre/post collecting scores in QueryPhase
5 participants