Skip to content

Bug: Python serialized_length property raises TypeError due to missing default argument #683

@titusz

Description

@titusz

Describe the bug

The serialized_length property on the Python Index class raises a TypeError when accessed. The pybind11 binding doesn't expose the default argument for the serialization_config_t parameter, so Python callers cannot use the property without explicitly providing a config object (which isn't possible via the property interface).

The binding in python/lib.cpp:

i.def_property_readonly("serialized_length", &dense_index_py_t::serialized_length);

The C++ method signature in index_dense.hpp:

std::size_t serialized_length(serialization_config_t config = {}) const

Suggested fix - wrap in a lambda:

i.def_property_readonly("serialized_length", [](dense_index_py_t const& self) { 
    return self.serialized_length(); 
});

Steps to reproduce

from usearch.index import Index, MetricKind, ScalarKind
import numpy as np

idx = Index(ndim=32, metric=MetricKind.Hamming, dtype=ScalarKind.B1)
idx.add(1, np.array([178, 204, 60, 240], dtype=np.uint8))

# This raises TypeError
result = idx.serialized_length

Error:

TypeError: (): incompatible function arguments. The following argument types are supported:
    1. (arg0: usearch.compiled.Index, arg1: unum::usearch::index_dense_serialization_config_t) -> int

Invoked with: <usearch.compiled.Index object at 0x...>

Expected behavior

idx.serialized_length should return an integer representing the serialized length in bytes, using the C++ default config value.

USearch version

v2.21.0

Operating System

Windows 11 (also reproduced on Linux)

Hardware architecture

x86

Which interface are you using?

Python bindings

Searched existing issues

I have searched existing issues and this hasn't been reported.

Code of Conduct

I agree to the Code of Conduct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions