fix(vector_io): align FAISS to upsert semantics for repeated chunk IDs - #6336
Open
yashanil98 wants to merge 1 commit into
Open
fix(vector_io): align FAISS to upsert semantics for repeated chunk IDs#6336yashanil98 wants to merge 1 commit into
yashanil98 wants to merge 1 commit into
Conversation
The FAISS index appended embeddings unconditionally, so re-ingesting a chunk with an existing chunk_id silently duplicated it, violating the upsert contract documented on VectorIO.insert_chunks and EmbeddingIndex.add_chunks. add_chunks now deduplicates within a batch and removes any existing entry that shares an incoming chunk_id before appending, reusing the position-shift logic already used by delete_chunks. Fixes ogx-ai#6256 Signed-off-by: Yash Anil <yashanil98@gmail.com>
yashanil98
requested review from
bbrowning,
cdoern,
franciscojavierarceo,
leseb,
mattf,
raghotham and
skamenan7
as code owners
July 21, 2026 20:32
There was a problem hiding this comment.
Pull request overview
This PR updates the inline FAISS EmbeddingIndex implementation to match the VectorIO.insert_chunks / EmbeddingIndex.add_chunks upsert contract by removing existing entries for repeated chunk_ids before appending new vectors, and adds unit tests to lock in the behavior.
Changes:
- Implement upsert-like behavior in
FaissIndex.add_chunksby de-duplicating within a batch and removing existing entries for incomingchunk_ids. - Extract deletion/position-shift logic into a shared
_remove_chunkhelper reused by bothadd_chunksanddelete_chunks. - Add unit tests covering cross-call replacement and within-batch de-duplication for repeated
chunk_ids.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ogx/providers/inline/vector_io/faiss/faiss.py | Adds upsert semantics to FAISS add_chunks and factors out shared removal logic. |
| tests/unit/providers/vector_io/test_faiss.py | Adds unit tests verifying replacement across calls and de-duplication within a batch. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+198
to
+201
| deduped: dict[str, EmbeddedChunk] = {} | ||
| for embedded_chunk in embedded_chunks: | ||
| deduped[embedded_chunk.chunk_id] = embedded_chunk | ||
| embedded_chunks = list(deduped.values()) |
Comment on lines
210
to
+213
| async with self.chunk_id_lock: | ||
| for chunk_id in [ec.chunk_id for ec in embedded_chunks if ec.chunk_id in self.chunk_ids]: | ||
| self._remove_chunk(chunk_id) | ||
|
|
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.
What does this PR do?
Finishes the FAISS part of #6256. PR #6260 aligned Milvus, ChromaDB, and SQLite-vec to upsert semantics and documented the contract on
VectorIO.insert_chunksandEmbeddingIndex.add_chunks, but left FAISS on pure-append semantics.The FAISS index called
self.index.add(embeddings)unconditionally, so re-ingesting a chunk with an existingchunk_idsilently created a duplicate.add_chunksnow deduplicates within a batch and removes any existing entry that shares an incomingchunk_idbefore appending. The removal reuses the position-shift logic already used bydelete_chunks, which is extracted into a_remove_chunkhelper.Closes #6256
Test Plan
Added two unit tests: one for replacing a chunk across separate
add_chunkscalls, one for deduplicating repeatedchunk_ids within a single batch. Both fail on the current code (index count grows to 3) and pass with this change.Output:
Full vector_io unit suite also passes: