diff --git a/python/python/lancedb/query.py b/python/python/lancedb/query.py index 66ff03a4a..8561f68de 100644 --- a/python/python/lancedb/query.py +++ b/python/python/lancedb/query.py @@ -70,7 +70,7 @@ def ensure_vector_query( ) -> Union[List[float], List[List[float]], pa.Array, List[pa.Array]]: if isinstance(val, list): if len(val) == 0: - return ValueError("Vector query must be a non-empty list") + raise ValueError("Vector query must be a non-empty list") sample = val[0] else: if isinstance(val, float): @@ -83,7 +83,7 @@ def ensure_vector_query( return val if isinstance(sample, list): if len(sample) == 0: - return ValueError("Vector query must be a non-empty list") + raise ValueError("Vector query must be a non-empty list") if isinstance(sample[0], float): # val is list of list of floats return val diff --git a/python/python/tests/test_query.py b/python/python/tests/test_query.py index 2105a4dfa..a7153b010 100644 --- a/python/python/tests/test_query.py +++ b/python/python/tests/test_query.py @@ -30,6 +30,7 @@ from lancedb.query import ( PhraseQuery, Query, FullTextSearchQuery, + ensure_vector_query, ) from lancedb.rerankers.cross_encoder import CrossEncoderReranker from lancedb.table import AsyncTable, LanceTable @@ -1501,6 +1502,18 @@ def test_search_empty_table(mem_db): assert results == [] +def test_ensure_vector_query_empty_list(): + """Regression: ensure_vector_query used to return instead of raise ValueError.""" + with pytest.raises(ValueError, match="non-empty"): + ensure_vector_query([]) + + +def test_ensure_vector_query_nested_empty_list(): + """Regression: ensure_vector_query used to return instead of raise ValueError.""" + with pytest.raises(ValueError, match="non-empty"): + ensure_vector_query([[]]) + + def test_fast_search(tmp_path): db = lancedb.connect(tmp_path)