feat(embedding): add auto_rebuild for embedding dimension mismatch#2740
Open
wangling12 wants to merge 1 commit into
Open
feat(embedding): add auto_rebuild for embedding dimension mismatch#2740wangling12 wants to merge 1 commit into
wangling12 wants to merge 1 commit into
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨No code suggestions found for the PR. |
Add embedding.auto_rebuild config to automatically rebuild vector index when embedding dimension changes between config and existing collection. - Add auto_rebuild field to EmbeddingConfig (default: false) - Extract _auto_rebuild_collection helper with drop failure handling and recursion guard to prevent infinite loops - Add 4 test cases covering success, disabled, drop-failure, and legacy-collection paths - Document auto_rebuild in EN/ZH configuration guides
3d3848f to
35ccc64
Compare
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
Add
embedding.auto_rebuildconfiguration to automatically rebuild the vector index when the embedding dimension in the configuration differs from the existing collection. Previously, dimension mismatches between config and the existing collection would raiseEmbeddingRebuildRequiredErrorwith no automated recovery path. This feature extracts the duplicated auto-rebuild logic into a shared helper, adds proper error handling fordrop_collection()failures (which previously caused infinite recursion), and includes a recursion guard.Related Issue
Type of Change
Changes Made
auto_rebuildboolean field toEmbeddingConfig(default:false) inembedding_config.py_auto_rebuild_collectionhelper function incollection_schemas.pyto deduplicate the auto-rebuild logic that was previously copy-pasted across two dimension-mismatch branches (old collections without embedding metadata, and collections with embedding metadata)drop_collection()return value — raiseEmbeddingRebuildRequiredErroron failure instead of silently recursing into an infinite loop_allow_recurseguard parameter toinit_context_collectionto prevent recursive rebuild cyclestest_collection_schemas.pycovering all auto-rebuild pathsembedding.auto_rebuildin both EN and ZH configuration guides (docs/en/guides/01-configuration.md,docs/zh/guides/01-configuration.md)Testing
New test cases:
test_auto_rebuild_drops_and_recreates_on_dimension_mismatch— verifies collection is dropped and recreated when dimension mismatches andauto_rebuild=truetest_auto_rebuild_disabled_raises_error_on_dimension_mismatch— verifiesEmbeddingRebuildRequiredErroris raised whenauto_rebuildis not settest_auto_rebuild_raises_error_when_drop_fails— verifies the core bug fix:drop_collection()returningFalseraises an error instead of infinite recursiontest_auto_rebuild_old_collection_without_embedding_metadata— verifies auto-rebuild works for legacy collections that lack embedding metadata but have aDimensionfieldChecklist
Screenshots (if applicable)
N/A
Additional Notes