Repository navigation
Conversation
…me document ID twice
Contributor
Coverage report (faiss)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Contributor
|
Hi @eric7h, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
HaystackBot
marked this pull request as draft
October 31, 2026 03:51
HaystackBot
marked this pull request as ready for review
October 31, 2026 04:43
Contributor
|
Thanks for signing the CLA, @eric7h! 🎉 This PR is now ready for review again and the reviewer has been re-assigned. |
This branch has not been deployed
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.
Related Issues
FAISSDocumentStore.write_documents.Proposed Changes:
When one
write_documentscall contains the same document ID twice (e.g. withDuplicatePolicy.OVERWRITE), the FAISS index ends up with an orphaned vector.Root cause: vectors are collected in
ids_to_add_to_index/vectors_to_addand only added to the index at the end of the call. When the second copy of an ID is processed, the overwrite path callsdelete_documents([doc.id]), which drops the ID mapping and callsremove_ids— but the first copy's vector is not in the index yet, so nothing is removed. Its vector is then still added at the end under an int ID that no longer maps to any document.Effects:
index.ntotalis larger thancount_documents(), andsearch()can return fewer thantop_kresults, because the orphan takes a slot in FAISS's top-k and is then skipped.Fix: keep the pending vectors in a dict keyed by document ID and drop the pending entry when that ID is overwritten later in the same batch.
How did you test it?
test_write_documents_overwrite_duplicate_in_same_batch_leaves_no_orphan_vector; it fails onmain(ntotal == 3, search returns onlya) and passes with the fix.pytest testsinintegrations/faiss: 103 passed, 2 skipped.ruff check,ruff format --checkandmypy(hatchtypesscript) pass.Notes for the reviewer
Small, self-contained change in
write_documents; behaviour for batches without duplicate IDs is unchanged.This PR was generated with an AI assistant. I have reviewed the changes and run the relevant tests.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:.