Repository navigation
fix(sysdb): delete embedding_metadata_array rows on collection delete - #7635
Open
nandinitiw wants to merge 1 commit into
Open
nandinitiw wants to merge 1 commit into
nandinitiw wants to merge 1 commit into
Conversation
delete_collection_with_conn deleted scalar embedding_metadata but never touched embedding_metadata_array (added later for list-valued metadata support in migration 00006). Combined with embeddings.id being declared without AUTOINCREMENT (so SQLite can reuse the rowid after all rows are deleted), a record in a newly created collection can be assigned the same internal id as a deleted collection's record, and the metadata segment's get() query - which joins embedding_metadata_array purely on that id with no segment/collection scoping - resurfaces the orphaned list-valued metadata from the deleted collection. Adds the matching DELETE FROM embedding_metadata_array, scoped and ordered identically to the existing embedding_metadata delete (must run before embeddings rows are removed, since it resolves ids via a join against embeddings). Regression test inserts an embeddings row + embedding_metadata_array row directly against a collection's segment, deletes the collection, and asserts embedding_metadata_array is empty afterward - fails without the fix (1 orphaned row) and passes with it. Fixes chroma-core#7594
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
3 of 4 tasks
This branch has not been deployed
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.
Fixes #7594
Problem
After
delete_collection(), a newly created collection's first record can silently inherit list-valued metadata from the deleted collection's first record. Scalar metadata is cleaned up correctly — only list-valued metadata leaks, and it happens whether or not the new collection reuses the deleted one's name, and survives a process restart (genuine on-disk state, not a cache).Root cause
delete_collection_with_conninrust/sysdb/src/sqlite.rsdeletes scalarembedding_metadatarows but never touchesembedding_metadata_array— the separate table introduced in migration00006-metadata-array-support.sqlite.sqlfor list-valued metadata (one row per array element).Combined with
embeddings.idbeing declaredINTEGER PRIMARY KEYwithoutAUTOINCREMENT(migration00001-embedding-metadata.sqlite.sql), SQLite is free to reuse that rowid once the table empties out. So:embeddings.id = 1; its list metadata (e.g.{"tags": ["stale"]}) is written toembedding_metadata_arraywithid = 1.delete_collectionwipes theembeddingsrow (id = 1gone) but leaves the orphanedembedding_metadata_arrayrow withid = 1behind.embeddings.id = 1(id space is reused once the table is empty/low).get()query (rust/segment/src/sqlite_metadata.rs) joinsembedding_metadata_arraypurely onid, with no segment/collection scoping — it finds the orphaned row and merges the deleted collection's list metadata into the new record's result.Fix
Add the missing
DELETE FROM embedding_metadata_arraytodelete_collection_with_conn, scoped and ordered identically to the existingembedding_metadatadelete (must run before theembeddingsrows are removed, since it resolves ids via a join againstembeddings).Testing
Added
test_delete_collection_cleans_array_metadatainrust/sysdb/src/sqlite.rs: inserts anembeddingsrow and anembedding_metadata_arrayrow directly against a collection's segment, deletes the collection viasysdb.delete_collection, and assertsembedding_metadata_arrayis empty afterward.Verified the test is a real regression guard, not a false positive — reverted the fix locally and confirmed the test fails (
left: 1, right: 0) against the buggy code, then confirmed it passes once the fix is restored.Full
chroma-sysdb(19 tests) andchroma-segment(83 tests, including all existing array-metadata tests) suites pass with no regressions.cargo fmt --checkandcargo clippy -- -D warningsare both clean.