blob: 1b2f62a144f6255271b0c38f46151fb6ed8dcdf1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "hnsw_single_best_neighbors.h"
namespace search::tensor {
std::vector<NearestNeighborIndex::Neighbor>
HnswSingleBestNeighbors::get_neighbors(uint32_t k, double distance_threshold)
{
while (_candidates.size() > k) {
_candidates.pop();
}
std::vector<NearestNeighborIndex::Neighbor> result;
result.reserve(_candidates.size());
for (const HnswCandidate & hit : _candidates.peek()) {
if (hit.distance > distance_threshold) continue;
result.emplace_back(hit.docid, hit.distance);
}
return result;
}
}
|