Skip to content

Fix API that approximates the size of FAISS indexes#75

Open
CascadingRadium wants to merge 5 commits into
blevefrom
fixSize
Open

Fix API that approximates the size of FAISS indexes#75
CascadingRadium wants to merge 5 commits into
blevefrom
fixSize

Conversation

@CascadingRadium
Copy link
Copy Markdown
Member

@CascadingRadium CascadingRadium commented May 8, 2026

  • We currently return 8 bytes for the faiss_IndexBinary_size and the
    faiss_Index_size APIs
  • Although this could be correct, since we memory-map the FAISS indexes, this API is
    quite useless as it always returns 8 after performing a sizeof operation.
  • When estimating the amount of memory a FAISS index would use on the GPU for throttling,
    this API cannot be used.
  • Fix this issue by modifying the API behavior to return the approximate amount of memory
    it would require if we bring the entire index to the memory, which would be useful in
    approximating how much memory must be available in the GPU to
    consider the FAISS index to be eligible for cloning.

CascadingRadium and others added 2 commits May 8, 2026 18:51
Co-authored-by: Copilot <copilot@github.com>
@CascadingRadium CascadingRadium changed the title Fix output of faiss_IndexBinary_size and faiss_Index_size Fix API that approximates the size of FAISS indexes May 8, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the FAISS C “_ex” APIs for index sizing to return a more useful (approximate) in-memory byte estimate instead of effectively returning the pointer size, with the goal of supporting GPU-memory eligibility/throttling decisions when cloning indexes.

Changes:

  • Changes faiss_Index_size / faiss_IndexBinary_size to return an error code (int) and write the size to an out-parameter (size_t*).
  • Implements a new size estimate based on ntotal * code_size plus extra IVF-related overhead (centroids + stored IDs).
  • Updates/expands header documentation and adds IVF includes to enable IVF-specific handling.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
c_api/Index_c_ex.h Updates C API signature + documentation for faiss_Index_size.
c_api/Index_c_ex.cpp Implements the new size estimation logic for float indexes (including IVF path).
c_api/IndexBinary_c_ex.h Updates C API signature + documentation for faiss_IndexBinary_size.
c_api/IndexBinary_c_ex.cpp Implements the new size estimation logic for binary indexes (including IVF path).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread c_api/Index_c_ex.cpp
Comment thread c_api/Index_c_ex.cpp Outdated
Comment thread c_api/Index_c_ex.h Outdated
Comment thread c_api/Index_c_ex.cpp Outdated
Comment thread c_api/IndexBinary_c_ex.h Outdated
Comment thread c_api/IndexBinary_c_ex.cpp Outdated
Comment thread c_api/IndexBinary_c_ex.h Outdated
Comment thread c_api/Index_c_ex.h Outdated
CascadingRadium and others added 2 commits May 8, 2026 22:14
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
capemox
capemox previously approved these changes May 11, 2026
@CascadingRadium CascadingRadium requested review from a team, capemox and steveyen May 11, 2026 12:09
Comment thread c_api/IndexBinary_c_ex.cpp
@Thejas-bhat
Copy link
Copy Markdown
Member

looks good but can you please add the MB for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants