Skip to content

Feat/ai jetstream listener#30

Merged
wailbentafat merged 47 commits intodevelopfrom
feat/ai-jetstream-listener
Mar 25, 2026
Merged

Feat/ai jetstream listener#30
wailbentafat merged 47 commits intodevelopfrom
feat/ai-jetstream-listener

Conversation

@Tyjfre-j
Copy link
Collaborator

@Tyjfre-j Tyjfre-j commented Mar 22, 2026

Summary

This PR implements a single‑face image matching worker driven by JetStream/NATS. The worker listens for face‑match requests, fetches images from MinIO, generates embeddings for single‑face images only, matches against users via pgvector similarity, and records the match. The flow is event‑driven, idempotent, and includes explicit guardrails + logging for failure modes.

Full Workflow

  1. Event Trigger
    A job is published to photo_faces.single.requested (JetStream).
    Payload includes photo_id, image_ref, optional face_index, optional faces_detected, and extra metadata (ignored).

  2. Subscription & Validation
    SingleFaceMatchWorker subscribes using a durable consumer.
    Payload is validated via SingleFaceMatchJob; malformed payloads are logged and skipped.

  3. Guardrails

If faces_detected is provided and != 1 → skip
If image_ref missing → skip
If photo_id not found → skip
If match already exists for photo → skip (idempotency)
4) Image Fetch (MinIO)
image_ref is parsed and fetched from MinIO.
Transient failures are retried with linear backoff.

  1. Face Detection / Embedding
    Image is decoded; all faces are detected.
    If not exactly one face → skip.
    Embedding + bounding box extracted.

  2. Upsert photo_faces
    Writes photo_id, face_index, embedding, bbox.
    DB errors are logged + rolled back.

  3. User Matching
    Finds closest user via pgvector similarity:
    ORDER BY face_embedding <=> :embedding LIMIT 1
    If no user embeddings → skip.

  4. Insert face_matches
    If match doesn’t exist, insert new row with confidence = distance.

@Tyjfre-j Tyjfre-j changed the base branch from main to develop March 23, 2026 23:20
@Tyjfre-j Tyjfre-j marked this pull request as draft March 24, 2026 21:09
@wailbentafat wailbentafat force-pushed the feat/ai-jetstream-listener branch from 4cd2c80 to 255c84a Compare March 25, 2026 17:18
@Tyjfre-j Tyjfre-j force-pushed the feat/ai-jetstream-listener branch from c5fe0e0 to 3bb3bad Compare March 25, 2026 20:29
@Tyjfre-j Tyjfre-j marked this pull request as ready for review March 25, 2026 20:30
Copy link
Collaborator

@wailbentafat wailbentafat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file structure is wrong u will fix it in the next pr

@Tyjfre-j
Copy link
Collaborator Author

Bon.

@wailbentafat wailbentafat merged commit 297a707 into develop Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants