未验证 提交 f5c22a83 编写于 作者: S shengjun.li 提交者: GitHub

#1903 Fix invalid annoy result (#1912)

Signed-off-by: Nshengjun.li <shengjun.li@zilliz.com>
上级 9ce6c21e
......@@ -11,6 +11,7 @@ Please mark all change in change log and use the issue from GitHub
- \#1832 Fix crash in tracing module
- \#1873 Fix index file serialize to incorrect path
- \#1881 Fix bad alloc when index files lost
- \#1903 Fix invalid annoy result
- \#1910 C++ SDK GetIDsInSegment could not work for large dataset
## Feature
......
......@@ -128,8 +128,15 @@ IndexAnnoy::Query(const DatasetPtr& dataset_ptr, const Config& config) {
distances.reserve(k);
index_->get_nns_by_vector((const float*)p_data + i * dim, k, search_k, &result, &distances, blacklist);
memcpy(p_id + k * i, result.data(), k * sizeof(int64_t));
memcpy(p_dist + k * i, distances.data(), k * sizeof(float));
size_t result_num = result.size();
auto local_p_id = p_id + k * i;
auto local_p_dist = p_dist + k * i;
memcpy(local_p_id, result.data(), result_num * sizeof(int64_t));
memcpy(local_p_dist, distances.data(), result_num * sizeof(float));
for (; result_num < k; result_num++) {
local_p_id[result_num] = -1;
local_p_dist[result_num] = 1.0 / 0.0;
}
}
auto ret_ds = std::make_shared<Dataset>();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册