Commit Graph

667 Commits

Author SHA1 Message Date
Accusys 2bbbf1950d fix: integrate VLM into worker poll loop for auto-resume
- Move VLM trigger from TKG spawn to worker poll loop
- Each poll checks if VLM is incomplete and key_frames are ready
- If VLM was interrupted (server restart), next poll will restart it
- Removed duplicate VLM spawn from TKG block
2026-08-24 21:34:31 +08:00
Accusys b2378a219b fix: pipeline stats API now shows VLM summary progress
- Added trace_profiles query to compute vlm_done/vlm_total
- vlm_summary stage now shows actual progress (e.g. 312/4829)
- Status shows 'running' while in progress, 'completed' when done
2026-08-24 19:40:00 +08:00
Accusys 9f12e835b8 feat: add TraceArtifacts phase + VLM waits for all key_frame.jpg
- Add TraceArtifacts phase to TkgPhase enum (phase 18)
- Report progress as key_frame.jpg/key_face.jpg are created
- VLM trigger now polls until ALL key_frame.jpg files exist
  (was: started after TKG build, before artifacts were ready)
- Add iron rule to AGENTS.md: ask before removing data

Tested: Gamma 8 (27 traces) → 27/27 VLM summaries completed
2026-08-24 19:13:11 +08:00
Accusys d29b4804af fix: P5 VLM trigger after Face Dedup + sync label to on-disk JSON
- Move P5 VLM trigger from TKG block to Face Dedup block
  (trace_profiles DB is written by update_face_track_labels, not TKG)
- Update on-disk trace_profile.json label when Face Dedup updates names
- Add output_dir and redis_clone to Face Dedup spawn scope

Pipeline flow:
  Face → P2 Tracing → P3 Cluster → update_face_track_labels
    → DB trace_profiles + on-disk JSON updated
    → P5 VLM triggered with verified trace count
2026-08-23 15:21:43 +08:00
Accusys ff9fb9a4ca fix: make VLM non-blocking in ingestion check
VLM summary was blocking job completion, causing jobs created before
P5 deployment to be stuck forever (vlm=false, all_ok=false).

Now VLM logs progress but doesn't block: vlm_done_bool always true.
This allows older jobs to complete while VLM can be triggered
separately via API.
2026-08-23 03:10:58 +08:00
Accusys cce30ffacb revert: remove auto-create monitor_job in register
Register should only write videos table, not automatically create
monitor jobs. This violates the design principle that register does
not trigger deep scan.

The auto-pipeline (triggered only for new files with auto_pipeline_enabled)
handles job creation separately. Re-scan via processing API will handle
job creation when needed.
2026-08-23 02:44:48 +08:00
Accusys b8b8f2d6af fix: register creates monitor_job with full pipeline after unregister
When a file is re-registered after unregister, the monitor_job is
missing. The register function now checks if a job exists and creates
one with full pipeline processors (cut, asr, asrx, ocr, face,
face_cluster) if missing.

This ensures re-scan after unregister triggers the complete pipeline
including face detection → TKG → VLM summary (P5).
2026-08-22 23:51:10 +08:00
Accusys 58d80e34c6 fix: move P5 verify inside TKG spawn — guarantee DB committed before VLM
verify_traces_ready now runs synchronously after build_tkg().await
completes, not inside a separate spawned task. This guarantees the
DB transaction from TKG is fully committed before VLM checks for data.

Before: TKG spawn → P5 spawn (race: P5 may run before TKG DB commit)
After:  TKG spawn → build_tkg() await → verify → spawn VLM (sequential)
2026-08-22 22:36:14 +08:00
Accusys 906243fdc1 refactor: replace P5 polling with JOIN-based verification + timeout
B: Replace wait_for_traces polling with verify_traces_ready
   - Uses JOIN query: trace_profiles INNER JOIN tkg_nodes
   - Ensures trace_profiles data is consistent with TKG before VLM runs
   - Single query instead of 30 retry attempts

C: Add 5-minute timeout to VLM generation
   - tokio::time::timeout(300s) prevents worker from hanging
   - Logs completion stats or timeout error

This fixes the root cause: P5 no longer polls blindly waiting for
TKG to finish. The JOIN query only returns rows when both
trace_profiles AND tkg_nodes face_track entries exist.
2026-08-22 22:17:21 +08:00
Accusys 165af40f3c fix: upsert_trace_profile preserves VLM fields on conflict
The ON CONFLICT DO UPDATE clause was missing vlm_* columns, causing
Face Cluster (P3) label sync to overwrite and lose VLM data.

Added COALESCE preservation for:
  vlm_description, vlm_clothing, vlm_tags, vlm_location, vlm_setting,
  vlm_lighting, vlm_weather, vlm_hand_objects, vlm_has_plants,
  vlm_has_animals, vlm_background, vlm_bg_tags, vlm_model,
  vlm_embedding, vlm_point_id
2026-08-22 17:27:56 +08:00
Accusys 11d210ee55 feat: add VLM summary progress to scan status API
- Add VlmSummaryStats { total, done } to FileStatsResponse
- Query trace_profiles for vlm_description count
- Endpoint: GET /api/v1/stats/file/:uuid returns vlm_summary field
- Response: { "vlm_summary": { "total": 22, "done": 22 } }
2026-08-22 17:03:09 +08:00
Accusys 978b2b338b fix: P5 race condition — poll for trace_profiles before VLM generation
- Add wait_for_traces() helper: polls trace_profiles table every 2s
  up to 60s, returning when rows appear (TKG may still be writing)
- Replace one-shot face_count query in both P5 triggers (has_face +
  no-face paths) with polling
- Verified: 22/22 traces summarized for 9df18017, semantic search
  returns 10 VLM results with sim 0.601-0.696
2026-08-22 16:17:30 +08:00
Accusys 054545bccd feat: VLM summary vector search integration
- Add vlm_point_id column to trace_profiles (stores Qdrant point ID)
- Add upsert_chunk_embedding_u64 to QdrantDb (numeric ID support)
- Add chunk_id to VLM payload in Qdrant for search enrichment
- Update enrich_from_pg to fallback to VLM lookup when chunk not found
- Add /api/v1/file/:uuid/vlm-summary endpoint for manual trigger
- Fix VLM point_id: use u64 hash instead of string (Qdrant requirement)
- Fix VLM timeout: was 0 (immediate timeout), now 120s

Verified: semantic search returns [vlm] results with proper enrichment
2026-08-22 12:10:47 +08:00
Accusys 476a31ecc6 feat: P5 VLM Summary pipeline integration + trace_profile vlm_summary field
- Add src/core/processor/vlm_summary.rs: VLM + Embedding pipeline stage
  * Reads key_frame.jpg → Ollama llava:7b → vlm_description
  * Writes DB (vlm_description, vlm_model, vlm_embedding) + on-disk JSON
  * EmbeddingGemma → Qdrant upsert (chunk_type=vlm_summary)
  * Non-blocking: errors logged, does not prevent job completion
  * Redis progress tracking: vlm_summary stage N/M traces

- Add src/bin/backfill_trace_vlm.rs: manual backfill binary
  * Supports --file-uuid, --force, --limit flags
  * Concurrency: 2 parallel VLM calls

- Add vlm_embedding JSONB column to trace_profiles (schema + migration)
- Add vlm_summary field to FaceTraceProfile struct
- Add P5 trigger in job_worker.rs (has_face + no-face paths)
- Add VLM monitoring to ingestion_complete() (non-blocking)
- Update .env / .env.development: VISION_URL → Ollama 11434
2026-08-22 09:52:04 +08:00
Accusys 6d7b477b31 fix: TKG key frame/face selection uses best-confidence — match frontend label
- tkg.rs: key_frame/key_face/best_bbox now use best-confidence frame
  (was cq_best capture-quality) so thumbnails agree with trace_agent_api
  best_face_frame / [F..] labels
- keep cq_best_quality as trace-level stat only
- add backfill_trace_dirs + skip_existing resume mode
- trace_agent_api.rs regenerate-thumbnail: use strict > tie-break (reduce)
  matching list_traces_sorted so equal-confidence frames pick the same one
2026-08-20 01:27:35 +08:00
Accusys efa17d4b62 fix: preserve integers in trace_profile.json — no more .0 suffix on trace_id/frame/bbox 2026-08-16 23:41:15 +08:00
Accusys 78eb4fb8d9 docs: studio team guide — face_artifacts completion counts (new API fields) 2026-08-16 23:14:10 +08:00
Accusys dda0b7cc7f feat: expose face artifact completion counts (trace_profile/key_frame/key_face) in scan + traces APIs 2026-08-16 23:09:12 +08:00
Accusys e2b9999cba fix: run-server-3002.sh restart — exec replaced stop's process, start never ran 2026-08-16 14:09:10 +08:00
Accusys 7c9c3ded42 feat: opt-in face trace quality filter (min_trace_len/min_confidence, default off) 2026-08-16 09:36:23 +08:00
Accusys 2466a41eb8 perf: cut face_traced Qdrant I/O — merge trace-count scan (B1) + batch 1000 (B2) 2026-08-16 09:27:46 +08:00
Accusys 6c4c645337 docs: record charade pre_chunks cleanup (9.28M→57K rows, 19G→130M) 2026-08-16 08:49:11 +08:00
Accusys 0533248f2c fix: workspace pre_chunks dedup — stop 19GB re-dispatch bloat (A1) + charade analysis 2026-08-16 08:44:29 +08:00
Accusys 5e6a7b7d51 feat: round output JSON floats to 2dp + unify ensure_ascii for asr/asrx 2026-08-16 06:38:39 +08:00
Accusys 39e9ce4c3b fix: add min_capture_quality to FaceFilterSettings + trace profile fixes
- Add min_capture_quality to FaceFilterSettings (file_profile.rs)
- Fix store_traced_faces.py: load embeddings from Qdrant with_vector=True
- Fix face_tracker.py: force new traces when frame_gap > 30
- Fix backfill_trace_profiles.py: key_frame select=eq(n,N), bbox scaling, best_frame
- Add best_frame to FaceTraceProfile (Rust + Python)
- Fix min_capture_quality persistence in file-profile API
2026-08-13 10:12:21 +08:00
Accusys 71172fa354 fix: separate confidence and captureQuality in face detection output
Apple Vision provides two distinct scores:
- confidence: detection confidence (is this a face?)
- faceCaptureQuality: capture quality (is this face suitable for recognition?)

Previously these were mixed together as 'confidence'. Now both are
stored separately in the output JSON for downstream use.
2026-08-12 11:51:10 +08:00
Accusys e88f066d65 fix: update trigger_processing face defaults to Apple Vision (0.5/1)
Hard-coded 0.75/64 in trigger_processing API was overriding the new
Apple Vision defaults when re-triggering processing. Now uses 0.5/1
consistently.
2026-08-12 09:49:59 +08:00
Accusys 86f1fe8852 fix: restore Apple Vision default detection thresholds (0.5 / 1px)
job_worker.rs was overriding Apple Vision defaults with 0.75/64 even when
no face_settings were provided, causing fewer faces to be detected.

Now detect all faces with Vision defaults (confidence 0.5, min_size 1px);
filter later for display via face_filter settings.
2026-08-12 09:16:30 +08:00
Accusys 2e4559715b fix: tkg face_track drift — trace stability check + repair script
Part B (source fix): Enhanced TKG build Qdrant readiness check in
job_worker.rs. Previously only checked point count >= expected_faces,
which could fire before short traces finished uploading. Now verifies
trace_id stability: two consecutive scroll checks (2s apart) with same
unique trace count before proceeding.

Part A (repair): New scripts/repair_tkg_face_tracks.py reconciles Qdrant
_faces traces with PG tkg_nodes face_track rows, inserts missing ones.
Fixed 233 missing traces in 44c37c (1197 → 1430).
2026-08-12 06:21:18 +08:00
Accusys c1e158a368 fix: trace-profile API SQL errors (missing FROM alias + null decoding)
Two pre-existing bugs broke rename/get operations:

1. schema.rs: DO UPDATE referenced 'tp' alias from LEFT JOIN which is
   invisible in ON CONFLICT scope → 'missing FROM-clause entry for table tp'
   Fix: use {tp_table}.column instead of tp.column

2. profile.rs: SELECT tp.properties / tn.properties can be NULL when no
   trace_profile row exists but decoder expected non-optional Value
   → 'unexpected null; try decoding as an Option'
   Fix: decode as Option<serde_json::Value> and handle None in merge logic
2026-08-12 05:51:12 +08:00
Accusys 2b1af42d06 fix: keep all traces in face clustering (remove min_faces=4 cutoff)
Large files (>1000 traces) used min_faces_per_trace=4, silently dropping
short traces (<=3 face points) from dedup. For 44c37c this excluded
484/1430 traces (34%) — walk-ons and passers-by never got a person label.

Now use min_faces=1 constant; noise is handled by the confidence>=0.5
filter in cluster_by_trace instead of dropping short appearances.

Result on 44c37c: 1430/1430 traces clustered, 21717/21717 faces assigned,
clusters 104 -> 203.
2026-08-12 05:19:54 +08:00
Accusys 258f8c4e96 fix: face clustering speaker mapping + representative face_id
- auto_bind_speakers: remove dead DB writes to nonexistent talents table,
  output speaker_person_mapping metadata into face_cluster.json instead
- fix representative_face.face_id to use face_idx (was frame_idx twice,
  causing duplicate face_ids for multi-face frames)
- fix asrx segment field names (start_time/end_time) and pass correct
  asrx path (ASRX_JSON_PATH was stale after UUID reassignment)
2026-08-12 05:04:48 +08:00
Accusys 59ca6cdf83 feat: add regenerate trace thumbnail endpoint with bbox clamping
- validator::clamp_crop: clamp crop rect to frame dims (fixes OOB shift)
- tkg.rs: use clamp_crop in key_face crop paths (root-cause fix)
- trace_agent_api: POST /api/v1/file/:file_uuid/trace/:trace_id/regenerate-thumbnail
- docs: 26_trace_thumbnail_regenerate.md for Studio team
2026-08-12 03:04:19 +08:00
Accusys aa28bf93fb fix: resolve merge silent failure by fixing upsert_trace_profile SQL and backfilling data
- Fixed upsert_trace_profile() SQL: changed trace_profiles.xxx to tp.xxx in ON CONFLICT DO UPDATE
  to fix invalid reference to FROM-clause entry error
- Fixed cluster_agent.rs error handling: replaced 'let _ =' with proper error logging
- Created migration script to backfill trace_profiles from tkg_nodes for existing files
- Migration successfully inserted 98 missing trace_profiles records
- Verified merge now works correctly: traces_merged > 0 instead of silent no-op

This fixes both the rename 500 error and the merge silent failure, as they share
the same root cause in upsert_trace_profile() SQL.
2026-08-10 01:42:34 +08:00
Accusys 65da4b451a fix: resolve trace-profile UPSERT SQL error and face-filter route syntax
- Fixed upsert_trace_profile() SQL: replaced scalar subqueries with LEFT JOIN
  to properly reference trace_profiles table in backfill logic
- Fixed face_filter routes: changed {file_uuid} to :file_uuid syntax for
  axum 0.7.9 compatibility
- Both fixes resolve HTTP 500 errors in rename and 404 errors in face filter
- Verified both APIs working correctly with test requests
2026-08-10 00:04:15 +08:00
Accusys d6f45683a0 fix: resolve trace-profile UPSERT SQL error and face-filter route syntax
- Fixed upsert_trace_profile() SQL: replaced scalar subqueries with LEFT JOIN
  to properly reference trace_profiles table in backfill logic
- Fixed face_filter routes: changed {file_uuid} to :file_uuid syntax for
  axum 0.7.9 compatibility
- Both fixes resolve HTTP 500 errors in rename and 404 errors in face filter
2026-08-09 23:41:11 +08:00
Accusys a3eba898e2 fix: update face filter API routes to avoid conflicts with identity_api
Changed routes to use /face-filter/ prefix to avoid conflicts:
- /api/v1/file/{uuid}/face-filter/faces
- /api/v1/file/{uuid}/face-filter/{faceId}/report
- /api/v1/file/{uuid}/face-filter/apply
- /api/v1/file/{uuid}/face-filter/stats
- /api/v1/file/{uuid}/face-filter/rules
2026-08-09 22:34:12 +08:00
Accusys 56ce009d84 docs: add hybrid mode implementation guide for Studio team
- Comprehensive guide for implementing hybrid filtering mode
- Includes architecture design with data layering
- Complete TypeScript code examples for all components
- Performance optimization strategies (LRU cache, lazy loading, virtual scroll)
- Best practices and common pitfalls to avoid
- Extension suggestions for future features

This document enables Studio team to implement the hybrid mode
efficiently with clear guidelines and examples.
2026-08-09 19:53:32 +08:00
Accusys 4fc7d0cf6d docs: add Studio team face filter usage guide
- Comprehensive API usage guide for Studio team
- Includes all 6 API endpoints with examples
- Complete TypeScript code examples
- Filtering strategies and best practices
- Performance optimization recommendations
- Based on FaceNet analysis results from WD and KOBA videos

This document enables Studio team to integrate face filtering
functionality efficiently.
2026-08-09 19:27:35 +08:00
Accusys dfa515f249 feat: add bbox_size field for frontend filtering
- Database: Added bbox_size column (min(width, height)) to face_filter_features
- API: Updated all endpoints to include bbox_size in responses
- Documentation: Added bbox_size explanation and frontend filtering examples
- Maintains current Swift implementation calculation method
- Enables efficient frontend filtering without backend threshold

This allows the frontend to do real-time filtering using bbox_size
while the backend pre-computes and stores the value.
2026-08-09 19:05:09 +08:00
Accusys 9b6750b85e feat: implement face filter API for GUI filtering mechanism
- Database schema: face_filter_features and filter_rules tables
- Core engine: FilterEngine with 4 filter rules (landmark, mediapipe, embedding, temporal)
- API endpoints:
  - GET /faces - Get faces with filtering
  - GET /face/{id}/filter-report - Get filter report for single face
  - POST /faces/filter - Apply filter rules
  - GET /filter-stats - Get filter statistics
  - GET/POST /filter-rules - Manage filter rules
- API documentation for Studio team with examples
- Based on FaceNet analysis results from WD and KOBA videos
2026-08-09 17:11:07 +08:00
Accusys 575623c765 docs: add cross-video FaceNet analysis report (WD vs KOBA)
- Completed FaceNet experiments on KOBA video (120 samples)
- Cross-video analysis confirms:
  - Face size impact on stability is CONSISTENT (Large > Medium > Small)
  - Bbox quality is CONSISTENT (Apple Vision ≈ MediaPipe)
  - Recognition accuracy depends on video content
- Key recommendations:
  - Minimum face size: 80px
  - Bbox strategy: Apple Vision (default) or MediaPipe (efficient)
  - Quality metric: Minimum similarity > 0.70
- Based on 240 total samples across 2 videos
2026-08-09 15:57:10 +08:00
Accusys 1f71ab4e14 docs: add FaceNet retest analysis report
- Completed 3 experiments using real FaceNet model (Inception ResNet V1)
- Key findings:
  - Large faces (>150px) have highest stability (0.9995)
  - Apple Vision and MediaPipe bboxes produce identical quality (0.899)
  - Face size affects recognition accuracy lower bound (0.760 vs 0.648)
- Recommendations:
  - Minimum face size: 80px
  - Ideal face size: >150px
  - Both AV and MP bboxes are acceptable
- Included detailed comparison with simplified model results
2026-08-09 14:43:33 +08:00
Accusys 61b774ab0b docs: add embedding vs face size analysis report
- Completed 3 experiments on WD video with 120 samples
- Key findings:
  - Apple Vision bbox produces higher quality embeddings (0.841 vs 0.748)
  - MediaPipe bbox is more precise but lower quality
  - Recommendation: Use Apple Vision bbox for embedding calculation
- Included detailed methodology, results, and recommendations
- Suggested bbox selection strategy and size filtering thresholds
2026-08-09 14:25:44 +08:00
Accusys 496895422f docs: add MediaPipe threshold POC report
- Tested confidence thresholds: 0.1, 0.2, 0.3, 0.4, 0.5
- Key finding: 0.3 is optimal threshold
  - Zero false positives (correctly rejects frames 671, 1116)
  - Same detection rate as 0.5 (100%)
  - More permissive than 0.5, may detect more faces in other videos
- Recommendation: Use 0.3 as default min_confidence for MediaPipe
- Updated dual-source filtering strategy:
  - Apple Vision: primary detector (min_confidence=0.5, min_size=1)
  - MediaPipe: verifier (min_confidence=0.3)
2026-08-09 13:36:51 +08:00
Accusys e1eae6a3d9 test: MediaPipe 1.0.0 vs 0.10.35 comparison results
- Upgraded MediaPipe from 0.10.35 to 1.0.0
- Re-ran same frame comparison experiment
- Key finding: MediaPipe 1.0.0 and 0.10.35 have identical performance
- Both versions: 2.5% recall, 100% precision (zero false positives)
- Apple Vision: 96.1% recall, 0% precision (3 false positives)
- Conclusion: MediaPipe is very conservative but reliable for false positive rejection
2026-08-09 12:55:49 +08:00
Accusys c7690f43d2 docs: add MediaPipe vs Apple Vision landmark comparison report
- Parallel detection on same frames (0, 3, 6, 9, 100, 200, 300, 400, 500, 671, 800, 1000, 1116, 1500)
- MediaPipe saves results as .mp_face.json format
- Key finding: MediaPipe 100% rejects false positives (frames 671, 1116)
- Trade-off: MediaPipe has lower recall (62.5% vs 100% for Apple Vision)
- Recommendation: Consider combining both detectors for best precision/recall balance
2026-08-09 12:42:56 +08:00
Accusys 5045d9f679 docs: update face_settings guide with correct log verification steps
- Updated log paths and examples to match actual implementation
- Added [WORKER] log verification
- Fixed swift_face log path (file_uuid.face_detect.json.log)
2026-08-08 23:24:08 +08:00
Accusys 1571f675a5 fix: worker reads face_settings from job and sets env vars for face processor
- job_worker.rs: Read face_settings from monitor_jobs before processing
- job_worker.rs: Set FACE_MIN_CONFIDENCE and FACE_MIN_SIZE env vars
- job_worker.rs: Restore env vars after processing completes
- Add detailed logging: [WORKER] face_settings and env var changes

This ensures the executor receives the correct face settings from the job.
2026-08-08 23:16:35 +08:00
Accusys 658f509500 fix: pass face_settings to create_monitor_job in register and process endpoints
- files.rs: register_file now converts FaceSettings to json and passes to create_monitor_job
- processing.rs: ProcessRequest now includes face_settings field
- processing.rs: trigger_processing now passes face_settings to create_monitor_job and updates existing jobs
- docs: updated API examples to use correct endpoints (/api/v1/files/register and /api/v1/files/:uuid/process)
2026-08-08 22:16:06 +08:00