diff --git a/python/python/lancedb/util.py b/python/python/lancedb/util.py index 6a5be99db..f582be7b4 100644 --- a/python/python/lancedb/util.py +++ b/python/python/lancedb/util.py @@ -307,13 +307,19 @@ def infer_vector_column_name( # FTS queries do not require a vector column return None - if query is not None or query_type == "hybrid": - try: - vector_column_name = inf_vector_column_query( - schema, dim=_query_vector_dim(query) - ) - except Exception as e: - raise e + if query is None and query_type != "hybrid": + # No vector search was requested (e.g. a plain scan), so there's + # nothing to infer. + return None + + vector_column_name = inf_vector_column_query(schema, dim=_query_vector_dim(query)) + + if vector_column_name is None: + raise ValueError( + "No vector column found in the schema. Please specify the " + "vector column name explicitly via the `vector_column_name` " + "parameter." + ) return vector_column_name diff --git a/python/python/tests/test_util.py b/python/python/tests/test_util.py index 7cb0ce448..a9b66b2dd 100644 --- a/python/python/tests/test_util.py +++ b/python/python/tests/test_util.py @@ -924,3 +924,23 @@ def test_sanitize_data_stream(): with pytest.raises(ValueError): next(output) + + +def test_infer_vector_column_raises_clear_error(tmp_path): + """Regression: querying a table with no inferable vector column should raise + a clear ValueError, not a cryptic TypeError (issue #1653). + + Previously, inf_vector_column_query silently returned None which then caused + a confusing TypeError deep in schema lookup. The fix adds a ValueError guard + so the user gets a direct, actionable error message. + """ + db = lancedb.connect(tmp_path) + table = db.create_table( + "no_vec", + data=[{"id": 1, "text": "hello"}, {"id": 2, "text": "world"}], + ) + + with pytest.raises(ValueError, match="vector"): + # Plain vector search on a table with no vector column should raise + # a clear ValueError, not a cryptic TypeError. + table.search([1.0, 2.0]).to_list()