Repository navigation
Description
DRAFT 15 (SDK, 2026-10-27) — to be filed
Title: [Bug]: vector bind_processor stringifies numpy arrays with space separators (and any unknown object via bare str())
Description
The SQLAlchemy vector types (VectorType, Vectorf32, Vectorf64 in sqlalchemy_ext/vector_type.py) serialize bind values like this — every one of the three classes has the identical tail:
def process_bind_param(self, value, dialect):
if value is None:
return None
if isinstance(value, list):
return "[" + ",".join(map(str, value)) + "]"
if isinstance(value, str):
return value
return str(value) # ← the trapstr(value) is the catch-all for anything that isn't None/list/str. The overwhelmingly common input for vector embeddings is a numpy ndarray — and ndarray's str():
>>> str(np.array([1.5, 2.5, 3.5]))
'[1.5 2.5 3.5]' # SPACE-separated, not comma
>>> str(np.array([[1.,2.],[3.,4.]]))
'[[1. 2.]\n [3. 4.]]' # nested with newlinesSo INSERT/update via SQLAlchemy ORM with an ndarray embedding ships '[1.5 2.5 3.5]' as the vector literal — MatrixOne's vector parser expects comma-separated terms, yielding (depending on server tolerance) a parse error far from the cause, or worse a silently wrong vector if whitespace ends up tolerated in some path. 2-D arrays produce multi-line garbage. Tensors/torch.Tensor behave the same way.
The same catch-all converts any other unfortunate object to its repr: decimal-comma locales, custom sequence types, pandas Series (str(Series) carries an index in some reprs) — all silently produce non-SQL.
This is not theoretical: the SDK's own docs advertise pandas/numpy-ecosystem embeddings workflows; the natural ORM write path (session.add(Model(embedding=np.array(...))) or session.execute(insert(Model).values(embedding=arr))) lands exactly here.
Reproduction (no server needed)
import numpy as np
from matrixone.sqlalchemy_ext.vector_type import Vectorf32
t = Vectorf32(3)
print(t.process_bind_param(np.array([1.5, 2.5, 3.5]), None))
# '[1.5 2.5 3.5]' ← space-separated, invalid vector literal
print(t.process_bind_param([1.5, 2.5, 3.5], None))
# '[1.5,2.5,3.5]' ← correct(Same result through bind_processor; result_processor is the read side and is tolerant.)
Impact
- numpy users get hard-to-diagnose insert failures or corrupted vectors on the primary workflow the vector types exist for — the error (SQL syntax/parse from the server) says nothing about numpy or str().
- The catch-all
str(value)masks every future type instead of failing fast; silent wrong-vector writes are the doomsday case for ANN search quality (garbage vectors still insert, searches return nonsense neighbors).
Expected behavior
- Handle ndarray explicitly:
hasattr(value, "tolist")→value.tolist()then the comma-join path (covers numpy, torch, cupy,jax arrays uniformly). Same guard coverspandas.Seriesvia.values/tolist. - Remove the bare-
str()fallback: unknown types should raiseTypeError(f"Cannot bind {type(value)} as vector; pass list/tuple/ndarray")— a clear boundary error vastly preferable to shipping a repr to the server. - Guard the list path too: non-numeric elements (e.g. strings) inside the list should raise, not produce
'['a','b']'. - Regression: bind ndarray(list/tuple/tensor) asserting the comma-separated literal; bind garbage type asserting the TypeError.
Activity
fix(python): unify SDK query and analytics lifecycle contracts (#31774)
XuPeng-SH commentedon Oct 30, 2026
QA handoff for merged #31774 (main
bbfe55669a1440424914d45a283a1d0e36f722fa): please verify the reported public SDK contract and its failure/recovery controls for vector types stringify numpy arrays to space-separated literals. This isolated QA run inspected the issue and merged PR but did not run tests or a live MatrixOne service at this SHA because the existing resource guard left insufficient headroom. The PR's author-reported validation is separate evidence, not a result of this QA run.Ariznawlll commentedon Oct 30, 2026
结论
测试通过。NumPy 一维数组经 SDK 向量类型绑定后能正确写入,不支持的对象及非法元素会被拒绝。
关键证据
main@d39d8a40343ccd40bf665036388df7a40ee867f8;修复 PR fix(python): unify SDK query and analytics lifecycle contracts #31774 合并提交bbfe55669a1440424914d45a283a1d0e36f722fa位于祖先链;实际二进制和 SDK 同完整 SHA。本地隔离 1 CN / 1 TN / 1 LogService,Python 3.12、NumPy 2.5.4。[1.5,2.5,3.5]均生成逗号分隔值并实际写入;逐列读取均为三个正确数值。list、tuple 和 NULL 对照也正确。待解决点
Ariznawlll commentedon Oct 30, 2026
回归位置更正:#295 已关闭并汇总至 MOTR #298;本 issue 的定向用例已补入 #298,之前所述测试结果及未覆盖项不变。#298 尚未合入,完整 MOTR suite 未运行。