Skip to content

Fix IndexIVFFlatDedup::remove_ids not counting duplicate-id removals - #5570

Open
trang-nm-nguyen wants to merge 1 commit into
facebookresearch:mainfrom
trang-nm-nguyen:export-D118606761
Open

Fix IndexIVFFlatDedup::remove_ids not counting duplicate-id removals#5570
trang-nm-nguyen wants to merge 1 commit into
facebookresearch:mainfrom
trang-nm-nguyen:export-D118606761

Conversation

@trang-nm-nguyen

@trang-nm-nguyen trang-nm-nguyen commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary:
https://www.internalfb.com/monitoring/oncall_operator?board=1003685189388103&workItem=1079527385016771


IndexIVFFlatDedup::add_with_ids increments ntotal for every added vector,
including duplicates (n_add++ runs for every id, then ntotal += n_add). A
duplicate vector is not stored as a new inverted-list entry; it is recorded
only as an entry in the instances multimap that maps a stored representative
id to the duplicate id.

remove_ids, however, derived its return value and its ntotal decrement
solely from nremove — the count of physically shrunk inverted-list entries.
Removing a duplicate-only id (an id that appears only as a value in instances)
erases the instances entry but shrinks no list, so nremove stayed 0:
remove_ids returned 0 and left ntotal unchanged even though a valid id was
removed. The same undercount happened when a stored representative id was
removed but a surviving duplicate took over its slot (the slot is rewritten,
not shrunk).

The library maintains the invariant
ntotal == (physical inverted-list entries) + instances.size(), so the true
number of logically removed ids is
nremove + (instances_before - instances_after). This captures both the
physically removed entries and the net drop in instances (erasures minus the
toadd re-links used when a representative with several duplicates is removed).
The fix records instances.size() before the rebalance and adjusts the count
and ntotal decrement accordingly.

Differential Revision: D118606761

@meta-cla meta-cla Bot added the CLA Signed label Sep 3, 2026
@meta-codesync

meta-codesync Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@trang-nm-nguyen has exported this pull request. If you are a Meta employee, you can view the originating Diff in D118606761.

@meta-codesync meta-codesync Bot changed the title Fix IndexIVFFlatDedup::remove_ids not counting duplicate-id removals Fix IndexIVFFlatDedup::remove_ids not counting duplicate-id removals (#5570) Sep 3, 2026
meta-codesync Bot pushed a commit that referenced this pull request Sep 4, 2026
…5570)

Summary:

https://www.internalfb.com/monitoring/oncall_operator?board=1003685189388103&workItem=1079527385016771

---

`IndexIVFFlatDedup::add_with_ids` increments `ntotal` for every added vector,
including duplicates (`n_add++` runs for every id, then `ntotal += n_add`). A
duplicate vector is not stored as a new inverted-list entry; it is recorded
only as an entry in the `instances` multimap that maps a stored representative
id to the duplicate id.

`remove_ids`, however, derived its return value and its `ntotal` decrement
solely from `nremove` — the count of physically shrunk inverted-list entries.
Removing a duplicate-only id (an id that appears only as a value in `instances`)
erases the `instances` entry but shrinks no list, so `nremove` stayed 0:
`remove_ids` returned 0 and left `ntotal` unchanged even though a valid id was
removed. The same undercount happened when a stored representative id was
removed but a surviving duplicate took over its slot (the slot is rewritten,
not shrunk).

The library maintains the invariant
`ntotal == (physical inverted-list entries) + instances.size()`, so the true
number of logically removed ids is
`nremove + (instances_before - instances_after)`. This captures both the
physically removed entries and the net drop in `instances` (erasures minus the
`toadd` re-links used when a representative with several duplicates is removed).
The fix records `instances.size()` before the rebalance and adjusts the count
and `ntotal` decrement accordingly.

Differential Revision: D118606761
meta-codesync Bot pushed a commit that referenced this pull request Sep 5, 2026
…5570)

Summary:

https://www.internalfb.com/monitoring/oncall_operator?board=1003685189388103&workItem=1079527385016771

---

`IndexIVFFlatDedup::add_with_ids` increments `ntotal` for every added vector,
including duplicates (`n_add++` runs for every id, then `ntotal += n_add`). A
duplicate vector is not stored as a new inverted-list entry; it is recorded
only as an entry in the `instances` multimap that maps a stored representative
id to the duplicate id.

`remove_ids`, however, derived its return value and its `ntotal` decrement
solely from `nremove` — the count of physically shrunk inverted-list entries.
Removing a duplicate-only id (an id that appears only as a value in `instances`)
erases the `instances` entry but shrinks no list, so `nremove` stayed 0:
`remove_ids` returned 0 and left `ntotal` unchanged even though a valid id was
removed. The same undercount happened when a stored representative id was
removed but a surviving duplicate took over its slot (the slot is rewritten,
not shrunk).

The library maintains the invariant
`ntotal == (physical inverted-list entries) + instances.size()`, so the true
number of logically removed ids is
`nremove + (instances_before - instances_after)`. This captures both the
physically removed entries and the net drop in `instances` (erasures minus the
`toadd` re-links used when a representative with several duplicates is removed).
The fix records `instances.size()` before the rebalance and adjusts the count
and `ntotal` decrement accordingly.

Differential Revision: D118606761
@meta-codesync meta-codesync Bot changed the title Fix IndexIVFFlatDedup::remove_ids not counting duplicate-id removals (#5570) Fix IndexIVFFlatDedup::remove_ids not counting duplicate-id removals Sep 7, 2026
Summary:
https://www.internalfb.com/monitoring/oncall_operator?board=1003685189388103&workItem=1079527385016771

---

`IndexIVFFlatDedup::add_with_ids` increments `ntotal` for every added vector,
including duplicates (`n_add++` runs for every id, then `ntotal += n_add`). A
duplicate vector is not stored as a new inverted-list entry; it is recorded
only as an entry in the `instances` multimap that maps a stored representative
id to the duplicate id.

`remove_ids`, however, derived its return value and its `ntotal` decrement
solely from `nremove` — the count of physically shrunk inverted-list entries.
Removing a duplicate-only id (an id that appears only as a value in `instances`)
erases the `instances` entry but shrinks no list, so `nremove` stayed 0:
`remove_ids` returned 0 and left `ntotal` unchanged even though a valid id was
removed. The same undercount happened when a stored representative id was
removed but a surviving duplicate took over its slot (the slot is rewritten,
not shrunk).

The library maintains the invariant
`ntotal == (physical inverted-list entries) + instances.size()`, so the true
number of logically removed ids is
`nremove + (instances_before - instances_after)`. This captures both the
physically removed entries and the net drop in `instances` (erasures minus the
`toadd` re-links used when a representative with several duplicates is removed).
The fix records `instances.size()` before the rebalance and adjusts the count
and `ntotal` decrement accordingly.

Differential Revision: D118606761
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.

1 participant