Repository navigation
fix(server): avoid duplicate face embeddings on refresh - #33709
Open
NikiforovG wants to merge 1 commit into
Open
NikiforovG wants to merge 1 commit into
NikiforovG wants to merge 1 commit into
Conversation
Contributor
|
Label error. Requires exactly 1 of: changelog:.*. Found: 🗄️server, auto-closed:template. A maintainer will add the required label. |
Contributor
|
This PR has been automatically closed as the description doesn't follow our template. Please make sure every section is present and filled in. After you edit it to match the template, the PR will automatically be reopened. |
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.
Description
Fixes #26373
Rerunning face detection on a manually tagged or imported face can fail with
duplicate key value violates unique constraint "face_search_pkey". The face already has an embedding, and the refresh tries to insert another row with the samefaceId.The refresh now updates the existing embedding. When several detections match the same tagged face, it writes one embedding, choosing the detection with the greatest bounding-box overlap. If the overlaps are equal within floating-point tolerance, the first detection wins. This also prevents PostgreSQL from trying to update the same row twice in one statement. Repeated matches to an existing machine-learning face preserve its embedding.
The repository writes embeddings in
faceIdorder so concurrent refreshes of the same faces acquire row locks in a consistent order.Credit to @spinninghypercube for identifying the duplicate-detection case and proposing the embedding upsert and per-face selection. Original analysis
How Has This Been Tested?
All three regression tests failed on unpatched
mainand passed with the fix:A separate local PostgreSQL check ran 12 pairs of concurrent refreshes. Each pair supplied the same 32 face IDs in opposite orders. All 12 pairs completed successfully.
Checklist:
src/services/uses repositories implementations for database calls, filesystem operations, etc.src/repositories/is pretty basic/simple and does not have any immich specific logic (that belongs insrc/services/)Please describe to which degree, if any, an LLM was used in creating this pull request.
An LLM was used to assist in writing the code and related tests.