feat: add Qdrant _faces collection embedding push
- Add qdrant_faces.py utility module for _faces collection operations - Modify face_processor.py to push embeddings to Qdrant (CoreML extraction re-enabled) - Modify store_traced_faces.py to update trace_id in Qdrant after face tracking - Collection schema: 512D vectors, Cosine distance, fixed name '_faces' - Payload: file_uuid, frame, trace_id, bbox, confidence, identity_id/uuid, stranger_id - Batch size: 100 (default), configurable via QDRANT_BATCH_SIZE env var - Error handling: face_processor.py exits with error if Qdrant push fails
This commit is contained in:
@@ -27,6 +27,7 @@ from datetime import datetime
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "utils"))
|
||||
from qdrant_faces import update_trace_ids
|
||||
|
||||
# Config
|
||||
DB_URL = os.environ.get("DATABASE_URL", "postgresql://accusys@localhost:5432/momentry")
|
||||
@@ -204,6 +205,25 @@ def store_traced_faces(file_uuid: str, traced_json_path: str, schema: str = SCHE
|
||||
|
||||
conn.commit()
|
||||
|
||||
# Build trace_mapping for Qdrant update
|
||||
trace_mapping = {} # {frame: {bbox_key: trace_id}}
|
||||
for frame_num_str, frame_data in sorted(frames.items(), key=lambda x: int(x[0])):
|
||||
frame_num = int(frame_num_str)
|
||||
trace_mapping[frame_num] = {}
|
||||
for face in frame_data.get("faces", []):
|
||||
trace_id = face.get("trace_id")
|
||||
if trace_id is None:
|
||||
continue
|
||||
bbox_key = f"{face['x']}_{face['y']}_{face['width']}_{face['height']}"
|
||||
trace_mapping[frame_num][bbox_key] = trace_id
|
||||
|
||||
# Update Qdrant _faces collection with trace_id
|
||||
try:
|
||||
qdrant_updated = update_trace_ids(file_uuid, trace_mapping)
|
||||
except Exception as e:
|
||||
print(f"[TRACE] Warning: Qdrant trace_id update failed: {e}")
|
||||
qdrant_updated = 0
|
||||
|
||||
# Log trace summary
|
||||
cur.execute(
|
||||
f"SELECT COUNT(DISTINCT trace_id) FROM {schema}.face_detections WHERE file_uuid = %s AND trace_id IS NOT NULL",
|
||||
@@ -217,6 +237,8 @@ def store_traced_faces(file_uuid: str, traced_json_path: str, schema: str = SCHE
|
||||
print(
|
||||
f"[TRACE] Stored {total_stored} face detections, {db_trace_count} unique traces in DB"
|
||||
)
|
||||
if qdrant_updated > 0:
|
||||
print(f"[TRACE] Updated {qdrant_updated} Qdrant points with trace_id")
|
||||
return total_stored, db_trace_count
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user