diff --git a/python/python/lancedb/query.py b/python/python/lancedb/query.py index 97be089c6..992463f0c 100644 --- a/python/python/lancedb/query.py +++ b/python/python/lancedb/query.py @@ -2634,7 +2634,7 @@ class LanceHybridQueryBuilder(LanceQueryBuilder): self._vector_query.ef(self._ef) if self._bypass_vector_index: self._vector_query.bypass_vector_index() - if self._lower_bound or self._upper_bound: + if self._lower_bound is not None or self._upper_bound is not None: self._vector_query.distance_range( lower_bound=self._lower_bound, upper_bound=self._upper_bound ) diff --git a/python/python/tests/test_hybrid_query.py b/python/python/tests/test_hybrid_query.py index d0712f16c..f2bbf3180 100644 --- a/python/python/tests/test_hybrid_query.py +++ b/python/python/tests/test_hybrid_query.py @@ -139,6 +139,20 @@ def test_hybrid_query_distance_range(sync_table: Table): assert 0.2 <= dist.as_py() <= 0.5 +def test_hybrid_query_applies_zero_upper_distance_bound(sync_table: Table): + result = ( + sync_table.search(query_type="hybrid") + .vector([0.0, 0.4]) + .text("elephant") + .distance_range(upper_bound=0.0) + .rerank(RRFReranker(return_score="all")) + .limit(4) + .to_arrow() + ) + + assert len(result) == 0 + + @pytest.mark.asyncio async def test_hybrid_query_distance_range_async(table: AsyncTable): reranker = RRFReranker(return_score="all")