#4331·lancedb

错误(Python): 所有分数重排器都丢失了输入的 Arrow 结构

作者: LindseyZ1205创建于 2026年9月27日更新于 2026年9月27日

What happened? Model rerankers using return_score="all" rebuild their merged results without passing the original Arrow schema. A uint64 row ID becomes int64, a fixed-size float32 vector becomes a variable-length float64 list, and schema metadata is lost. A valid uint64 row ID of 2**63 raises OverflowError instead. Empty inputs also lose their columns. Requesting the original scores should preserve the input columns' types and metadata, as the return_score="relevance" path does. The cause is Reranker._merge_and_keep_scores() calling pa.Table.from_pylist() without a schema after merging Python row dictionaries. A small fix is to unify the original input schemas before adding placeholder score columns and pass that schema to from_pylist. ### Are there known steps to reproduce? The following uses the public Cohere reranker path with a mocked client; no Cohere SDK, API key, model download, or network request is needed. Python from types import SimpleNamespace import pyarrow as pa from lancedb.rerankers import CohereReranker schema = pa.schema([("rowid", pa.uint64()), ("text", pa.string()), ("vector", pa.list(pa.float32(), 2))], metadata={b"source": b"example"}) row = {"_rowid": 1, "text": "example", "vector": [1.0, 0.0]} vector = pa.Table.from_pylist([{**row, "_distance": 0.1}], schema=schema.append(pa.field("_distance", pa.float32()))) fts = pa.Table.from_pylist([{**row, "_score": 0.8}], schema=schema.append(pa.field("_score", pa.float32()))) reranker = CohereReranker(return_score="all") reranker._client = SimpleNamespace(rerank=lambda **kwargs: SimpleNamespace(results=[SimpleNamespace(index=0, relevance_score=1.0)])) result = reranker.rerank_hybrid("example", vector, fts) print(result.select(schema.names).schema) assert result.select(schema.names).schema.equals(schema, check_metadata=True) On the unmodified source, the assertion fails: the row ID is int64, the vector is list<double>, and metadata is absent. Replacing 1 with 2**63 in the row ID reproduces OverflowError: Python int too large to convert to C long. Ten parametrized cases cover normal/high row IDs, float32/float64 scores, empty inputs and the relevance-only control. Before the fix: 5 failed / 5 passed. After the fix: all 10 pass. The reranker, hybrid-query and TypeSafe reranker test files pass locally: 150 passed, 17 skipped (optional model/API tests). AI disclosure: I used Codex to investigate the issue, implement the local fix, prepare and run tests, and draft this report.

内容来源: lancedb/lancedb