Skip to content

fix: validate join_mode in MultiRetriever - #13122

Open
hermanrous wants to merge 1 commit into
deepset-ai:mainfrom
hermanrous:fix/multi-retriever-join-mode-validation
Open

hermanrous wants to merge 1 commit into
deepset-ai:mainfrom
hermanrous:fix/multi-retriever-join-mode-validation

Conversation

@hermanrous

Copy link
Copy Markdown

Related Issues

Proposed Changes:

MultiRetriever.__init__ accepted any join_mode value. Only the exact string "reciprocal_rank_fusion" selects RRF in _merge_results; every other value falls through to the concatenate branch:

if top_k is not None or self.join_mode == "reciprocal_rank_fusion":
    documents = _reciprocal_rank_fusion(document_lists)
    ...
return _deduplicate_documents([doc for docs in document_lists for doc in docs])

A typo such as "Concatenate", "rrf", or "reciprocal_rank_fusion " with a trailing space was therefore accepted silently and changed both the scores and the order of the merged documents, with nothing raised. The mistake also stays invisible in pipelines deserialized from YAML, where the Literal annotation on join_mode cannot be enforced.

This adds a ValueError in __init__ naming the two supported modes, using the same wording MetaFieldRanker uses for its Literal parameters.

JoinMode from haystack/components/joiners/document_joiner.py was deliberately not reused: it has four members (merge and distribution_based_rank_fusion included) while MultiRetriever implements only two, so JoinMode.from_str would let the other two fall into the very concatenate branch this PR fixes.

How did you test it?

  • New test_init_with_invalid_join_mode_raises, parametrized over "Concatenate", "reciprocal-rank-fusion", "reciprocal_rank_fusion " and "rrf".
    • On unmodified main: 4 failed, with E Failed: DID NOT RAISE ValueError.
    • With the change: 4 passed.
  • test/components/retrievers/test_multi_retriever.py: 54 passed, 6 skipped before, 58 passed, 6 skipped after.
  • test/components/retrievers/: 254 passed, 11 skipped.
  • Checked the deserialization path directly as well: component_from_dict with join_mode="Reciprocal_Rank_Fusion" used to return an instance silently and now raises.
  • ruff check, ruff format --check and mypy are clean.

Environment caveat, same as #12262 and #12719: the suites were run in a plain venv built with pip rather than through Hatch, because the full Hatch environment could not be resolved locally.

Notes for the reviewer

  • The :raises ValueError: docstring now also covers join_mode.
  • Release note added under releasenotes/notes/.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes. — N/A, there is no related issue.
  • I have added unit tests and updated the docstrings.
  • I've used a conventional commit type for my PR title: fix:.
  • I have documented my code.
  • I have added a release note file.
  • I have run pre-commit hooks and fixed any issue.

This PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests.

@hermanrous
hermanrous requested a review from a team as a code owner October 5, 2026 14:25
@hermanrous
hermanrous requested review from bogdankostic and removed request for a team October 5, 2026 14:25
@CLAassistant

CLAassistant commented Oct 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @hermanrous, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from bogdankostic October 5, 2026 15:32
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Oct 5, 2026
@HaystackBot
HaystackBot marked this pull request as draft October 5, 2026 15:32
@HaystackBot
HaystackBot marked this pull request as ready for review October 5, 2026 17:28
@HaystackBot HaystackBot removed the cla-pending PR is in draft until the contributor signs the CLA label Oct 5, 2026
@HaystackBot

Copy link
Copy Markdown
Contributor

Thanks for signing the CLA, @hermanrous! 🎉 This PR is now ready for review again and the reviewer has been re-assigned.

@bogdankostic bogdankostic self-assigned this Oct 6, 2026

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.

4 participants