fix(llm): failed to remove vectors when updating vid embedding#243
Merged
imbajin merged 2 commits intoapache:mainfrom May 20, 2025
Merged
fix(llm): failed to remove vectors when updating vid embedding#243imbajin merged 2 commits intoapache:mainfrom
imbajin merged 2 commits intoapache:mainfrom
Conversation
imbajin
previously approved these changes
May 20, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that vector removals in update_vid_embedding are persisted to disk by unconditionally writing the updated index after removals.
- Always call
to_index_fileafter removing vids so deletions are saved. - Retains existing behavior to write on additions.
hugegraph-llm/src/hugegraph_llm/operators/index_op/build_semantic_index.py
Outdated
Show resolved
Hide resolved
hugegraph-llm/src/hugegraph_llm/operators/index_op/build_semantic_index.py
Outdated
Show resolved
Hide resolved
…tic_index.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
imbajin
approved these changes
May 20, 2025
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.
Bug Report
After deleting vertices, running
update_vid_embeddingdoes not successfully remove the corresponding vectors.Initial State
vidembeddingsAfter Clearing Graph Data
After
update_vid_embeddingHowever, calling

get_vector_index_infostill shows 13vidembeddings.Problem Location
Function
get_vector_index_info:This logic is correct. It reads
graph_vid_vector_numfromgraph_vid_vector_index.index.ntotal.update_vid_embeddingCode AnalysisThis correctly identifies vectors to be removed and added.
self.vid_index.remove()implementation:This also seems correct.
Debug Output
Output:
→ This confirms that in-memory deletion is successful.
However, re-running
update_vid_embeddingagain shows:→ Confirms that the vector index file still contains 13 vectors (i.e., deletion was not persisted).
And this is verified by loading the index from file via:
Note: The result of this deletion was not saved.
Root Cause
In the full
BuildSemanticIndex.run()implementation:The call to
self.vid_index.to_index_file(self.index_dir)only happens ifadded_vidsis non-empty.So if you're only removing embeddings (i.e., no new vertices), the deletion is never persisted to disk.
Fix
Verification
Problem solved.