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 disparity between disk and memory search for Universal label #347

Merged
merged 9 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions include/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ template <typename T, typename TagT = uint32_t, typename LabelT = uint32_t> clas
DISKANN_DLLEXPORT size_t get_num_points();
DISKANN_DLLEXPORT size_t get_max_points();

DISKANN_DLLEXPORT const std::vector<LabelT> find_common_filters(uint32_t point_id, bool search_invocation,
gopalrs marked this conversation as resolved.
Show resolved Hide resolved
const std::vector<LabelT> &incoming_labels);

// Batch build from a file. Optionally pass tags vector.
DISKANN_DLLEXPORT void build(const char *filename, const size_t num_points_to_load,
const IndexWriteParameters &parameters,
Expand Down
50 changes: 27 additions & 23 deletions src/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,31 @@ template <typename T, typename TagT, typename LabelT> std::vector<uint32_t> Inde
return init_ids;
}

template <typename T, typename TagT, typename LabelT>
const std::vector<LabelT> Index<T, TagT, LabelT>::find_common_filters(uint32_t point_id, bool search_invocation,
const std::vector<LabelT> &incoming_labels)
{
std::vector<LabelT> common_filters;
auto &curr_node_labels = _pts_to_labels[point_id];
std::set_intersection(incoming_labels.begin(), incoming_labels.end(), curr_node_labels.begin(),
gopalrs marked this conversation as resolved.
Show resolved Hide resolved
curr_node_labels.end(), std::back_inserter(common_filters));
if (_use_universal_label)
{
if (!search_invocation)
{
if (std::find(incoming_labels.begin(), incoming_labels.end(), _universal_label) != incoming_labels.end() ||
std::find(curr_node_labels.begin(), curr_node_labels.end(), _universal_label) != curr_node_labels.end())
common_filters.push_back(_universal_label);
}
else
{
if (std::find(curr_node_labels.begin(), curr_node_labels.end(), _universal_label) != curr_node_labels.end())
common_filters.push_back(_universal_label);
}
}
return common_filters;
}

template <typename T, typename TagT, typename LabelT>
std::pair<uint32_t, uint32_t> Index<T, TagT, LabelT>::iterate_to_fixed_point(
const T *query, const uint32_t Lsize, const std::vector<uint32_t> &init_ids, InMemQueryScratch<T> *scratch,
Expand Down Expand Up @@ -933,17 +958,7 @@ std::pair<uint32_t, uint32_t> Index<T, TagT, LabelT>::iterate_to_fixed_point(

if (use_filter)
{
std::vector<LabelT> common_filters;
auto &x = _pts_to_labels[id];
std::set_intersection(filter_label.begin(), filter_label.end(), x.begin(), x.end(),
std::back_inserter(common_filters));
if (_use_universal_label)
{
if (std::find(filter_label.begin(), filter_label.end(), _universal_label) != filter_label.end() ||
std::find(x.begin(), x.end(), _universal_label) != x.end())
common_filters.emplace_back(_universal_label);
}

std::vector<LabelT> common_filters = find_common_filters(id, search_invocation, filter_label);
if (common_filters.size() == 0)
continue;
}
Expand Down Expand Up @@ -1012,18 +1027,7 @@ std::pair<uint32_t, uint32_t> Index<T, TagT, LabelT>::iterate_to_fixed_point(
if (use_filter)
{
// NOTE: NEED TO CHECK IF THIS CORRECT WITH NEW LOCKS.
std::vector<LabelT> common_filters;
auto &x = _pts_to_labels[id];
std::set_intersection(filter_label.begin(), filter_label.end(), x.begin(), x.end(),
std::back_inserter(common_filters));
if (_use_universal_label)
{
if (std::find(filter_label.begin(), filter_label.end(), _universal_label) !=
filter_label.end() ||
std::find(x.begin(), x.end(), _universal_label) != x.end())
common_filters.emplace_back(_universal_label);
}

std::vector<LabelT> common_filters = find_common_filters(id, search_invocation, filter_label);
if (common_filters.size() == 0)
continue;
}
Expand Down