Skip to content

Use int64_t for getters in the cagra/ivf_flat c-api#1272

Merged
rapids-bot[bot] merged 5 commits intorapidsai:branch-25.10from
benfred:int64_getters
Sep 17, 2025
Merged

Use int64_t for getters in the cagra/ivf_flat c-api#1272
rapids-bot[bot] merged 5 commits intorapidsai:branch-25.10from
benfred:int64_getters

Conversation

@benfred
Copy link
Copy Markdown
Contributor

@benfred benfred commented Aug 21, 2025

Java doesn't support unsigned types well, and this is leading to us only supporting 2^31 items in the cagra index - instead of 2^32.

Fix by changing the getters in the c-api to return int64_t values for the size/dim etc, instead of uint32_t.

We were also not consistent on returning error codes in ivf_flat/ivf_pq for these getters - with cagra returning an error code, and the ivf* methods just returning the value directly. Change to always return an error code to be consistent. (Note that #1123 is also making this change for ivf-pq - and I'm skipping ivf-pq to avoid merge conflicts).

Java doesn't support unsigned types well, and this is leading
to us only supporting 2**31 items in the cagra index - instead
of 2**32.

Fix by changing the getters in the c-api to return int64_t values
for the size/dim etc, instead of uint32_t.

We were also not consistent on returning error codes in ivf_flat/ivf_pq
for these getters - with cagra returning an error code, and the ivf*
methods just returning the value directly. Change to always return an
error code to be consistent. (Note that rapidsai#1123 is also making this change
for ivf-pq - and I'm skipping ivf-pq to avoid merge conflicts).
@benfred benfred self-assigned this Aug 21, 2025
@benfred benfred requested review from a team as code owners August 21, 2025 18:37
@benfred benfred added the breaking Introduces a breaking change label Aug 21, 2025
@benfred benfred requested a review from a team as a code owner August 21, 2025 18:37
@benfred benfred added the improvement Improves an existing functionality label Aug 21, 2025
extern "C" cuvsError_t cuvsCagraIndexGetDims(cuvsCagraIndex_t index, int64_t* dim)
{
return cuvs::core::translate_exceptions([=] {
auto index_ptr = reinterpret_cast<cuvs::neighbors::cagra::index<float, uint32_t>*>(index->addr);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tangential question: How come index->addr is a uintprt_t and not a void*?

(Functionally, it's likely equivalent, except for the ability to use static_cast instead of reinterpret_cast.)

Copy link
Copy Markdown
Contributor

@mythrocks mythrocks left a comment

Choose a reason for hiding this comment

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

C++ and Java changes: 👍

Python changes: Look good to my eye, but should probably be reviewed by an expert.

if (index->dtype.code == kDLFloat && index->dtype.bits == 32) {
auto index_ptr =
reinterpret_cast<cuvs::neighbors::ivf_flat::index<float, int64_t>*>(index->addr);
*n_lists = index_ptr->n_lists();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this is a non-narrowing conversion (uint32_t -> int64_t), an explicit static_cast is not required, but explicit casting can still help with readability and safety.
Same comment for all the other getters (such as cuvsIvfFlatIndexGetDim) that are doing an implicit casting.

Comment thread cpp/src/neighbors/ivf_flat_c.cpp
@benfred
Copy link
Copy Markdown
Contributor Author

benfred commented Sep 17, 2025

/merge

@rapids-bot rapids-bot Bot merged commit b3a4fd8 into rapidsai:branch-25.10 Sep 17, 2025
84 checks passed
@benfred benfred deleted the int64_getters branch January 30, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Introduces a breaking change improvement Improves an existing functionality

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants