Skip to content

Hybrid Search Fails with Sparse Vector Type — "Search target vector type is illegal" Exception #1402

@qidafang0413

Description

@qidafang0413

Hi Milvus team,

I encountered an issue while using the Java SDK for hybrid search. I followed the example provided in the documentation and translated it into Java code. However, when executing the hybrid search, it throws a ParamException indicating that the vector type is invalid for sparse vectors.

Here's the Python example from the documentation that I tried to replicate:

search_params_dense = {
    "data": [[1.25, 2, 3.5]],
    "anns_field": "vector",
    "param": {
        "metric_type": "IP",
        "params": {"nprobe": 10}, 
    },
    "limit": 100
}

req_dense = ANNSearchRequest(**search_params_dense)

search_params_sparse = {
    "data": ["shoes"],
    "anns_field": "text_sparse",
    "param": {
        "metric_type": "BM25",
        "params": {"drop_ratio_search": 0.2}
    }
}

req_sparse = ANNSearchRequest(**search_params_sparse)

res = client.hybrid_search(
    collection_name="my_collection",
    reqs=[req_dense, req_sparse],
    reranker=RRFRanker(),
    limit=10
)

And here's my Java equivalent:

List<AnnSearchReq> searchRequests = new ArrayList<>();
searchRequests.add(AnnSearchReq.builder()
        .vectorFieldName("dense_vector")
        .vectors(Collections.singletonList(new FloatVec(queryVector)))
        .metricType(IndexParam.MetricType.COSINE)
        .params("{\"nprobe\": 10}")
        .topK(topK)
        .build());
searchRequests.add(AnnSearchReq.builder()
        .vectorFieldName("sparse_vector")
        .vectors(Collections.singletonList(new EmbeddedText(question)))
        .metricType(IndexParam.MetricType.BM25)
        .params("{\"drop_ratio_build\": 0.2}")
        .topK(topK)
        .build());

BaseRanker reranker = new WeightedRanker(Arrays.asList(0.8f, 0.3f));

HybridSearchReq hybridSearchReq = HybridSearchReq.builder()
    .collectionName(collectionName)
    .searchRequests(searchRequests)
    .ranker(reranker)
    .topK(topK)
    .build();

SearchResp searchResp = milvusClient.hybridSearch(hybridSearchReq);

But I get the following exception:

io.milvus.exception.ParamException: Search target vector type is illegal. Only allow List<Float> for FloatVector, ByteBuffer for BinaryVector/Float16Vector/BFloat16Vector, List<SortedMap<Long, Float>> for SparseFloatVector.

It seems the Java SDK does not accept EmbeddedText as a valid input for sparse vector hybrid search, even though the Python SDK allows a string for sparse text fields.

Could you clarify what the correct way is to represent sparse vector input (text-based or otherwise) in the Java SDK? If the EmbeddedText class is not supported for this purpose, some guidance or equivalent usage would be much appreciated.

Thanks in advance!

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