π Bugfix: re-embed chunk on content update#3250
Open
Lingxi-Li wants to merge 1 commit into
Open
Conversation
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.
π Bugfix: re-embed chunk on content update so stored vector stays in sync
ElasticSearchService.update_chunkacceptedcontentedits but wrote the new text to Elasticsearch without regenerating the embedding vector.The stored vector silently drifted out of sync with the stored text, degrading pure k-NN search and corrupting the vector half of hybrid search with no operator-visible signal.
This change regenerates and persists the embedding whenever the update payload includes a non-None
contentvalue, mirroring the resolution path thatcreate_chunkalready uses but with fail-loud semantics instead of create's silent-skip (see Follow-ups section).New behavior
contentkey in payload, orcontent=None) take a fast path: no knowledge-record lookup, no embedding call, noembeddingorembedding_model_idwritten.embedding_model_id, to avoid re-using a possibly stale model id.vdb_core.update_chunkis invoked; the error is wrapped through the existingexceptblock asException("Error updating chunk: ..."), matching the prior fail-loud convention.Changes
backend/services/vectordatabase_service.py:ElasticSearchService.update_chunknow detects caller-setcontent, resolves the embedding model from the knowledge base record viaget_knowledge_recordthenget_embedding_model_by_id, callsget_embeddings, and writesembeddingplusembedding_model_idonto the same flat payload sent tovdb_core.update_chunk.backend/consts/model.py:ChunkUpdateRequest.contentgainsmin_length=1so an explicit empty string is rejected at the schema boundary, mirroringChunkCreateRequest.content.content=Noneskip, and six fail-loud branches (missing tenant, missing knowledge record, missingembedding_model_id, unresolvable model,get_embeddingsraising, empty embedding result).test_update_chunk_builds_payload_and_calls_corewas rewritten to use the realChunkUpdateRequest, mock the two new resolution helpers, passtenant_id, and assert the newembedding/embedding_model_idfields.test_update_chunk_wrapped_exceptionwas switched to a metadata-only payload so the core-failure path is still exercised.test/backend/test_model_consts.pyadds the empty-string rejection plus a positive metadata-only construction assertion.Follow-ups
create_chunkfail-loud on embedding resolution failure, matching the convention this PR establishes forupdate_chunk.Today it silently proceeds without an
embeddingfield whentenant_idorembedding_model_idis missing or whenget_embeddingsraises, and only logs a warning.Deferred because the asymmetry is load-bearing β create-skip leaves an auditable missing field while update-stale leaves a wrong field that looks healthy β and flipping create may break callers that tolerate vector-less creates during KB setup churn, so it deserves its own caller-impact review.
embedding_model_name(matching the index mapping) butcreate_chunkwritesembedding_model_id, which lands as a dynamic field.The mismatch originates in
create_chunkand predates this PR;update_chunkmirrorscreate_chunkhere, so this PR perpetuates the mismatch rather than introducing or fixing it.