Conversation
… merge_from Fixes facebookresearch#5576. IndexFlat1D maintains a sorted permutation array `perm` for binary search, which was only updated in `add()` and cleared in `reset()`. When `remove_ids()` or `merge_from()` was called, the inherited implementations from `IndexFlatCodes` compacted or appended elements and updated `ntotal`, leaving `perm` in a stale state with `perm.size() != ntotal`. Subsequent `search()` calls would throw a RuntimeError. This commit: - Overrides `remove_ids()` in `IndexFlat1D` to rebuild `perm` when `continuous_update=true` or invalidate it (`perm.clear()`) when `continuous_update=false`. - Overrides `merge_from()` in `IndexFlat1D` with matching permutation maintenance. - Adds regression tests in `TestFlat1D` covering deletion, empty match, complete clearance, continuous/manual update lifecycles, and index merging.
|
Hi @thlurte! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
… merging empty index
Fixes #5576.
Problem
IndexFlat1Dmaintains a sorted permutation arraypermfor binary search, which was previously only updated inadd()and cleared inreset().When
remove_ids()ormerge_from()was called, the inherited implementations fromIndexFlatCodescompacted or appended elements and updatedntotal, leavingpermin a stale state withperm.size() != ntotal. The subsequent call tosearch()would throw aRuntimeError: '!(perm.size() == static_cast<size_t>(ntotal))' failed: Call update_permutation before search.Solution
remove_ids: Override inIndexFlat1D:IndexFlatL2::remove_ids(sel).nremoved > 0):continuous_update == true, immediately callupdate_permutation().continuous_update == false, clearpermto invalidate it untilupdate_permutation()is explicitly invoked.merge_from: Override inIndexFlat1Dwith identical permutation maintenance.tests/test_index_accuracy.py(TestFlat1D.test_remove_idsandTestFlat1D.test_merge_from) covering:continuous_update=Truewith search immediately followingremove_ids.continuous_update=Falseverifying permutation invalidation and re-sorting.nremoved == 0).remove_ids.IndexFlat1Dindexes.