fix: add better check for empty results in hybrid search (#2252)

fixes: https://github.com/lancedb/lancedb/issues/2249
This commit is contained in:
Ayush Chaurasia
2025-03-21 13:05:05 +05:30
committed by GitHub
parent b595d8a579
commit ba1ded933a
2 changed files with 26 additions and 2 deletions

View File

@@ -368,6 +368,26 @@ def test_rrf_reranker_distance():
assert score == fts_scores[rowid], "Score mismatch"
assert found_match, "No results matched between hybrid and fts search"
# Test for empty fts results
fts_results = (
table.search("abcxyz" * 100, query_type="fts").with_row_id(True).to_list()
)
hybrid_results = (
table.search(query_type="hybrid")
.vector([0.0] * 32)
.text("abcxyz" * 100)
.with_row_id(True)
.rerank(reranker)
.to_list()
)
assert len(fts_results) == 0
# confirm if _rowid, _score, _distance & _relevance_score are present in hybrid
assert len(hybrid_results) > 0
assert "_rowid" in hybrid_results[0]
assert "_score" in hybrid_results[0]
assert "_distance" in hybrid_results[0]
assert "_relevance_score" in hybrid_results[0]
@pytest.mark.skipif(
os.environ.get("COHERE_API_KEY") is None, reason="COHERE_API_KEY not set"