feat(api): image map endpoints with cached UMAP projection and DBSCAN clusters - #37
Open
lstein wants to merge 1 commit into
Open
feat(api): image map endpoints with cached UMAP projection and DBSCAN clusters#37lstein wants to merge 1 commit into
lstein wants to merge 1 commit into
Conversation
lstein
marked this pull request as draft
August 2, 2026 22:23
lstein
force-pushed
the
feat/image-map-03-deps
branch
from
August 2, 2026 22:38
13a64aa to
fdb7e82
Compare
lstein
force-pushed
the
feat/image-map-04-projection
branch
from
August 2, 2026 22:38
236d5ef to
5091e5d
Compare
lstein
force-pushed
the
feat/image-map-04-projection
branch
from
August 3, 2026 01:38
5091e5d to
ec55e63
Compare
lstein
force-pushed
the
feat/image-map-03-deps
branch
from
August 3, 2026 01:38
fdb7e82 to
b86155a
Compare
lstein
force-pushed
the
feat/image-map-04-projection
branch
from
August 3, 2026 02:26
ec55e63 to
9a46659
Compare
lstein
marked this pull request as ready for review
August 3, 2026 18:28
lstein
force-pushed
the
feat/image-map-04-projection
branch
from
August 4, 2026 01:43
9a46659 to
589a09b
Compare
lstein
force-pushed
the
feat/image-map-03-deps
branch
from
August 4, 2026 01:43
b86155a to
3b0243b
Compare
lstein
force-pushed
the
feat/image-map-04-projection
branch
from
August 4, 2026 05:37
589a09b to
bbab55d
Compare
lstein
force-pushed
the
feat/image-map-03-deps
branch
from
August 4, 2026 05:37
3b0243b to
99ff815
Compare
lstein
force-pushed
the
feat/image-map-04-projection
branch
from
August 4, 2026 14:58
bbab55d to
fe1b01c
Compare
lstein
force-pushed
the
feat/image-map-03-deps
branch
from
August 4, 2026 14:58
99ff815 to
086926d
Compare
lstein
force-pushed
the
feat/image-map-04-projection
branch
from
August 4, 2026 22:32
fe1b01c to
d1976a2
Compare
lstein
force-pushed
the
feat/image-map-03-deps
branch
from
August 4, 2026 22:32
086926d to
178f253
Compare
lstein
force-pushed
the
feat/image-map-04-projection
branch
from
August 5, 2026 00:31
d1976a2 to
8754846
Compare
lstein
force-pushed
the
feat/image-map-03-deps
branch
from
August 5, 2026 00:31
178f253 to
41592b3
Compare
lstein
force-pushed
the
feat/image-map-04-projection
branch
from
August 5, 2026 01:18
8754846 to
285ea0b
Compare
… clusters
Adds the serving layer for the semantic image map:
- Pure projection math in `image_index/projection.py` (lazy imports so the
numba JIT never slows app startup): PhotoMapAI-tuned UMAP
(n_neighbors<=15, min_dist 0.05, cosine), per-request DBSCAN, and an
order-insensitive scope hash fingerprinting the accessible image set.
- Projection jobs on the index worker: deduplicated per user, run when the
index is quiescent, cached per (user_id, model_id), and announced with a
new `image_map_projection_ready` event routed to the user's socket room
(plus admins).
- New `/api/v1/image_map` router:
- `GET /points?eps=` serves the cached projection with live DBSCAN
clustering (eps adjustable without recompute) and never blocks on a
UMAP fit; missing/stale caches enqueue a recompute. Stale caches are
filtered against the current accessible set so un-shared or deleted
images never leak out of an old projection.
- `POST /refresh` (202) and `GET /status`.
- Admins get the all-images scope; regular users get their accessible set.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
lstein
force-pushed
the
feat/image-map-04-projection
branch
from
August 5, 2026 01:21
285ea0b to
8984cd4
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.
Summary
PR 4 of the Image Map stack (on the deps PR). Adds the serving layer:
image_index/projection.py, lazy imports so the numba JIT never slows startup): PhotoMapAI-tuned UMAP (n_neighbors<=15,min_dist 0.05, cosine, seeded); 2-3-point galleries fall back to a PCA projection (umap-learn cannot fit them); per-request DBSCAN with eps clamped relative to the projection's coordinate span and a hard point cap — both bound sklearn's O(pairs) neighborhood memory.(user_id, model_id). A failed fit caches an empty projection under the current scope hash — clients see "empty" instead of hot-looping recompute requests, and the next gallery change retries naturally./api/v1/image_maprouter:GET /points?eps=— serves the cached projection, never blocks on a UMAP fit; clustering + response assembly run off the event loop (asyncio.to_thread). Stale caches are filtered against the caller's current accessible set before clustering, so un-shared/deleted images neither appear nor influence visible cluster labels via density-chaining.POST /refresh(202),GET /status(index counts admin-only; projectionpoint_countfiltered to the current scope).image_map_projection_readysocket event routed touser:{id}+adminrooms in a single deduped emit.An adversarial review of this diff was run; both HIGH findings (2-3-image permanent failure loop; event-loop-blocking DBSCAN with measured OOM at 30k points/eps=2.0), the pre-filter clustering leak, duplicate admin emits, scope-pinning dedup, and the stale point-count leak are all fixed above with regression tests. Accepted trade-offs (documented): projection fits are single-threaded (seeded) and can occupy the worker for large galleries;
/pointsis unpaginated.Testing
59 tests: projection math (blob recovery, seed determinism, tiny-gallery PCA fallback, eps clamp, size cap), worker projection jobs (compute+cache+event, failure self-healing, dedup semantics), router auth matrix (no cross-user name/coordinate/count leakage; hidden points cannot influence visible clusters), staleness flips, live re-clustering.
🤖 Generated with Claude Code