Skip to content

MOD-10047: Prepare Hybrid Parsing For Hybrid Cursors#6736

Closed
kei-nan wants to merge 9 commits intofeature-RRFfrom
rrf_jk_prepare_hybrid_parsing_for_cursors
Closed

MOD-10047: Prepare Hybrid Parsing For Hybrid Cursors#6736
kei-nan wants to merge 9 commits intofeature-RRFfrom
rrf_jk_prepare_hybrid_parsing_for_cursors

Conversation

@kei-nan
Copy link
Collaborator

@kei-nan kei-nan commented Aug 27, 2025

Reorganize the parsing of a hybrid request so a hybrid request can live without a pipeline.

A clear and concise description of what the PR is solving, including:

  1. Current: Various subquery pipeline related code is done in hybrid merger construction
  2. Change: Since we might not have a merger we need the pipeline changes to happen in the parsing level, this also meant heavilty changing the cpp tests that relied on the hybrid merger pipeline construction.(we use the parse function instead)
  3. Outcome: Cleaner code.

Main objects this PR modified

  1. Hybrid Request

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

@kei-nan kei-nan requested review from Itzikvaknin and nafraf August 27, 2025 13:25
@kei-nan kei-nan self-assigned this Aug 27, 2025
@codecov
Copy link

codecov bot commented Aug 28, 2025

Codecov Report

❌ Patch coverage is 70.55215% with 48 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feature-RRF@cd47772). Learn more about missing BASE report.

⚠️ Current head 84e3107 differs from pull request most recent head b09b749

Please upload reports for the commit b09b749 to get more accurate results.

Files with missing lines Patch % Lines
src/hybrid/hybrid_exec.c 45.33% 41 Missing ⚠️
src/hybrid/hybrid_request.c 92.10% 3 Missing ⚠️
src/module.c 60.00% 2 Missing ⚠️
src/aggregate/aggregate_request.c 83.33% 1 Missing ⚠️
src/hybrid/parse_hybrid.c 97.29% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##             feature-RRF    #6736   +/-   ##
==============================================
  Coverage               ?   88.69%           
==============================================
  Files                  ?      261           
  Lines                  ?    42760           
  Branches               ?     3630           
==============================================
  Hits                   ?    37925           
  Misses                 ?     4786           
  Partials               ?       49           
Flag Coverage Δ
flow 80.91% <63.80%> (?)
unit 49.08% <46.62%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@kei-nan kei-nan requested a review from Copilot August 28, 2025 13:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors hybrid request parsing to move pipeline-related code from the merger construction phase to the parsing level, enabling hybrid requests to exist without requiring a merger. The primary motivation is to prepare for future cursor support in hybrid search by decoupling request construction from pipeline building.

Key changes include:

  • Reorganized parsing function to return structured command context rather than complete HybridRequest
  • Moved LOAD step processing and implicit sorting logic from merger to parser
  • Updated test suite to use new parsing interface instead of merger-based construction

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/cpptests/test_cpp_parsed_hybrid_pipeline.cpp New test file using parse-then-build pattern instead of merger construction
tests/cpptests/test_cpp_parse_hybrid.cpp Updated to use new ParseHybridCommandCtx structure and parsing interface
tests/cpptests/test_cpp_hybrid_defaults.cpp Modified to work with restructured parsing context and parameter handling
tests/cpptests/test_cpp_hybrid.cpp Simplified to basic HybridRequest creation test, removing pipeline tests
src/pipeline/pipeline_construction.h Removed processLoadStep function declaration
src/pipeline/pipeline_construction.c Updated comment about scorer creation conditions
src/module.c Split hybrid command handler into internal/external variants
src/hybrid/parse_hybrid.h Added ParseHybridCommandCtx structure and updated function signature
src/hybrid/parse_hybrid.c Major refactor moving pipeline logic to parsing phase
src/hybrid/hybrid_request.h Updated HybridRequest structure and added new pipeline building functions
src/hybrid/hybrid_request.c Split pipeline building into depletion and merge phases
src/hybrid/hybrid_exec.h Updated function signatures and added cursor support
src/hybrid/hybrid_exec.c Refactored execution flow to work with new parsing structure
src/aggregate/aggregate_request.c Enhanced SORTBY 0 handling for hybrid tail queries
src/aggregate/aggregate.h Added QEXEC_F_NO_SORT flag for explicit no-sorting behavior
Comments suppressed due to low confidence (1)

tests/cpptests/test_cpp_parse_hybrid.cpp:1

  • Same issue as previous test - 'COMBINE' should not appear before 'SORTBY'. The command structure is incorrect. It should be: 'SEARCH', 'hello', 'VSIM', '@vector', TEST_BLOB_DATA, 'SORTBY', '1', '@score'
/*

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +742 to +744
if (hybridParams->scoringCtx) {
HybridScoringContext_Free(hybridParams->scoringCtx);
rm_free(hybridParams);
}

if (tailPipeline) {
Pipeline_Clean(tailPipeline);
rm_free(tailPipeline);
hybridParams->scoringCtx = NULL;
Copy link

Copilot AI Aug 28, 2025

Choose a reason for hiding this comment

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

The error handling only frees the scoringCtx but doesn't clean up other resources that may have been allocated during parsing, such as vector query parameters or other contexts that could have been created before the error occurred. This could lead to memory leaks.

Copilot uses AI. Check for mistakes.
@kei-nan kei-nan changed the title Prepare Hybrid Parsing For Hybrid Cursors MOD-10047: Prepare Hybrid Parsing For Hybrid Cursors Aug 28, 2025
StrongRef_Release(sync_ref);
array_free(depleters);
return rc;
return NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure this won't cause some side-effects? Callee level

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pretty sure,
currently it is only called in HybridRequest_BuildPipeline and it handles it correctly.

RedisModuleCtx *ctx, RedisSearchCtx *sctx, QueryError *status,
bool internal) {
// Build the pipeline and execute
hreq->reqflags = hybridParams->aggregationParams.common.reqflags;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider moving this to HybridRequest_BuildPipeline

Comment on lines +1205 to +1210
int RSShardedHybridCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
return hybridCommandHandler(ctx, argv, argc, true);
}

int RSClientHybridCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
return hybridCommandHandler(ctx, argv, argc, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider different names - like internal-external

Copy link
Collaborator

@Itzikvaknin Itzikvaknin left a comment

Choose a reason for hiding this comment

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

LGTM, see few comments

@kei-nan kei-nan requested a review from Itzikvaknin September 1, 2025 08:23
AC_Advance(ac); // Advance without adding SortBy step to the plan
*papCtx->reqflags |= QEXEC_F_NO_SORT;
} else {
QueryError_SetError(status, QUERY_EPARSEARGS, "SORTBY 0 is not supported in this type of query");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have test for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, lets have a also a flow test for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants