fix: rebuild FAISS index on vector deletion#4178
Merged
whysosaket merged 1 commit intomem0ai:mainfrom Mar 28, 2026
Merged
Conversation
The delete() method removed the vector from docstore and index_to_id but never removed it from the actual FAISS index. This caused stale vectors to remain in the index and incorrect search results. Fix by reconstructing remaining vectors and rebuilding the index after deletion, ensuring index_to_id stays contiguous.
Contributor
Author
|
Hi — just a gentle bump on this. Happy to make any changes if needed! |
Himanshu-Sangshetti
approved these changes
Mar 23, 2026
Contributor
Himanshu-Sangshetti
left a comment
There was a problem hiding this comment.
@kartik-mem0 / @whysosaket, LGTM to merge
delete() used to update the docstore and index_to_id but left the underlying FAISS index unchanged, so deleted vectors could still affect search / leave the index out of sync with metadata.
This PR rebuilds the index after a delete so everything stays in line.
I reviewed the implementation and ran tests/vector_stores/test_faiss.py successfully on my machine (all tests passing).
utkarsh240799
approved these changes
Mar 27, 2026
whysosaket
approved these changes
Mar 28, 2026
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.
Description
The
delete()method inFAISSvector store removed the vector fromdocstoreandindex_to_idbut never removed it from the actual FAISS index. This caused stale vectors to remain searchable and corrupted search results after deletion.Fixes #3787
Type of change
How Has This Been Tested?
Updated
test_deleteto verify that the FAISS index is properly rebuilt after deletion:index.reset()is called to clear the old indexindex.add()is called with remaining vectorsindex_to_idis remapped contiguously (e.g., deleting id at index 0 remaps index 1→0)All 11 existing FAISS tests pass.
Checklist: