Skip to content

Add IndexBinaryIDMap2 support to index binary factory#4603

Closed
ashishresu2001 wants to merge 4 commits into
facebookresearch:mainfrom
ashishresu2001:feature/indexbinaryidmap2-support
Closed

Add IndexBinaryIDMap2 support to index binary factory#4603
ashishresu2001 wants to merge 4 commits into
facebookresearch:mainfrom
ashishresu2001:feature/indexbinaryidmap2-support

Conversation

@ashishresu2001

Copy link
Copy Markdown
Contributor

Summary

  • Add support for IDMap2/IDMap prefix and suffix parsing in index_binary_factory
  • Normalize description string to handle whitespace
  • Add unit tests for IDMap2 prefix, suffix, and whitespace cases

Testing

  • Ran: pytest tests/test_binary_factory.py

Fixes #3875

@meta-cla meta-cla Bot added the CLA Signed label Oct 6, 2025

@ashishresu2001 ashishresu2001 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi!
Could someone please review this PR: Add IndexBinaryIDMap2 support to index binary factory?
It adds support for IDMap2/IDMap prefix and suffix parsing in the index binary factory, normalizes description strings, and includes new unit tests for these cases.
All relevant tests have been run (pytest tests/test_binary_factory.py) and the CLA is signed.

Thank you!

@ashishresu2001 ashishresu2001 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

format

@mnorris11 mnorris11 self-assigned this Oct 14, 2025
@mnorris11

mnorris11 commented Oct 14, 2025

Copy link
Copy Markdown
Contributor

Hi @ashishresu2001 , sorry for the delay, I will review this today

@meta-codesync

meta-codesync Bot commented Oct 14, 2025

Copy link
Copy Markdown
Contributor

@mnorris11 has imported this pull request. If you are a Meta employee, you can view this in D84619819.

Comment thread faiss/index_factory.cpp Outdated
Comment on lines +943 to +945
desc_str.erase(
std::remove_if(desc_str.begin(), desc_str.end(), ::isspace),
desc_str.end());

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.

We do not need this part, we can assume it is incorrect if there are incorrect spaces. (We can follow the pattern of the other parts of the index_factory which do not have this handling)

Comment thread faiss/index_factory.cpp Outdated
desc_str.end());

// Check for IDMap2 or IDMap as prefix
if (desc_str.rfind("IDMap2,", 0) == 0 && desc_str.size() > 7) {

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.

Are you able to use the same approach of re_match as the other IDMap2 handling for non-binary index? i.e. like here:

if (re_match(description, "(.+),IDMap2", sm) ||
re_match(description, "IDMap2,(.+)", sm)) {
IndexIDMap2* idmap2 = new IndexIDMap2(
index_factory_sub(d, sm[1].str(), metric).release());
idmap2->own_fields = true;
return std::unique_ptr<Index>(idmap2);
}

(ideally we can keep it consistent)
This lets us consolidate to fewer conditions, since prefix and suffix should behave the same.

Comment thread faiss/index_factory.cpp Outdated

int ncentroids = -1;
int M, nhash, b;
const char* desc_cstr = desc_str.c_str();

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.

Why did we need to convert to a C style string here, if the input is a C style string?

@mnorris11

Copy link
Copy Markdown
Contributor

Thanks for this contribution @ashishresu2001 ! I just left a few small comments: we can make it closer to the existing approach. Otherwise looks great.

Comment thread tests/test_binary_factory.py Outdated
Comment on lines +56 to +59
def test_factory_IDMap2_with_spaces(self):
index = faiss.index_binary_factory(16, " IDMap2 , BFlat ")
assert isinstance(index, faiss.IndexBinaryIDMap2)
assert index.index.code_size == 2

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.

We are very grateful you added tests! We can remove this spaces one though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @mnorris11 , Thanks for the review. I’ve made the requested updates. Removed whitespace handling, switched to re_match for consistency, dropped the redundant C-string conversion, and removed the extra test.

@meta-codesync

meta-codesync Bot commented Oct 14, 2025

Copy link
Copy Markdown
Contributor

@mnorris11 merged this pull request in 484dd97.

AlSchlo pushed a commit to AlSchlo/faiss-panorama that referenced this pull request Oct 20, 2025
…ch#4603)

Summary:
- Add support for IDMap2/IDMap prefix and suffix parsing in index_binary_factory
- Normalize description string to handle whitespace
- Add unit tests for IDMap2 prefix, suffix, and whitespace cases

## Testing
- Ran: pytest tests/test_binary_factory.py

Fixes facebookresearch#3875

Pull Request resolved: facebookresearch#4603

Reviewed By: subhadeepkaran, junjieqi

Differential Revision: D84619819

Pulled By: mnorris11

fbshipit-source-id: 5a2ac77bdce36f3322d4e3d60bb857767e551c52
dimitraseferiadi pushed a commit to dimitraseferiadi/SuCo_CSPG_SHG that referenced this pull request Mar 8, 2026
…ch#4603)

Summary:
- Add support for IDMap2/IDMap prefix and suffix parsing in index_binary_factory
- Normalize description string to handle whitespace
- Add unit tests for IDMap2 prefix, suffix, and whitespace cases

## Testing
- Ran: pytest tests/test_binary_factory.py

Fixes facebookresearch#3875

Pull Request resolved: facebookresearch#4603

Reviewed By: subhadeepkaran, junjieqi

Differential Revision: D84619819

Pulled By: mnorris11

fbshipit-source-id: 5a2ac77bdce36f3322d4e3d60bb857767e551c52
dimitraseferiadi pushed a commit to dimitraseferiadi/SuCo_CSPG_SHG that referenced this pull request Mar 16, 2026
…ch#4603)

Summary:
- Add support for IDMap2/IDMap prefix and suffix parsing in index_binary_factory
- Normalize description string to handle whitespace
- Add unit tests for IDMap2 prefix, suffix, and whitespace cases

## Testing
- Ran: pytest tests/test_binary_factory.py

Fixes facebookresearch#3875

Pull Request resolved: facebookresearch#4603

Reviewed By: subhadeepkaran, junjieqi

Differential Revision: D84619819

Pulled By: mnorris11

fbshipit-source-id: 5a2ac77bdce36f3322d4e3d60bb857767e551c52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for IndexBinaryIDMap2 to index_binary_factory

3 participants