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

Expose search function with pre-filter for ANN #302

Merged
merged 54 commits into from
Oct 2, 2024

Conversation

lowener
Copy link
Contributor

@lowener lowener commented Aug 26, 2024

Related to #136

This PR:

  • Expose the search() function with optional filters in the public API of ANNs (CAGRA, IVF-PQ, IVF-Flat)
  • Add compiled bitset objects
  • Restore tests for filters in IVF-Flat
  • Add tests for filter in CAGRA

@lowener lowener changed the title Expose search() with optional filter for ANN Expose search function with optional filter for ANN Aug 26, 2024
@cjnolet
Copy link
Member

cjnolet commented Sep 10, 2024

Closes #319

@lowener lowener marked this pull request as ready for review September 10, 2024 15:22
@lowener lowener requested review from a team as code owners September 10, 2024 15:22
*/

void search(raft::resources const& res,
cuvs::neighbors::cagra::search_params const& params,
const cuvs::neighbors::cagra::index<float, uint32_t>& index,
raft::device_matrix_view<const float, int64_t, raft::row_major> queries,
raft::device_matrix_view<uint32_t, int64_t, raft::row_major> neighbors,
raft::device_matrix_view<float, int64_t, raft::row_major> distances);
raft::device_matrix_view<float, int64_t, raft::row_major> distances,
std::optional<cuvs::neighbors::filtering::bitset_filter<uint32_t, int64_t>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to support both bitset and bitmap using inheritance (and without having to instantiate two explicit templates), right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could work on the host API side if we do dynamic casts on the host side down the line (before passing it to device) and do not add any virtual methods to the filter struct (so that the objects we pass to device don't have virtual tables).
(otherwise it gets very complicated and potentially slow)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, inheritance doesn't work as well on device side so the filter can't dynamically choose the right virtual function. Doing a dynamic cast on the host side can work so I will try that approach

@lowener lowener changed the title Expose search function with optional filter for ANN Expose search function with pre-filter for ANN Sep 25, 2024
Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the changes look good, but I'd like to avoid using pointers on the public APIs where at all possible on the public APIs and either pass by const reference or std::optional.

Also, can we consolidate the search API on brute-force also so that we can remove that search_with_filter function? We can do that in a follow-up if needed.

cpp/include/cuvs/neighbors/cagra.hpp Outdated Show resolved Hide resolved
cpp/src/neighbors/ivf_flat/ivf_flat_search.cuh Outdated Show resolved Hide resolved
@lowener
Copy link
Contributor Author

lowener commented Sep 30, 2024

@cjnolet Let's do the brute-force part in a follow-up, as it requires additional changes in the python, C and Rust wrappers code.

@cjnolet
Copy link
Member

cjnolet commented Oct 2, 2024

/merge

@rapids-bot rapids-bot bot merged commit 6c0fd14 into rapidsai:branch-24.10 Oct 2, 2024
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CMake cpp improvement Improves an existing functionality non-breaking Introduces a non-breaking change
Projects
Development

Successfully merging this pull request may close these issues.

3 participants