MultiRetriever rejects top_k=0 at init but accepts it at runtime
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 88/100
Direzione di ricerca
Inizia in multi_retriever.py, nella validazione di init intorno alle righe 116-119, quindi confrontala con _resolve_top_k e con il ramo di run descritto nell’issue. Aggiungi una copertura di regressione per gli argomenti del costruttore con valore 0 e verifica che run() restituisca un risultato documents vuoto. Il lavoro è completato quando 0 viene accettato all’inizializzazione, i valori negativi continuano a generare un errore e la descrizione di ValueError riflette la nuova soglia.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
MultiRetriever.__init__ rejects top_k=0 (and top_k_per_retriever=0), but the runtime validation in _resolve_top_k accepts top_k=0 with an explicit docstring saying it is valid. The component is internally inconsistent: a value that the runtime treats as "no documents returned" cannot be set at construction time.
Reproduction
On current main:
from haystack.components.retrievers import MultiRetriever
try:
MultiRetriever(retrievers={}, top_k=0)
except ValueError as e:
print(repr(e))
# ValueError("top_k must be greater than 0, but got 0")
try:
MultiRetriever(retrievers={}, top_k_per_retriever=0)
except ValueError as e:
print(repr(e))
# ValueError("top_k_per_retriever must be greater than 0, but got 0")
The init-time checks at multi_retriever.py:116-119 raise on 0 even though _resolve_top_k (multi_retriever.py:137-142) explicitly allows 0, with the docstring:
Resolve runtime values against the init defaults and reject negatives.
A resolved value of 0 is valid and means no documents are returned.
And run itself handles top_k=0 (multi_retriever.py:264):
if resolved_top_k == 0 or resolved_top_k_per_retriever == 0:
So top_k=0 is a meaningful runtime value — it returns an empty result — but the constructor refuses to accept it.
Expected behavior
MultiRetriever(top_k=0) and MultiRetriever(top_k_per_retriever=0) should construct successfully and produce empty results at runtime, matching what _resolve_top_k and run already support.
Suggested scope
Change the __init__ checks at multi_retriever.py:116-119 from <= 0 to < 0, mirroring the runtime validation. Update the :raises ValueError: description at line 114 to drop the "not greater than 0" wording (now "is negative"). No public API change, no behavior change beyond accepting 0. Add a regression test that constructs MultiRetriever(top_k=0) and verifies run() returns {"documents": []} (or the equivalent empty branch for the chosen join_mode).
Alternatives considered
- Tightening the runtime to reject
0. Not chosen —_resolve_top_kdocstring, therunshort-circuit, and the empty-slice semantics (merged[:0] == []) all treat0as a valid "no documents" value. - Treating
0asNone. Not chosen — explicit0is useful for callers who want to disable a retriever's contribution without dropping it fromretrievers.
Acceptance criteria
MultiRetriever(retrievers={}, top_k=0)constructs without error.MultiRetriever(retrievers={}, top_k_per_retriever=0)constructs without error.run()with a resolvedtop_kortop_k_per_retrieverof0returns{"documents": []}(or the documented equivalent forjoin_mode="concatenate").- The init-time
:raises ValueError:description matches the new threshold.
Backward compatibility
None. The change accepts a previously-rejected value; existing callers passing positive values see no difference.
- Lingua principale
- Python
- Stelle
- 26.6k
- Fork
- 3.2k
- Merge medio
- 1g 12h
- PR unite (30g)
- 237
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di deepset-ai/haystack
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 88/100
deepset-ai/haystack#12978 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
deepset-ai/haystack#12954 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
deepset-ai/haystack#12953 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
deepset-ai/haystack#12945 ·
I maintainer di solito rispondono entro 1 giorno
-
P2
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 91/100
deepset-ai/haystack#12939 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di deepset-ai/haystack
Issue simili
-
Broken links found in docsApertadocs pydanty:is-working
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
pydantic/pydantic-ai#8863 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
run-llama/llama_index#23278 ·
I maintainer di solito rispondono entro 2 giorni
-
documentation from-review-extraction github-actions priority: low severity:nit
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
LearningCircuit/local-deep-research#6946 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
oracle/langchain-oracle#323 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
tenstorrent/tt-metal#58057 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno