Skip to content

SentenceTransformersDiversityRanker incorrectly replaces lambda_threshold=0.0 with 0.5 #9770

@abdokaseb

Description

@abdokaseb

Describe the bug
SentenceTransformersDiversityRanker incorrectly replaces lambda_threshold=0.0 with 0.5 because of short-circuit evaluation:

self.lambda_threshold = lambda_threshold or 0.5
# BUG: 0.0 is falsy, so it becomes 0.5

This silently changes the intended behavior when users explicitly set lambda_threshold=0.0.

Expected behavior
Passing lambda_threshold=0.0 should preserve 0.0.

To Reproduce

from haystack.components.rankers import SentenceTransformersDiversityRanker

ranker = SentenceTransformersDiversityRanker(lambda_threshold=0.0)
print(f"Expected: 0.0, Actual: {ranker.lambda_threshold}")
# Expected: 0.0, Actual: 0.5

FAQ Check

System:
The error will be in all OSs and versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions