Skip to content

fix: CohereRanker reordered the top_k fallback to happen after validation - #3747

Merged
davidsbatista merged 1 commit into
mainfrom
fix/cohere-ranker-top-k-zero
Aug 10, 2026
Merged

fix: CohereRanker reordered the top_k fallback to happen after validation#3747
davidsbatista merged 1 commit into
mainfrom
fix/cohere-ranker-top-k-zero

Conversation

@davidsbatista

@davidsbatista davidsbatista commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

  • Added init-time top_k <= 0 validation
  • Reordered _prepare_cohere_input_docs (shared by run/run_async) to validate before falling back.

How did you test it?

  • Fixed 3 pre-existing tests that constructed CohereRanker(top_k=-2/0) outside a pytest.raises block, those would now fail at construction time since init validates.
  • Added test_run_zero_topk_does_not_fall_back_to_instance_topk and its async counterpart, the exact swallowed-fallback scenario, with a non-default instance top_k=5.

Checklist

@github-actions github-actions Bot added integration:cohere type:documentation Improvements or additions to documentation labels Aug 7, 2026
@davidsbatista
davidsbatista marked this pull request as ready for review August 7, 2026 16:20
@davidsbatista
davidsbatista requested a review from a team as a code owner August 7, 2026 16:20
@davidsbatista
davidsbatista requested review from julian-risch and removed request for a team August 7, 2026 16:20
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Coverage report (cohere)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/cohere/src/haystack_integrations/components/rankers/cohere
  ranker.py
Project Total  

This report was generated by python-coverage-comment-action

@davidsbatista
davidsbatista merged commit 9e09ac9 into main Aug 10, 2026
20 checks passed
@davidsbatista
davidsbatista deleted the fix/cohere-ranker-top-k-zero branch August 10, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:cohere type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants