milvus-io / milvus-sdk-java

Java SDK for Milvus.
https://milvus.io
Apache License 2.0
366 stars 150 forks source link

When a SearchIteratorParam is initialized via withParams, calling build() raises an error #887

Closed PiercarloSlavazza closed 2 months ago

PiercarloSlavazza commented 2 months ago

For instance:

SearchIteratorParam.newBuilder()
                .withCollectionName(metadata.getCollectionName())
                .withMetricType(MetricType.IP)
                .withParams("{\"radius\": 0.5, \"range_filter\": 0.8}")

gives the error:

class java.lang.Double cannot be cast to class java.lang.Float (java.lang.Double and java.lang.Float are in module java.base of loader 'bootstrap')

The bug has already been reported and debugged in #881 - quoting explanation from https://github.com/milvus-io/milvus-sdk-java/issues/881#issuecomment-2098505462 (Bug n.2):

This bug is actually unrelated to bug n.1 - it just happened to occur while I was trying hard to find a workaround to bug n. 1 (well, before I understood the very nature of that first issue, of course).

In this line:

milvus-sdk-java/src/main/java/io/milvus/orm/iterator/SearchIterator.java

Line 143 in bf981d0 float radius = (float) params.get(RADIUS);

the result of params.get(RADIUS) is cast to a Float - but this leads to a casting error because params.get(RADIUS) is read as a Double, which of course cannot be just cast to a Float. BTW the parameter is read as a Double because this is parsed via JacksonUtils.fromJson(searchIteratorParam.getParams(), new TypeReference<Map<String, Object>>(){}), and Jackson wil always read a real number as a Double in this case, and this behaviour is not - to my knowledge - configurable.

yhmo commented 2 months ago

I suppose this bug is fixed by this pr: https://github.com/milvus-io/milvus-sdk-java/pull/884

PiercarloSlavazza commented 2 months ago

@yhmo you are right - closing.