Skip to content

fix(python): support batched UInt8 Hamming queries - #9244

Open
ddupg wants to merge 1 commit into
lance-format:mainfrom
ddupg:fix/ddu-379-batch-uint8-hamming
Open

ddupg wants to merge 1 commit into
lance-format:mainfrom
ddupg:fix/ddu-379-batch-uint8-hamming

Conversation

@ddupg

@ddupg ddupg commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Batched NumPy uint8 queries were converted to List<Float32> and skipped the existing UInt8 cast, causing Hamming search to fail with a type mismatch.

Preserve the batch shape while casting its elements back to UInt8.

Reproduction

import lance
import numpy as np
import pyarrow as pa
import tempfile

with tempfile.TemporaryDirectory() as root:
    ds = lance.write_dataset(
        pa.table({
            "vector": pa.array(
                [[0, 0], [255, 0]],
                type=pa.list_(pa.uint8(), 2),
            )
        }),
        f"{root}/data.lance",
    )
    ds.to_table(nearest={
        "column": "vector",
        "q": np.array([[0, 0]], dtype=np.uint8),
        "metric": "hamming",
        "k": 1,
    })

Before this change:

Column vector has element type UInt8 and the query vector is Float32

@github-actions github-actions Bot added A-python Python bindings bug Something isn't working labels Sep 15, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Gate recommendation: approve.

The shape-preserving UInt8 cast restores the documented batched-query contract for binary vectors while leaving scalar-query and core search semantics unchanged. Flat and IVF_FLAT batch results match repeated single-query searches.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-python Python bindings bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant