Skip to content

Commit 2a64a57

Browse files
joshinitin2016883-sketchclaudebogdankostic
authored
fix(jina): respect a falsy score_threshold override in JinaRanker (#4084)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: bogdankostic <bogdankostic@web.de>
1 parent 0443c89 commit 2a64a57

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎integrations/jina/src/haystack_integrations/components/rankers/jina/ranker.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _prepare_request_data(
119119
raise ValueError(msg)
120120

121121
top_k = top_k or self.top_k
122-
score_threshold = score_threshold or self.score_threshold
122+
score_threshold = score_threshold if score_threshold is not None else self.score_threshold
123123

124124
data = {
125125
"query": query,

‎integrations/jina/tests/test_ranker.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,25 @@ def test_run_with_score_threshold_filters_results(self):
233233
assert len(ranked) == 2
234234
assert all(doc.score >= 2.5 for doc in ranked)
235235

236+
def test_run_score_threshold_zero_overrides_init(self):
237+
docs = [Document(content=f"doc {i}") for i in range(4)]
238+
239+
with patch("httpx.Client.post", side_effect=mock_httpx_post_response):
240+
ranker = JinaRanker(api_key=Secret.from_token("fake-api-key"), score_threshold=2.5)
241+
result = ranker.run(query="q", documents=docs, score_threshold=0.0)
242+
243+
assert len(result["documents"]) == 4
244+
245+
@pytest.mark.asyncio
246+
async def test_run_async_score_threshold_zero_overrides_init(self):
247+
docs = [Document(content=f"doc {i}") for i in range(4)]
248+
249+
with patch("httpx.AsyncClient.post", side_effect=mock_httpx_post_response):
250+
ranker = JinaRanker(api_key=Secret.from_token("fake-api-key"), score_threshold=2.5)
251+
result = await ranker.run_async(query="q", documents=docs, score_threshold=0.0)
252+
253+
assert len(result["documents"]) == 4
254+
236255
def test_run_with_top_k_truncates_results(self):
237256
docs = [Document(content=f"doc {i}") for i in range(5)]
238257

0 commit comments

Comments
 (0)