diff --git a/python/python/tests/test_query.py b/python/python/tests/test_query.py index 6840be052..a3c94e7e8 100644 --- a/python/python/tests/test_query.py +++ b/python/python/tests/test_query.py @@ -666,6 +666,27 @@ def test_distance_range(table: lancedb.table.Table): assert res["_distance"].to_pylist() == [min_dist, max_dist] +@pytest.mark.parametrize( + ("expression", "expected_type"), + [ + ("1 - _distance", pa.float32()), + ("1.0 - _distance", pa.float64()), + ], +) +def test_select_arithmetic_with_distance(table, expression, expected_type): + result = ( + table.search([10, 10]) + .select({"similarity": expression}) + .distance_type("cosine") + .to_arrow() + ) + + assert result.schema.field("similarity").type == expected_type + assert result["similarity"].to_pylist() == pytest.approx( + [1 - distance for distance in result["_distance"].to_pylist()] + ) + + @pytest.mark.asyncio async def test_distance_range_async(table_async: AsyncTable): q = [0, 0]