  The $q$-Racah polynomials are expressed in terms of certain ratios of scalar
products of Bethe states associated with Bethe equations of either homogeneous
or inhomogeneous type. This result is obtained by combining the theory of
Leonard pairs and the modified algebraic Bethe ansatz.
