perf: cut face_traced Qdrant I/O — merge trace-count scan (B1) + batch 1000 (B2)
This commit is contained in:
@@ -35,7 +35,9 @@ QDRANT_API_KEY = os.environ.get("QDRANT_API_KEY", "Test3200Test3200Test3200")
|
||||
FACES_COLLECTION = "_faces"
|
||||
SEEDS_COLLECTION = "_seeds"
|
||||
VECTOR_DIM = 512
|
||||
BATCH_SIZE = int(os.environ.get("QDRANT_BATCH_SIZE", "100"))
|
||||
# Default 1000 (was 100): larger pages cut the number of scroll/set_payload HTTP
|
||||
# round-trips ~10x on large files (B2). Still overridable via QDRANT_BATCH_SIZE.
|
||||
BATCH_SIZE = int(os.environ.get("QDRANT_BATCH_SIZE", "1000"))
|
||||
|
||||
|
||||
def qdrant_request(method: str, path: str, body: dict = None) -> dict:
|
||||
@@ -158,7 +160,9 @@ def push_face_embeddings_batch(file_uuid: str, faces: list, publisher=None) -> i
|
||||
return pushed
|
||||
|
||||
|
||||
def update_trace_ids(file_uuid: str, trace_mapping: dict) -> int:
|
||||
def update_trace_ids(
|
||||
file_uuid: str, trace_mapping: dict, return_trace_ids: bool = False
|
||||
):
|
||||
"""Update trace_id for all face points in a file
|
||||
|
||||
Called by store_traced_faces.py after face tracking.
|
||||
@@ -168,9 +172,12 @@ def update_trace_ids(file_uuid: str, trace_mapping: dict) -> int:
|
||||
file_uuid: Video file UUID
|
||||
trace_mapping: {frame: {bbox_key: trace_id}}
|
||||
bbox_key = f"{x}_{y}_{width}_{height}"
|
||||
return_trace_ids: If True, also return the set of trace_ids seen during the
|
||||
scroll. This lets the caller avoid a redundant full collection scan just
|
||||
to count unique traces (B1 optimization for large files).
|
||||
|
||||
Returns:
|
||||
Number of updated points
|
||||
Number of updated points, or (updated_count, trace_id_set) if return_trace_ids.
|
||||
"""
|
||||
all_points = []
|
||||
offset = None
|
||||
@@ -217,7 +224,7 @@ def update_trace_ids(file_uuid: str, trace_mapping: dict) -> int:
|
||||
trace_groups[trace_id].append(point_id)
|
||||
|
||||
if not trace_groups:
|
||||
return 0
|
||||
return (0, set()) if return_trace_ids else 0
|
||||
|
||||
# Use set_payload per trace_id group (no vector write)
|
||||
total = 0
|
||||
@@ -228,6 +235,8 @@ def update_trace_ids(file_uuid: str, trace_mapping: dict) -> int:
|
||||
total += len(batch_ids)
|
||||
|
||||
print(f"[QDRANT] Updated {total} trace_ids in {FACES_COLLECTION}")
|
||||
if return_trace_ids:
|
||||
return total, set(trace_groups.keys())
|
||||
return total
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user