Skip to content

feat: add asynchronous support to LLMRanker with run_async method#11841

Open
GovindhKishore wants to merge 2 commits into
deepset-ai:mainfrom
GovindhKishore:feat/llm-ranker-run-async
Open

feat: add asynchronous support to LLMRanker with run_async method#11841
GovindhKishore wants to merge 2 commits into
deepset-ai:mainfrom
GovindhKishore:feat/llm-ranker-run-async

Conversation

@GovindhKishore

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Added native asynchronous support (run_async) to LLMRanker. This allows reranking pipelines to run concurrently inside asynchronous environments (like FastMCP or FastAPI) without stalling the main event loop during LLM network requests.

How it works:

  • Runtime check for async support: Verifies whether the assigned chat generator natively supports async execution via hasattr(self._chat_generator, "run_async"). If it only supports synchronous execution, it automatically drops down to a safe thread-pool fallback via asyncio.to_thread instead of blocking the event loop.
  • Identical logic to run: Deduplication, empty-query/empty-document guards, and the ranking/parsing post-processing (_get_reply_text, _rank_documents_from_reply) are unchanged and shared between the sync and async paths - only the chat generation call itself differs.
  • Monitored failure tracking: Strictly matches the existing sync error-handling configuration (raise_on_failure), falling back to the original document order when ranking or generation fails and the flag is False, or re-raising when it's True.

How did you test it?

Added a complete async test suite (test_run_async_*) mirroring the existing sync test coverage in test_llm_ranker.py. The tests cover:

  • run_async version for existing run sync tests: Implemented the corresponding test_run_async versions for test_run ones.
  • Dual-path execution: Confirming run_async is used when the chat generator supports it, and that it is not used (with asyncio.to_thread calling sync run instead) when the generator lacks run_async.
  • Live integration tests: Added async equivalents of the existing live integration tests against the real OpenAI API, confirming end-to-end ranking behavior.

Ran hatch run test:unit test/components/rankers/test_llm_ranker.py with a 100% clean pass, hatch run ruff format / hatch run ruff check --fix.

Notes for the reviewer

The implementation structure mirrors the synchronous run method identically to keep the component maintenance straightforward.

Checklist

@GovindhKishore GovindhKishore requested a review from a team as a code owner June 30, 2026 18:08
@GovindhKishore GovindhKishore requested review from davidsbatista and removed request for a team June 30, 2026 18:08
@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

@GovindhKishore is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant