Repository navigation
Description
Description
Selecting a Python SDK FulltextFilter expression through SQLAlchemy converts the numeric relevance score into a Python bool. Distinct non-zero scores therefore become True, losing the value applications need for ranking and scoring. This occurs even without calling .label().
Environment
- Official
mainat analysis time:f0a6ed145e07c84ecc80566ac659212c4a20debd. - Python 3.12; SQLAlchemy 1.4.54 and 2.1.6.
- The SDK was executed from clean
d24f446e1e94a58c329d422519f7aad621cdcd05; its entireclients/python/matrixonepackage is byte-identical to the official main commit above. - The live MO control used an isolated service built from older main
ea184ad90624ae3dba8ced628ac019271a6c309c, reporting8.0.30-MatrixOne-v1.3.0; live latest-main server behavior was not tested.
Steps to reproduce
With a docs(id, content) table containing a classic FULLTEXT index and a matching document:
from sqlalchemy import MetaData, Table, select
from matrixone.sqlalchemy_ext.fulltext_search import boolean_match
docs = Table('docs', MetaData(), autoload_with=engine)
match = boolean_match(docs.c.content).must('needle')
print(engine.connect().execute(select(docs.c.id, match).where(match)).all())On the same connection/database, compare the numeric value produced by SELECT id, MATCH(content) AGAINST('+needle' IN BOOLEAN MODE) FROM docs WHERE MATCH(content) AGAINST('+needle' IN BOOLEAN MODE) using the raw driver.
Actual behavior
In three independent existing test databases, raw SQL returned (1, 0.09061906) with Python type float; SQLAlchemy returned (1, True) with type bool for the same match and row. The selected expression does not use .label().
Expected behavior
When selected as a score, the expression should preserve the numeric result and type returned by the driver while remaining usable as a WHERE predicate.
Stability and controls
- Live older-MO comparison: 3/3 databases, numeric driver result versus boolean SDK/SQLAlchemy result.
- Independent client-side isolation: on both SQLAlchemy versions, replace only the SQLite compiler's MATCH rendering with the numeric constant
0.09061906. Selectingliteral(0.09061906)andboolean_match('content').must('needle')in one statement returned(0.09061906, True)3/3 times. This control isolates SQLAlchemy result processing; it does not execute MO fulltext SQL or claim latest-MO server validation. - Read-only queries; no data mutations in these checks.
Code analysis
clients/python/matrixone/sqlalchemy_ext/fulltext_search.py:FulltextFilter.__init__ declares self.type = Boolean(). SQLAlchemy consequently applies a boolean result processor to the MATCH relevance value. Predicate use and numeric projection have different result-type requirements.
Regression coverage
Add SDK regression checks for an unlabelled projected score, multiple different nonzero scores and zero, asserting numerical type/value; retain a WHERE predicate control. Also verify against a live current-main MO service.
Related
#32026 is a separate failure: the overridden .label() returns an object rejected during statement construction. This report uses an unlabelled FulltextFilter and demonstrates loss of score after a query executes. The query-composition investigation was prompted by #32018.
Activity
Ariznawlll commentedon Nov 2, 2026
结论
测试不通过。本问题不只影响直接投影:
SUM/MIN/MAX继承全文表达式的布尔结果类型,分数也被读取为True;子查询和UNION ALL会继续传播该类型。这些是同根扩展,不另提 issue。关键证据
d24f446e1e94a58c329d422519f7aad621cdcd05,已核对其clients/python/matrixone与f0a6ed145e07c84ecc80566ac659212c4a20debd完全一致。SQLAlchemy 2.1.6。实测数据库仍为隔离的旧版ea184ad90624ae3dba8ced628ac019271a6c309c,不是最新 MO 服务验证。projection/sort_page/SUM/MIN/MAX均出现分数变布尔值;CAST(... AS FLOAT)、AVG、COUNT保持正确数值和类型。连接到两个 CN 是两个入口的对照,不代表这些小查询执行了分布式计划。SUM=0.07804843969643116、MIN=0.015609688、MAX=0.046829063,SDK 三者均为True;AVG=0.026016146565477054和COUNT=3两条路径一致。按原始分数排序分页的行 ID 与顺序保持一致,但结果中的分数仍丢失。stmt编译出的同一 SQL 交给原始驱动比较:待解决点
fix(python-sdk): preserve numeric fulltext relevance scores (#32042)
XuPeng-SH commentedon Nov 3, 2026
QA 交接(已合并修复,非验收通过)
修复 PR #32042 已于 2026-11-03 00:32:23 UTC 合入 main,merge SHA
da62af35f615824a3987ce9f6eac4c9bc5e7b541。FulltextFilter的结果类型由 Boolean 改为 Float,修复相关表达式的分数布尔化。已核对本 issue 全部评论及两文件修复范围。原评论的聚合、子查询和 UNION ALL 反例针对旧 SDK;该 PR 的冻结 head 审查 报告基线重现、候选聚合/子查询/UNION ALL/空值与空结果/谓词/dialect processor/Client.execute 对照通过,并有 101 项 focused tests 通过。作者报告 SQLAlchemy 1.4.54、2.0.43、2.1.6 的完整 offline suite 及九项新增回归通过。以上为远端作者/审查证据,本轮未进行本地实测;未发现适用于新修复的已验证反例或未完开发 follow-up,因此交 QA 复测。
验证限制与建议:未验证最新 main 的 live MatrixOne 全文评分、多 CN、在线 CI、SQL BVT 或性能;请在当前 main 对照原始驱动和 SDK 的直接投影、排序分页、SUM/MIN/MAX、子查询/UNION ALL,并覆盖不同正分数、零、负值、NULL/空结果、BOOLEAN/NATURAL LANGUAGE/QUERY EXPANSION、裸 WHERE 与数值阈值。旧双 CN 结果不等同分布式执行验证。独立
.label()问题 #32026 不在本修复范围。转测不代表验收通过。fix(python): keep fulltext scores numeric and labels selectable
Ariznawlll commentedon Nov 3, 2026
结论
测试通过。全文表达式作为投影和聚合结果时保留数值分数,不再把非零分数转换成 Python 布尔值。
关键证据
main@d61a7206c16b30baa4efc525eb6067c4364035aa、隔离 MO、Python 3.12;覆盖 SQLAlchemy 1.4.54、2.0.55、2.1.6。修复 #32042 的 SDK 离线矩阵及 CI Required 通过;online CI 跳过,下述真实服务测试是本次补充执行。SUM/MIN/MAX均保留数值类型和相同结果。自然语言示例的两条匹配行得到不同分数0.062016264、0.031008132,而不是两个True。直接投影和聚合在三个 SQLAlchemy 版本均执行;排序、阈值、子查询和 UNION 使用 2.1.6。第二个 CN 入口也复测三轮。UNION ALL的结果与原始驱动相同;没有依赖未指定的 UNION 行顺序。非法全文单词输入被 SDK 拒绝,三轮通过。测试后删除临时表。clients/python/tests/offline/test_fulltext_score_type.py覆盖表达式类型、裸 WHERE 和阈值,并以模拟服务分数覆盖正值、零、负值、NULL 及三种表达式模式;本地相关离线选择每版本 37 passed + 20 subtests。零、负分及 QUERY EXPANSION 属于离线结果处理覆盖,本次不宣称真实 MO 产生了这些分数或支持该搜索模式。此问题在 SDK 结果处理,回归应位于 SDK 测试,不适合纯 SQL MOTR。待解决点
无本 issue 范围内待解决项。第二个 CN 是独立入口复测,并不证明查询采用分布式计划;单独的
.label()问题不属于此修复。