Add cross-property BM25 And operator - #2114
Conversation
Exposes the OPERATOR_AND_CROSS search operator added in Weaviate 1.39.0 (backported to 1.37.15 and 1.38.8) as `BM25Operator.and_cross()`. Unlike `and_()`, a query token may be matched by any of the searched properties instead of having to occur within a single one. The gRPC construction for the bm25 and hybrid paths is folded into a shared `_BaseGRPC._bm25_operator_to_grpc()` so the version gate applies to query, generative-query and aggregation alike; sending the new enum to a server that predates it raises WeaviateUnsupportedFeatureError. `_ServerVersion.is_at_least_any()` is added to express minimums that were backported across several release branches.
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Secrets | View in Orca |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev/1.39 #2114 +/- ##
===========================================
Coverage ? 88.34%
===========================================
Files ? 303
Lines ? 23323
Branches ? 0
===========================================
Hits ? 20605
Misses ? 2718
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- Changelog is written at version creation, so the entry is removed. - Mismatched-tokenization integration test dropped: the server validates that. - Unsupported-version integration tests dropped for bm25 and hybrid: the version gate is already covered by unit tests. - Hybrid cross-property integration test dropped: it exercises the same server path as the bm25 one, and the request wiring is unit tested. - Unit tests cut to the two behaviours that are actually new: and_cross maps to OPERATOR_AND_CROSS on the bm25 and hybrid requests, and older servers are rejected.
|
That leaves the public surface asymmetric for no reason — users who want to from weaviate.collections.classes.grpc import (
MMR,
BM25OperatorAnd,
BM25OperatorAndCross,
BM25OperatorOr,
...
)
__all__ = [
...
"BM25OperatorAnd",
"BM25OperatorAndCross",
"BM25OperatorOr",
...
] |
Its two siblings, BM25OperatorAnd and BM25OperatorOr, are already exported, so isinstance checks and type annotations against the new operator have to reach into the private module without this.
Exposes the
OPERATOR_AND_CROSSsearch operator (Weaviate 1.39.0, backported to 1.37.15 and 1.38.8) asBM25Operator.and_cross(), available wherever a BM25 operator is accepted:query.bm25,query.hybrid, the generative-query equivalents, andaggregate.hybrid.Unlike
and_(), which requires every query token to occur within a single property,and_cross()lets a token be matched by any of the searched properties as long as each token is matched by at least one. All searched properties must share the same tokenization and analyzer settings — the server rejects the query otherwise.Changes
BM25OperatorAndCross+BM25Operator.and_cross()inweaviate/collections/classes/grpc.py.SearchOperatorOptionsconstruction in the bm25 and hybrid paths is folded into_BaseGRPC._bm25_operator_to_grpc(), so the version gate covers every caller. Usingand_cross()against an older server raisesWeaviateUnsupportedFeatureErrorrather than sending an enum value the server does not understand._ServerVersion.is_at_least_any()expresses a minimum that was backported across several release branches (a 1.38.x server needs 1.38.8, a 1.37.x server needs 1.37.15).OPERATOR_AND_CROSSenum value.1.39.0-rc.1-89299a5— the first RC carrying the operator.Tests
test/collection/test_bm25_operator.py—and_cross()maps toOPERATOR_AND_CROSSon the bm25 and hybrid requests, and is rejected on servers that predate it.test/test_server_version.py—is_at_least_any()around each branch boundary.integration/test_collection.py— one cross-property match against a live server, version-gated with a skip.