-
Notifications
You must be signed in to change notification settings - Fork 706
Filter elements with an optional filtering function #402
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
765c4ab
Filter elements with an optional filtering function.
kishorenc ad3440c
Filter function should be sent the label and not the internal ID.
kishorenc 4f6dcc3
Ensure that results are not empty when reading from top results.
kishorenc 1c833a7
Make allowAllIds static.
kishorenc aaee13a
Use functor for filtering.
kishorenc b87f623
Explicitly check for filter functor being default.
kishorenc f0dedf3
Remove duplicate assignment.
kishorenc de22860
Merge branch 'develop' into filter-elements
kishorenc e4705fd
Add search with filter test to CI.
kishorenc 7f419ea
Remove constexpr for functor in test.
kishorenc 1fe7baf
Add check for is_filter_disabled.
kishorenc c9897b0
Add assert header.
kishorenc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,7 +247,8 @@ namespace hnswlib { | |
std::priority_queue<std::pair<dist_t, tableint>, std::vector<std::pair<dist_t, tableint>>, CompareByFirst> candidate_set; | ||
|
||
dist_t lowerBound; | ||
if ((!has_deletions || !isMarkedDeleted(ep_id)) && isIdAllowed(getExternalLabel(ep_id))) { | ||
bool is_filter_disabled = std::is_same<filter_func_t, decltype(allowAllIds)>::value; | ||
if ((!has_deletions || !isMarkedDeleted(ep_id)) && (is_filter_disabled || isIdAllowed(getExternalLabel(ep_id)))) { | ||
dist_t dist = fstdistfunc_(data_point, getDataByInternalId(ep_id), dist_func_param_); | ||
lowerBound = dist; | ||
top_candidates.emplace(dist, ep_id); | ||
|
@@ -307,7 +308,8 @@ namespace hnswlib { | |
_MM_HINT_T0);//////////////////////// | ||
#endif | ||
|
||
if ((!has_deletions || !isMarkedDeleted(candidate_id)) && isIdAllowed(getExternalLabel(candidate_id))) | ||
is_filter_disabled = std::is_same<filter_func_t, decltype(allowAllIds)>::value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can remove this line as above we assigned value to |
||
if ((!has_deletions || !isMarkedDeleted(candidate_id)) && (is_filter_disabled || isIdAllowed(getExternalLabel(candidate_id)))) | ||
top_candidates.emplace(dist, candidate_id); | ||
|
||
if (top_candidates.size() > ef) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the following micro optimisation to not call isIdAllowed at all if filtering is disabled: