Skip to content

fix: rebuild FAISS index on vector deletion#4178

Merged
whysosaket merged 1 commit intomem0ai:mainfrom
Br1an67:fix/issue-3787-faiss-delete
Mar 28, 2026
Merged

fix: rebuild FAISS index on vector deletion#4178
whysosaket merged 1 commit intomem0ai:mainfrom
Br1an67:fix/issue-3787-faiss-delete

Conversation

@Br1an67
Copy link
Copy Markdown
Contributor

@Br1an67 Br1an67 commented Mar 1, 2026

Description

The delete() method in FAISS vector store removed the vector from docstore and index_to_id but 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

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit Test

Updated test_delete to verify that the FAISS index is properly rebuilt after deletion:

  • index.reset() is called to clear the old index
  • index.add() is called with remaining vectors
  • index_to_id is remapped contiguously (e.g., deleting id at index 0 remaps index 1→0)

All 11 existing FAISS tests pass.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

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.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 1, 2026

CLA assistant check
All committers have signed the CLA.

@Br1an67
Copy link
Copy Markdown
Contributor Author

Br1an67 commented Mar 8, 2026

Hi — just a gentle bump on this. Happy to make any changes if needed!

Copy link
Copy Markdown
Contributor

@Himanshu-Sangshetti Himanshu-Sangshetti left a comment

Choose a reason for hiding this comment

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

@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).

@whysosaket whysosaket merged commit 27a6e78 into mem0ai:main Mar 28, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using FAISS vector db the delete function will not delete the vector from the FAISS index

5 participants