Fix IndexIVFFlatDedup::remove_ids not counting duplicate-id removals - #5570
Open
trang-nm-nguyen wants to merge 1 commit into
Open
Fix IndexIVFFlatDedup::remove_ids not counting duplicate-id removals#5570trang-nm-nguyen wants to merge 1 commit into
trang-nm-nguyen wants to merge 1 commit into
Conversation
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 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
trang-nm-nguyen
force-pushed
the
export-D118606761
branch
from
September 7, 2026 03:57
3f8f2ca to
aab7535
Compare
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
trang-nm-nguyen
force-pushed
the
export-D118606761
branch
from
September 7, 2026 18:58
aab7535 to
1d49789
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
https://www.internalfb.com/monitoring/oncall_operator?board=1003685189388103&workItem=1079527385016771
IndexIVFFlatDedup::add_with_idsincrementsntotalfor every added vector,including duplicates (
n_add++runs for every id, thenntotal += n_add). Aduplicate vector is not stored as a new inverted-list entry; it is recorded
only as an entry in the
instancesmultimap that maps a stored representativeid to the duplicate id.
remove_ids, however, derived its return value and itsntotaldecrementsolely 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
instancesentry but shrinks no list, sonremovestayed 0:remove_idsreturned 0 and leftntotalunchanged even though a valid id wasremoved. 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 truenumber of logically removed ids is
nremove + (instances_before - instances_after). This captures both thephysically removed entries and the net drop in
instances(erasures minus thetoaddre-links used when a representative with several duplicates is removed).The fix records
instances.size()before the rebalance and adjusts the countand
ntotaldecrement accordingly.Differential Revision: D118606761