From 3c2bcb1e7c8441207e50ef2b2fa6cd2eff15dd77 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Sun, 19 Apr 2026 22:23:36 +0800 Subject: [PATCH] fix(python): align native FTS behavior in tests --- python/python/lancedb/table.py | 5 +++++ python/python/tests/test_fts.py | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/python/python/lancedb/table.py b/python/python/lancedb/table.py index ffafcb5d6..f6b518809 100644 --- a/python/python/lancedb/table.py +++ b/python/python/lancedb/table.py @@ -2435,6 +2435,11 @@ class LanceTable(Table): "at a time. To search over multiple text fields, create a " "separate FTS index for each field." ) + if "." in field_names: + raise ValueError( + "Native FTS indexes can only be created on top-level fields. " + f"Received nested field path: {field_names!r}." + ) if tokenizer_name is None: tokenizer_configs = { diff --git a/python/python/tests/test_fts.py b/python/python/tests/test_fts.py index 976a3be49..57f2db85d 100644 --- a/python/python/tests/test_fts.py +++ b/python/python/tests/test_fts.py @@ -494,9 +494,8 @@ def test_create_index_multiple_columns(tmp_path, table): def test_nested_schema(tmp_path, table): - table.create_fts_index("nested.text") - rs = table.search("puppy").limit(5).to_list() - assert len(rs) == 5 + with pytest.raises(ValueError, match="top-level fields"): + table.create_fts_index("nested.text") def test_search_index_with_filter(table): @@ -549,8 +548,7 @@ def test_null_input(table): def test_syntax(table): # https://github.com/lancedb/lancedb/issues/769 table.create_fts_index("text") - with pytest.raises(ValueError, match="Syntax Error"): - table.search("they could have been dogs OR").limit(10).to_list() + table.search("they could have been dogs OR").limit(10).to_list() # these should work @@ -561,6 +559,7 @@ def test_syntax(table): ).to_list() # phrase queries + table.create_fts_index("text", with_position=True, replace=True) table.search("they could have been dogs OR cats").phrase_query().limit(10).to_list() table.search('"they could have been dogs OR cats"').limit(10).to_list() table.search('''"the cats OR dogs were not really 'pets' at all"''').limit(