From 3afd0ced9c764587134e80a3d64dacaf442a200b Mon Sep 17 00:00:00 2001 From: KarthikS Date: Tue, 1 Dec 2026 23:04:52 -0500 Subject: [PATCH] fix: reject combined-fields queries on legacy Enterprise servers (#5343) Closes #5340. Reject `CombinedFields` before sending an FTS query to a LanceDB Enterprise server older than 0.3.0. The check follows all Boolean clauses and both sides of a Boost query. The 0.3.0 regression test also checks that unequal column weights and the `AND` operator reach the server. Reproduced with Python SDK 0.42.1 against a mock 0.2.0 server. Both searches returned HTTP 200. The top-level query lost its weights and operator, and the nested Boolean query sent an empty string. The same searches preserved the structured query on 0.3.0. --- docs/web/search/full-text-search.mdx | 3 ++ rust/lancedb/src/remote/table.rs | 70 +++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/docs/web/search/full-text-search.mdx b/docs/web/search/full-text-search.mdx index 2eb475f5c..d49d2561e 100644 --- a/docs/web/search/full-text-search.mdx +++ b/docs/web/search/full-text-search.mdx @@ -829,6 +829,9 @@ The query below finds `car` in `text` and `merrily` in `text2`, returning rows 1 and 3. The same query with `MultiMatchQuery` returns no rows, because neither column contains both words on its own. +On LanceDB Enterprise, combined-fields queries require server version 0.3.0 or +later, including when nested in a Boolean or boost query. + Every column must use the same tokenizer configuration. The two indexes in this example are built with the same `FTS` settings. Boosts work as they do for `MultiMatchQuery`: one weight per column, each at least 1. diff --git a/rust/lancedb/src/remote/table.rs b/rust/lancedb/src/remote/table.rs index a23632f73..7a5ba8505 100644 --- a/rust/lancedb/src/remote/table.rs +++ b/rust/lancedb/src/remote/table.rs @@ -179,6 +179,22 @@ fn fts_query_requires_document_granularity_support(query: &FtsQuery) -> bool { } } +fn contains_combined_fields(query: &FtsQuery) -> bool { + match query { + FtsQuery::CombinedFields(_) => true, + FtsQuery::Boost(query) => { + contains_combined_fields(&query.positive) || contains_combined_fields(&query.negative) + } + FtsQuery::Boolean(query) => query + .must + .iter() + .chain(&query.should) + .chain(&query.must_not) + .any(contains_combined_fields), + FtsQuery::Match(_) | FtsQuery::MultiMatch(_) | FtsQuery::Phrase(_) => false, + } +} + /// Per-table state driving the freshness headers (`x-lancedb-min-version`, /// `x-lancedb-min-timestamp`, and `x-lancedb-min-read-version`) sent on table /// requests. @@ -1633,6 +1649,12 @@ impl RemoteTable { "query": full_text_search.query.clone(), }); } else { + if contains_combined_fields(&full_text_search.query) { + return Err(Error::NotSupported { + message: "CombinedFields queries require LanceDB Enterprise server version 0.3.0 or later" + .into(), + }); + } let has_and = match &full_text_search.query { FtsQuery::Match(query) => query.operator == Operator::And, FtsQuery::MultiMatch(query) => query @@ -9272,6 +9294,47 @@ mod tests { .unwrap(); } + #[tokio::test] + async fn test_query_combined_fields_requires_structured_fts() { + use lance_index::scalar::inverted::query::{ + BooleanQuery, BoostQuery, CombinedFieldsQuery, Occur, + }; + + let table = Table::new_with_handler_version::<&str>( + "my_table", + semver::Version::new(0, 2, 0), + |request| { + panic!( + "unexpected legacy FTS request: {:?}", + request_body_json(&request) + ) + }, + ); + let combined: FtsQuery = + CombinedFieldsQuery::try_new("hello world".into(), vec!["title".into(), "text".into()]) + .unwrap() + .into(); + let term: FtsQuery = MatchQuery::new("hello".into()) + .with_column(Some("title".into())) + .into(); + let boosted = BoostQuery::new(term.clone(), combined.clone(), None).into(); + for query in [ + combined.clone(), + BooleanQuery::new(vec![(Occur::Must, combined.clone())]).into(), + BooleanQuery::new(vec![(Occur::Should, combined.clone())]).into(), + BooleanQuery::new(vec![(Occur::MustNot, boosted)]).into(), + BoostQuery::new(combined, term, None).into(), + ] { + let result = table + .query() + .full_text_search(FullTextSearchQuery::new_query(query)) + .execute() + .await; + assert!(matches!(result, Err(Error::NotSupported { message }) + if message.contains("CombinedFields") && message.contains("0.3.0"))); + } + } + #[tokio::test] async fn test_query_combined_fields_uses_structured_fts() { use lance_index::scalar::inverted::query::CombinedFieldsQuery; @@ -9286,8 +9349,8 @@ mod tests { "combined_fields": { "query": "hello world", "columns": ["title", "text"], - "boost": [1.0, 1.0], - "operator": "Or" + "boost": [2.0, 1.0], + "operator": "And" } }) ); @@ -9312,6 +9375,9 @@ mod tests { vec!["title".into(), "text".into()], ) .unwrap() + .try_with_boosts(vec![2.0, 1.0]) + .unwrap() + .with_operator(Operator::And) .into(), )) .execute()