milvus-io/milvus-sdk-java

ANN 查询数据 id返回值错误

Opened this issue · 3 comments

collection 设置 主键为 VarChar(32)

在查询时返回值为

 "rowRecords" : [ {
    "fieldValues" : {
      "distance" : 0.62605506,
      "id" : 0
    }
  }, {
    "fieldValues" : {
      "distance" : 0.9031652,
      "id" : 0
    }
  }, {
    "fieldValues" : {
      "distance" : 0.9675503,
      "id" : 0
    }]
}

查询参数为

SearchParam{collectionName='chat_kb', partitionNames='[]', metricType=L2, target vectors count=1, vectorFieldName='vector', topK=10, nq=1, expr='', params='{"offset":0}', consistencyLevel='null', ignoreGrowing='false'}

无法返回正确的 uuid 作为业务关联使用

what is your schema of your collection?
is id your primary key field?
is it autoIncrement or user specified

yhmo commented

Use the 'SearchResultsWrapper' class to print out all the search results:

        SearchParam searchParam = SearchParam.newBuilder()
                .withCollectionName(randomCollectionName)
                .withMetricType(MetricType.IP)
                .withTopK(topK)
                .withVectors(targetVectors)
                .withVectorFieldName(field2Name)
                .addOutField(field4Name)
                .build();

        R<SearchResults> searchR = client.search(searchParam);
        Assertions.assertEquals(R.Status.Success.getCode(), searchR.getStatus().intValue());

        SearchResultsWrapper results = new SearchResultsWrapper(searchR.getData().getResults());
        for (int i = 0; i < targetVectors.size(); ++i) {
            List<SearchResultsWrapper.IDScore> scores = results.getIDScore(i);
            System.out.println("The result of No." + i + " target vector:");
            for (int k = 0; k < scores.size(); ++k) {
                SearchResultsWrapper.IDScore score = scores.get(k);
                System.out.println("ID: " + score.getStrID() + " Distance:" + score.getScore());
            }
        }

If your primary key is Long type, the id is score.getLongID().
If your primary key is Varchar type, the id is score.getStrID().

yhmo commented

It is a bug of SearchResultsWrapper.getRowRecords(), which is fixed by #757 and #758.

In fact, getRowRecords() is a wrapper of getIDScore(), it is better to use getIDScore() to get the results.