Skip to content

fix: respect LLMRanker top_k on fallback - #13051

Open
charan-rathore wants to merge 2 commits into
deepset-ai:mainfrom
charan-rathore:fix/llmranker-fallback-top-k
Open

charan-rathore wants to merge 2 commits into
deepset-ai:mainfrom
charan-rathore:fix/llmranker-fallback-top-k

Conversation

@charan-rathore

Copy link
Copy Markdown

Related Issues

Proposed Changes:

LLMRanker limits successful results to top_k, but returned every input document after generation or parsing failures and invalid queries. Apply the same limit to those fallback results in both run and run_async.

Document order and deduplication stay unchanged. The runtime top_k override still takes precedence. Documentation and a release note explain that fallback output now follows the same limit as successful ranking.

How did you test it?

  • New regression cases: 16 failed and 8 passed before the fix.
  • LLMRanker and LostInTheMiddleRanker suites: 99 passed, 3 live-provider tests skipped.
  • Focused mypy: no issues in the implementation and test files.
  • All applicable pre-commit hooks passed on the five changed files.
  • A real Haystack Pipeline returned one fallback document with top_k=1, synchronously and asynchronously, without an LLM call.

Notes for the reviewer

The seven existing fallback tests with top_k=1 expected both input documents. Those expectations now follow the documented limit. New cases cover generation and parsing failures, empty and non-string queries, duplicate inputs, constructor defaults, runtime overrides, and limits larger than the input list.

This is an intentional result-limit change for callers relying on all documents during fallback. Setting top_k to the input document count keeps all fallback documents.

Instinct assisted. This patch was generated with assistance; human review and understanding are still required before submission.

reno lint could not finish in the shallow clone because history object f4e004c34cbc724b3ffb026debdf7a0541e4a21f is missing. Release-note YAML and backtick hooks passed. Full repository tests and type checks were not run.

Checklist

  • I have read the contributors guidelines and code of conduct.
  • I have updated the related issue with new insights and changes. No public comments have been made.
  • I have added unit tests and updated the docstrings.
  • I've used a conventional commit type for the PR title.
  • I have documented my code.
  • I have added a release note file.
  • I have run pre-commit hooks and fixed any issue on changed files.

@charan-rathore
charan-rathore requested a review from a team as a code owner October 1, 2026 04:47
@charan-rathore
charan-rathore requested review from bogdankostic and removed request for a team October 1, 2026 04:47
@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

@charan-rathore is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Oct 1, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

LLMRanker fallback paths ignore top_k and return all input documents

2 participants