Skip to content

feat(python): add CombinedFieldsQuery for BM25F full text search - #4691

Merged
Xuanwo merged 5 commits into
lancedb:mainfrom
BHAWESHBHASKAR:python-combined-fields-query
Oct 29, 2026
Merged

Xuanwo merged 5 commits into
lancedb:mainfrom
BHAWESHBHASKAR:python-combined-fields-query

Conversation

@BHAWESHBHASKAR

Copy link
Copy Markdown
Contributor

Closes #4652

Lance supports combined_fields (BM25F) full text queries, but the Python SDK had no class for them, and python/src/query.rs raised "Combined-fields FTS queries are not yet supported in Python" when converting such a query back to Python.

This adds CombinedFieldsQuery(query, columns, *, boosts=None, operator=OR) to lancedb.query, mirroring MultiMatchQuery, and converts it in both directions in python/src/query.rs. Unlike MultiMatchQuery, which scores each column on its own and keeps the best one, it treats the columns as one field, so an AND query also matches rows whose terms are spread across columns. Boosts are validated by Lance during conversion, the same as for MultiMatchQuery (one per column, each at least 1).

Changes:

  • python/python/lancedb/query.py: COMBINED_FIELDS query type and the CombinedFieldsQuery class.
  • python/src/query.rs: FromPyObject and IntoPyObject arms for FtsQuery::CombinedFields.
  • python/python/tests/test_fts.py: AND and OR results compared with MultiMatchQuery, boosts, and the async to_query_object() round trip.
  • docs/src/python/python.md: API reference entry.

Testing:

  • pytest python/python/tests/test_fts.py on a local build of this branch: 85 passed.
  • ruff format --check, ruff check and rustfmt --check (edition 2024) are clean.

The Node SDK side is not included here; it is being discussed on the issue.

Lance supports combined_fields (BM25F) full text queries, but the Python
SDK had no class for them, and the binding rejected FtsQuery::CombinedFields
when converting a query back to Python.

Add CombinedFieldsQuery to lancedb.query, mirroring MultiMatchQuery, and
convert it in both directions in python/src/query.rs. Unlike
MultiMatchQuery, which scores each column on its own and keeps the best one,
it treats the columns as one field, so an AND query also matches rows whose
terms are spread across columns.

Boosts are validated by Lance when the query is converted, the same as for
MultiMatchQuery: each must be at least 1, with one per column.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added enhancement New feature or request Python Python SDK labels Oct 27, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 27, 2026
Shows an AND query whose terms are split across two columns, which MultiMatchQuery cannot match, plus column boosts and the shared tokenizer requirement.
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 27, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 27, 2026
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 29, 2026

@lancedb-gatekeeper lancedb-gatekeeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

Exposing Lance’s existing BM25F query remains a focused solution to the Python cross-field search gap. Local checks on the updated Lance dependency covered execution, boost validation, serialization, and nested Boolean round trips; the guide example also produced the documented results. No blocker was found.

Documentation: The revised SDK support note acknowledges Rust correctly. Keep the new Python example drafted until this API is released.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 29, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified 16 current-head checks, the Python matrix, Gatekeeper, and targeted CombinedFields coverage; no blocking findings.

@Xuanwo
Xuanwo merged commit 8917743 into lancedb:main Oct 29, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request K-approved Latest Gatekeeper recommendation permits acceptance. Python Python SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: CombinedFieldsQuery (BM25F) in the Python SDK

2 participants