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.
This commit is contained in:
KarthikS
2026-12-02 12:04:52 +08:00
committed by GitHub
parent 9bdb1b7219
commit 3afd0ced9c
2 changed files with 71 additions and 2 deletions
+68 -2
View File
@@ -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<S: HttpSend> RemoteTable<S> {
"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()