Skip to content

MOD-10798: Support K Ratio argument in FT.HYBRID vector query#8227

Merged
nafraf merged 29 commits into
masterfrom
nafraf_mod-10798
Feb 16, 2026
Merged

MOD-10798: Support K Ratio argument in FT.HYBRID vector query#8227
nafraf merged 29 commits into
masterfrom
nafraf_mod-10798

Conversation

@nafraf

@nafraf nafraf commented Jan 30, 2026

Copy link
Copy Markdown
Collaborator

Describe the changes in the pull request

Support K Ratio argument in FT.HYBRID vector query, as part of KNN clause.

[KNN <count-tokens>]
   K <topk-k>
   [EF_RUNTIME <ef-value>]
   [YIELD_DISTANCE_AS <distance_field>]
   [SHARD_K_RATIO <shard-k-ratio-value>]

Main objects this PR modified

  1. ...

Mark if applicable

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

Release Notes

  • This PR requires release notes
  • This PR does not require release notes

Note

Medium Risk
Touches hybrid parsing and distributed command construction, which can affect query correctness/performance in clustered execution. Risk is mitigated by explicit validation and extensive new unit/integration tests.

Overview
Adds support for the new optional SHARD_K_RATIO argument (since 8.6.1) in FT.HYBRID KNN queries, allowing distributed executions to request fewer candidates per shard (while still guaranteeing enough results overall).

The coordinator now computes an effective per-shard K from the ratio and shard count, rewrites the distributed VSIM KNN K value accordingly, and makes shard-count access thread-safe by capturing it in the concurrent command context. Validation and duplicate detection for SHARD_K_RATIO (and improved duplicate handling for YIELD_SCORE_AS) are added, with expanded C++ and new Python tests covering parsing, error cases, and cluster profile behavior.

Written by Cursor Bugbot for commit 3436088. This will update automatically on new commits. Configure here.

@nafraf nafraf marked this pull request as ready for review January 30, 2026 22:56
Comment thread src/coord/hybrid/dist_hybrid.c Outdated
@codecov

codecov Bot commented Jan 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.89%. Comparing base (311afdb) to head (3436088).
⚠️ Report is 48 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8227      +/-   ##
==========================================
- Coverage   83.00%   82.89%   -0.11%     
==========================================
  Files         389      414      +25     
  Lines       57556    58815    +1259     
  Branches    15708    16873    +1165     
==========================================
+ Hits        47772    48757     +985     
- Misses       9625     9877     +252     
- Partials      159      181      +22     
Flag Coverage Δ
flow 84.24% <97.05%> (+<0.01%) ⬆️
unit 51.07% <80.88%> (+0.65%) ⬆️

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.

@nafraf nafraf marked this pull request as draft January 31, 2026 06:53
@nafraf nafraf marked this pull request as ready for review January 31, 2026 19:17
@nafraf nafraf requested a review from oshadmi January 31, 2026 21:02
@oshadmi oshadmi requested a review from Itzikvaknin February 2, 2026 13:03
Comment thread src/hybrid/vector_query_utils.h Outdated
Comment thread src/shard_window_ratio.c Outdated
Comment thread tests/cpptests/test_cpp_parse_hybrid.cpp Outdated
Comment thread src/coord/hybrid/dist_hybrid.c Outdated
Comment thread tests/cpptests/coord_tests/test_cpp_hybrid_build_mr_cmd.cpp Outdated
Comment thread tests/pytests/test_hybrid_shard_k_ratio.py Outdated

@Itzikvaknin Itzikvaknin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, left a few comments

@nafraf nafraf marked this pull request as draft February 3, 2026 03:39
@nafraf nafraf marked this pull request as ready for review February 3, 2026 03:39
Comment thread tests/pytests/test_hybrid_shard_k_ratio.py
@nafraf nafraf requested a review from Itzikvaknin February 4, 2026 07:08
Comment thread tests/cpptests/coord_tests/test_cpp_hybrid_build_mr_cmd.cpp
Comment thread src/coord/hybrid/dist_hybrid.c Outdated
Comment thread src/coord/hybrid/dist_hybrid.c
Comment thread src/hybrid/parse_hybrid.c Outdated
if (parseYieldScoreClause(ac, pvd, status) != REDISMODULE_OK) {
goto error;
// Check for optional YIELD_SCORE_AS detecting duplicate arguments
while (!AC_IsAtEnd(ac)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this while loop required?

@nafraf nafraf Feb 4, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It detects duplicate YIELD_SCORE_AS, in this example:

...
"SEARCH", "hello",
 "VSIM", "@vector", "$BLOB",
      "KNN", "2", "K", "10",
      "YIELD_SCORE_AS", "dist1", "YIELD_SCORE_AS", "dist2",
 ...

Without the loop, the error is reported as: "YIELD_SCORE_AS: Unknown argument"
With the loop: "Duplicate YIELD_SCORE_AS argument"

@Itzikvaknin Itzikvaknin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

a few minor comments

@nafraf nafraf requested a review from Itzikvaknin February 4, 2026 13:03
Comment thread src/concurrent_ctx.c
Comment thread tests/cpptests/coord_tests/test_cpp_hybrid_build_mr_cmd.cpp Outdated
Comment thread commands.json
Comment thread src/shard_window_ratio.c Outdated
Comment thread tests/pytests/test_hybrid_shard_k_ratio.py

@Itzikvaknin Itzikvaknin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Minor comments

Comment thread tests/cpptests/coord_tests/test_cpp_hybrid_build_mr_cmd.cpp Outdated
Comment thread tests/cpptests/test_cpp_parse_hybrid.cpp
@sonarqubecloud

Copy link
Copy Markdown

@nafraf nafraf added this pull request to the merge queue Feb 16, 2026
Merged via the queue into master with commit d7ac7d3 Feb 16, 2026
50 checks passed
@nafraf nafraf deleted the nafraf_mod-10798 branch February 16, 2026 23:15
@nafraf

nafraf commented Feb 17, 2026

Copy link
Copy Markdown
Collaborator Author

/backport

@redisearch-backport-pull-request

Copy link
Copy Markdown
Contributor

Backport failed for 8.4, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 8.4
git worktree add -d .worktree/backport-8227-to-8.4 origin/8.4
cd .worktree/backport-8227-to-8.4
git switch --create backport-8227-to-8.4
git cherry-pick -x d7ac7d333dfa3824f925094ad585c65560294dd4

@redisearch-backport-pull-request

Copy link
Copy Markdown
Contributor

Backport failed for 8.6, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 8.6
git worktree add -d .worktree/backport-8227-to-8.6 origin/8.6
cd .worktree/backport-8227-to-8.6
git switch --create backport-8227-to-8.6
git cherry-pick -x d7ac7d333dfa3824f925094ad585c65560294dd4

nafraf added a commit that referenced this pull request Feb 17, 2026
nafraf added a commit that referenced this pull request Feb 17, 2026
github-merge-queue Bot pushed a commit that referenced this pull request Feb 21, 2026
…tor query (#8227) (#8399)

MOD-10798: Support K Ratio argument in FT.HYBRID vector query (#8227)
(cherry picked from commit d7ac7d3)
github-merge-queue Bot pushed a commit that referenced this pull request Feb 23, 2026
…tor query (#8400)

* [8.4] MOD-14094, MOD-10798: Support K Ratio argument in FT.HYBRID vector query (#8227)
(cherry picked from commit d7ac7d3)

* Fix "since" field in commands.json

Co-authored-by: Omer Shadmi <[email protected]>

* Update "since" field for SHARD_K_RATIO in FT.HYBRID command to 8.4.7

---------

Co-authored-by: Omer Shadmi <[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.

3 participants