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

Fix the problem of low recall rate of glass(hnsw) in multi-core environment #11

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions glass/hnsw/hnsw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,31 @@ struct HNSW : public Builder {
printf("HNSW building cost: %.2lfs\n", ela);
final_graph.init(nb, 2 * M);
#pragma omp parallel for
for (int i = 0; i < nb; ++i) {
int *edges = (int *)hnsw->get_linklist0(i);
for (int j = 1; j <= edges[0]; ++j) {
final_graph.at(i, j - 1) = edges[j];
for (int i = 0; i < nb; ++i) {
auto internal_id = hnsw->label_lookup_[i];
int *edges = (int *)hnsw->get_linklist0(internal_id);
for (int j = 1; j <= edges[0]; ++j) {
int external_id = hnsw->getExternalLabel(edges[j]);
final_graph.at(i, j - 1) = external_id;
}
}
}
auto initializer = std::make_unique<HNSWInitializer>(nb, M);
initializer->ep = hnsw->enterpoint_node_;
for (int i = 0; i < nb; ++i) {
int level = hnsw->element_levels_[i];
initializer->levels[i] = level;
if (level > 0) {
initializer->lists[i].assign(level * M, -1);
for (int j = 1; j <= level; ++j) {
int *edges = (int *)hnsw->get_linklist(i, j);
for (int k = 1; k <= edges[0]; ++k) {
initializer->at(j, i, k - 1) = edges[k];
auto initializer = std::make_unique<HNSWInitializer>(nb, M);
initializer->ep = hnsw->getExternalLabel(hnsw->enterpoint_node_);
for (int i = 0; i < nb; ++i) {
auto internal_id = hnsw->label_lookup_[i];
int level = hnsw->element_levels_[internal_id];
initializer->levels[i] = level;
if (level > 0) {
initializer->lists[i].assign(level * M, -1);
for (int j = 1; j <= level; ++j) {
int *edges = (int *)hnsw->get_linklist(internal_id, j);
for (int k = 1; k <= edges[0]; ++k) {
initializer->at(j, i, k - 1) = hnsw->getExternalLabel(edges[k]);
}
}
}
}
}
}
final_graph.initializer = std::move(initializer);
final_graph.initializer = std::move(initializer);
}

Graph<int> GetGraph() override { return final_graph; }
Expand Down