Repository navigation
fix(knowledge): preserve shared image vectors when editing segment attachments - #45237
Open
Zhi-Xiang-Guo wants to merge 1 commit into
Open
Zhi-Xiang-Guo wants to merge 1 commit into
Zhi-Xiang-Guo wants to merge 1 commit into
Conversation
Zhi-Xiang-Guo
requested review from
JohnJyong and
QuantumGhost
as code owners
November 1, 2026 07:39
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
Removing a shared image from segment A previously deleted its dataset-level vector even when segment B still referenced it. A subsequent retrieval returned no image despite B's binding remaining intact.
Compute removed and added attachments separately. Before deleting removed vectors, query other bindings within the same tenant and dataset; preserve vectors owned by those bindings, including disabled segments and other documents. Leave retained vectors untouched and embed only newly added attachments. Existing upload files are not deleted.
Related Issues
Fixes #45236. #42642 concerns document deletion; #44402 dataset deletion; #44434 disabled-segment deletion; #41777 omitted attachment_ids. This patch covers explicit attachment edits.
Module(s) Affected
api/services/knowledge/segments/indexing.pyapi/repositories/knowledge/segment_repository.pyTesting
10 behavior regressions cover Console/Service API adapters, same/cross-document sharing, enabled/disabled owners and retained-vector reuse. They all fail on baseline. A further repository scope test fails on baseline because the new query does not exist. All 11 pass with the fix; expanded related suite: 143 passed.
Actual source API + official plugin + real local CLIP + Qdrant: retrieval/images change 1→0 before, 1→1 after removing A, then 1→0 after removing final B. The upload record remains.
main@4c521a3c0a1f60607c8a7bcf90792f34adcf18d0; branchfix/shared-segment-attachment-index; commit8c3efb6c9dfac48e2b204c234ff309ed9b45abe3.git diff --checkpassed. Import linter: 78 contracts kept, 0 broken. Response contract lint: 762 valid, 0 mismatch, 378 unknown (not a claim of full coverage).action_required; CI has not passed. Independent human code review is pending.Checklist
Additional Notes
AI-assisted implementation and validation. The query protects references present when the edit checks them; it is not a cross-store transaction or global lock. Concurrent edits, vector-provider failure mid-operation, and other deletion/indexing paths retain their existing coordination limitations. Existing missing vectors are not automatically repaired by this patch; an actual reindex or remove/re-add operation is needed.
Known separate provider limitation: Qdrant delete_by_ids can delete matching attachment IDs across datasets in a shared collection (discussed in #42642). This PR fixes same-dataset attachment edits and does not change provider deletion filters or claim cross-dataset deletion safety.