milvus-io/milvus · error · ValueError

Int8Vector size mismatch: expected {dim}, got {len(bytes_dat

Error message

Int8Vector size mismatch: expected {dim}, got {len(bytes_data)}

What it means

Raised when an Int8Vector blob's byte count differs from the expected dim. Int8 vectors store exactly one signed byte per dimension, so len(bytes) must equal dim exactly. Because the deserializer infers dim = len(bytes_data) when dim is None, this only triggers when an explicit mismatching dim is passed or the blob is truncated.

Source

Thrown at cmd/tools/binlogv2/parquet_analyzer/vector_deserializer.py:175

        Deserialize Int8Vector
        References Int8Vector processing logic from serde.go
        
        Args:
            bytes_data: byte data
            dim: dimension, if None will auto-calculate
            
        Returns:
            List[int]: deserialized int8 vector
        """
        if not bytes_data:
            return None
        
        try:
            if dim is None:
                dim = len(bytes_data)
            
            if len(bytes_data) != dim:
                raise ValueError(f"Int8Vector size mismatch: expected {dim}, got {len(bytes_data)}")
            
            # Convert to int8 array
            int8_vector = [int8 for int8 in bytes_data]
            return int8_vector
        
        except Exception as e:
            print(f"Int8Vector deserialization failed: {e}")
            return None
    
    @staticmethod
    def deserialize_float16_vector(bytes_data: bytes, dim: Optional[int] = None) -> Optional[List[float]]:
        """
        Deserialize Float16Vector
        References Float16Vector processing logic from serde.go
        
        Args:
            bytes_data: byte data
            dim: dimension, if None will auto-calculate

View on GitHub (pinned to b43a76673a)

Solutions

  1. Omit dim (or pass dim=len(data)) and validate the inferred dimension against the collection schema.
  2. Verify file integrity and re-export if blobs are short.
  3. Confirm the column type mapping labels the field Int8Vector correctly.

Example fix

# before
deserializer.deserialize_int8_vector(data, dim=128)  # data len 127

# after
dim = len(data)
deserializer.deserialize_int8_vector(data, dim)
Defensive patterns

Strategy: validation

Validate before calling

def check_int8_vector(data: bytes, dim: int) -> bool:
    return len(data) > 0 and len(data) == dim

Type guard

def is_valid_int8_vector_blob(bytes_data: bytes, dim: int) -> bool:
    """True when bytes_data has exactly one byte per dimension."""
    return isinstance(bytes_data, (bytes, bytearray)) and len(bytes_data) == dim

Prevention

When it happens

Trigger: Explicit dim supplied that differs from blob length; truncated parquet data; column actually another vector type being read as Int8Vector.

Common situations: Dimension changed in schema between write and analysis; CLI dim flag typo; corrupt/truncated export.

Related errors


AI-assisted analysis of milvus-io/milvus@b43a76673a (2026-08-15). Data as JSON: /api/errors/a87b4acb0239dc23. Report an issue: GitHub.