Skip to content

Falsy run() overrides are silently ignored in SentenceTransformersSimilarityRanker #3854

Description

@keosung

Describe the bug
run() resolves its overrides with or:

top_k = top_k or self.top_k
scale_score = scale_score or self.scale_score
score_threshold = score_threshold or self.score_threshold

or falls back on any falsy value, not just None, so valid falsy arguments are silently replaced by the init values, although the docstring says "If set, overrides the value set at initialization":

  • run(scale_score=False) is ignored: with the default scale_score=True, False or True is True
  • run(score_threshold=0.0) is replaced by the init value, or by no filtering at all
  • run(top_k=0) silently uses the init top_k instead of raising the documented ValueError

To Reproduce

ranker = SentenceTransformersSimilarityRanker()   # scale_score=True by default
ranker.run(query=query, documents=docs, scale_score=False)
# the cross encoder still runs with the Sigmoid activation

Describe your environment (please complete the following information):

  • OS: Ubuntu 24.04 LTS
  • Haystack version: 3.0.0
  • Integration version: current main

Additional context
#3745 fixed the same or pattern for top_k in the fastembed rankers.
Happy to open a PR with the same fix and regression tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions