Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ def run(self, query: str, documents: list[Document], top_k: int | None = None) -
if not documents:
return {"documents": []}

top_k = top_k or self.top_k
if top_k <= 0:
if top_k is not None and top_k <= 0:
msg = f"top_k must be > 0, but got {top_k}"
raise ValueError(msg)
top_k = self.top_k if top_k is None else top_k

if self._model is None:
self.warm_up()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,25 @@ def test_run_incorrect_input_format(self):
):
ranker.run(query=query, documents=list_document, top_k=-3)

with pytest.raises(
ValueError,
match="top_k must be > 0, but got 0",
):
ranker.run(query=query, documents=list_document, top_k=0)

def test_run_runtime_top_k_zero_does_not_fall_back_to_instance_top_k(self):
"""
A runtime top_k=0 must raise, not silently fall back to the instance top_k.
"""
ranker = FastembedLateInteractionRanker(model_name="colbert-ir/colbertv2.0", top_k=5)
ranker._model = "mock_model"

with pytest.raises(
ValueError,
match="top_k must be > 0, but got 0",
):
ranker.run(query="query", documents=[Document("Document 1")], top_k=0)

def test_run_empty_document_list(self):
"""
Test for no error when sending no documents.
Expand Down
Loading