Feat: Implement Incremental Indexing Engine for Scalable Library Management
๐ Problem
Currently, library rescans may reprocess many or all images, even if they haven't changed.
For large libraries (10k+ images), this leads to:
- Slow refresh times
- Unnecessary ML reprocessing
- High CPU usage
- Poor scalability
There is no reliable mechanism to detect:
- Newly added files
- Modified files
- Deleted files
- Unchanged files
๐ก Proposed Solution
Implement a true Incremental Indexing Engine that:
- Stores file metadata (e.g., path, size, last modified time, optional hash)
- Processes only new or modified files
- Skips unchanged files
- Removes deleted files from the database
- Cleans associated embeddings and thumbnails
๐ฏ Expected Benefits
- Significant performance improvement for large libraries
- Reduced redundant ML inference
- Better database consistency
- Production-grade scalability
๐ ๏ธ Implementation Overview
- Extend image table schema to store file metadata
- Add comparison logic during rescans
- Update indexing pipeline to process only changed files
- Handle cleanup for deleted files
๐งช Acceptance Criteria
- Only new/modified files are processed during rescan
- Deleted files are removed from DB
- No redundant ML processing occurs
- Works reliably on large datasets (10k+ images)
๐ I would like to work on this issue.
๐ Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)
Hi @rahulharpal1603
Iโve gone through the issue and the current indexing flow, and Iโd like to confirm my understanding before starting implementation.
From what I see, the current rescan mechanism does not differentiate between:
new files
modified files
deleted files
unchanged files
which results in redundant ML embedding generation and full-library reprocessing.
Iโm proposing the following structured approach:
1๏ธโฃ Schema Extension (Backward Compatible)
Extend the image table to store:
file_path
file_size
last_modified_timestamp
optional hash (only if metadata comparison is insufficient)
2๏ธโฃ Incremental Comparison Logic During Rescan
If file not in DB โ process & insert
If metadata unchanged โ skip
If metadata changed โ reprocess & update embeddings
If DB entry missing on disk โ delete record + clean embeddings & thumbnails
3๏ธโฃ Cleanup & Consistency
Ensure associated embeddings are safely removed for deleted/modified files
Avoid redundant ML inference
4๏ธโฃ Testing Strategy
Validate behavior on:
newly added files
modified files
deleted files
large dataset simulation (10k+ entries)
Before I begin implementation, Iโd like to confirm:
Whether metadata-based detection is sufficient or if you prefer hash-based validation
If there are any architectural constraints I should follow for the indexing pipeline
Iโd be happy to take this up and submit a draft PR once the approach is aligned.
Looking forward to your feedback ๐
@rahulharpal1603 Sir can you please assign this issue to me ?
Hi @rahulharpal1603 , following up โ is this issue still open for assignment? Happy to work on this issue, can you please assign it to me?
@rahulharpal1603 @rohan-pandeyy following up on this.
Checked the recent commits before writing this โ PR #1481 (merged Aug 10) already does the "skip unchanged files" part. It stores file_mtime with file_size and skips a file if size, mtime, and thumbnail all match. Half of this issue is already done; it just wasn't linked here.
What's not done yet: deleted files. If a file is removed from disk, nothing cleans up its DB row, embeddings, or thumbnail. Over time, that leaves stale data in the library.
I want to take this scoped to just that:
Detect DB entries whose file no longer exists on disk during rescan Delete the row and clean up embeddings/tags/thumbnail tied to it Tests for deletion + regression tests for the unchanged/modified cases Can you assign this to me? Let me know if you want it scoped differently.
Hi @Devnil434 / maintainers,
Iโd like to contribute to #1186 if collaboration is possible.
I inspected the current image indexing flow and found that PictoPy already has part of the incremental mechanism: image metadata stores file size/mtime, unchanged files can be skipped, and existing image IDs are preserved through the path conflict update.
The remaining consistency gap Iโd like to address is modified-file invalidation. A modified image can currently retain its previous isTagged / isEmbedded state and derived data such as image classes, face embeddings, and semantic embeddings.
My proposed scope is:
- Explicitly distinguish new / unchanged / modified / deleted files during image indexing.
- Preserve the existing
image.idfor modified files. - Refresh thumbnail + metadata only for new/modified files.
- Invalidate stale derived ML/index data for modified images.
- Remove deleted files and associated derived data safely.
- Ensure unchanged images do not trigger thumbnail generation or ML inference.
- Add backend tests covering new, unchanged, modified, deleted, and mixed-rescan scenarios.
- Keep the implementation within the existing route โ utils โ database architecture rather than introducing a separate indexing subsystem.
Iโd be happy to work on this as a contribution while coordinating with whoever is currently working on the issue.
Would this scope be useful, or would you prefer me to take a specific sub-part of #1186?