Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MilvusBasicExample search fail #155

Closed
RailyMay opened this issue Dec 7, 2020 · 1 comment
Closed

MilvusBasicExample search fail #155

RailyMay opened this issue Dec 7, 2020 · 1 comment

Comments

@RailyMay
Copy link

RailyMay commented Dec 7, 2020

SearchParam searchParam =
SearchParam.create(collectionName)
.setDsl(dsl)
.setParamsInJson("{"fields": ["duration", "release_year", "embedding"]}");
System.out.println("\n--------Search Result--------");
SearchResult searchResult = client.search(searchParam);

private SearchResult buildSearchResponse(QueryResult topKQueryResult) {
final int numQueries = (int) topKQueryResult.getRowNum();
final int topK = numQueries == 0 ? 0 : topKQueryResult.getDistancesCount() / numQueries;

List<List<Long>> resultIdsList = new ArrayList<>(numQueries);
List<List<Float>> resultDistancesList = new ArrayList<>(numQueries);
List<List<Map<String, Object>>> resultFieldsMap = new ArrayList<>(numQueries);

Entities entities = topKQueryResult.getEntities();
List<Long> queryIdsList = entities.getIdsList();
List<Float> queryDistancesList = topKQueryResult.getDistancesList();

// If fields specified, put it into searchResponse
List<Map<String, Object>> fieldsMap = new ArrayList<>();
for (int i = 0; i < queryIdsList.size(); i++) {
  fieldsMap.add(new HashMap<>());
}
if (entities.getValidRowCount() != 0) {
  List<FieldValue> fieldValueList = entities.getFieldsList();
  for (FieldValue fieldValue : fieldValueList) {
    String fieldName = fieldValue.getFieldName();
    for (int j = 0; j < queryIdsList.size(); j++) {
      if (fieldValue.getAttrRecord().getInt32ValueCount() > 0) {
        fieldsMap.get(j).put(fieldName, fieldValue.getAttrRecord().getInt32ValueList().get(j));
      } else if (fieldValue.getAttrRecord().getInt64ValueCount() > 0) {
        fieldsMap.get(j).put(fieldName, fieldValue.getAttrRecord().getInt64ValueList().get(j));
      } else if (fieldValue.getAttrRecord().getDoubleValueCount() > 0) {
        fieldsMap.get(j).put(fieldName, fieldValue.getAttrRecord().getDoubleValueList().get(j));
      } else if (fieldValue.getAttrRecord().getFloatValueCount() > 0) {
        fieldsMap.get(j).put(fieldName, fieldValue.getAttrRecord().getFloatValueList().get(j));
      } else {
        // the object is vector
        List<VectorRowRecord> vectorRowRecordList =
            fieldValue.getVectorRecord().getRecordsList();
        if (vectorRowRecordList.get(j).getFloatDataCount() > 0) {
          fieldsMap.get(j).put(fieldName, vectorRowRecordList.get(j).getFloatDataList());
        } else {
          fieldsMap.get(j).put(fieldName, vectorRowRecordList.get(j).getBinaryData().asReadOnlyByteBuffer());
        }
      }
    }
  }
}

....
}

进入search方法后, 在buildSearchResponse () 里, j 循环报错
Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

@sahuang
Copy link
Member

sahuang commented Dec 7, 2020

Which SDK version are you using?

v0.9.1 fixed a bug related to this: milvus-io/milvus#4086

@RailyMay RailyMay closed this as completed Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants