Open
Conversation
This commit implements on-the-fly filtering for KNN search, allowing the search algorithm to continue exploring until k filtered candidates are found, rather than finding k total candidates and then filtering them. Key changes: - Added `k` parameter to `searchBaseLayerST()` method to specify the target number of filtered results when filtering is enabled - Added `use_filter` flag to determine when filtering mode is active - Modified termination condition to continue searching until `k` filtered candidates are found when `use_filter` is true, instead of stopping after `ef` total candidates - Updated exploration logic (`should_explore`) to continue exploring neighbors when filtering is enabled and fewer than `k` filtered candidates have been found, even if `ef` candidates have already been explored - Added filtering check (`is_filtered`) before adding candidates to `top_candidates` priority queue, ensuring only filtered candidates are stored - The filter callback (`BaseFilterFunctor* isIdAllowed`) is invoked for each candidate node via `(*isIdAllowed)(label)` to determine if it passes the filter - Updated `searchKnn()` to pass the `k` parameter to `searchBaseLayerST()` when a filter is provided The changes ensure that when filtering is enabled: 1. The search continues until `k` filtered candidates are found (if they exist) 2. Only candidates that pass the filter are added to `top_candidates` 3. The exploration continues even if `ef` candidates have been explored, as long as fewer than `k` filtered candidates have been found This enables more accurate KNN search results when combined with attribute filters, as the algorithm actively searches for filtered candidates rather than relying on post-filtering which may return fewer than `k` results.
This was referenced Jan 22, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR implements on-the-fly filtering for KNN search, allowing the search algorithm to continue exploring until k filtered candidates are found, rather than finding k total candidates and then filtering them.
Key changes:
kparameter tosearchBaseLayerST()method to specify the target number of filtered results when filtering is enableduse_filterflag to determine when filtering mode is activekfiltered candidates are found whenuse_filteris true, instead of stopping aftereftotal candidatesshould_explore) to continue exploring neighbors when filtering is enabled and fewer thankfiltered candidates have been found, even ifefcandidates have already been exploredis_filtered) before adding candidates totop_candidatespriority queue, ensuring only filtered candidates are storedBaseFilterFunctor* isIdAllowed) is invoked for each candidate node via(*isIdAllowed)(label)to determine if it passes the filtersearchKnn()to pass thekparameter tosearchBaseLayerST()when a filter is providedThe changes ensure that when filtering is enabled:
kfiltered candidates are found (if they exist)top_candidatesefcandidates have been explored, as long as fewer thankfiltered candidates have been foundThis enables more accurate KNN search results when combined with attribute filters, as the algorithm actively searches for filtered candidates rather than relying on post-filtering which may return fewer than
kresults.