feat: OCR independent chunks + TMDb seed with file_uuid
- Rule 1 now creates OCR-only chunks instead of merging into ASRX - generate_seed_embeddings.py supports --file-uuid parameter - get_seeds() filters by file_uuid - identity_matcher.py uses file_uuid for seed matching - Push QDRANT_API_KEY to Python subprocesses - Face clustering uses frame+bbox matching instead of face_id - Portal uses JWT authentication - FilesView filter logic fixed
This commit is contained in:
@@ -46,11 +46,12 @@ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
FACENET_PATH = os.path.join(SCRIPT_DIR, "..", "models", "facenet512.mlpackage")
|
||||
|
||||
|
||||
def get_tmdb_identities(limit: int = None) -> List[Dict]:
|
||||
def get_tmdb_identities(limit: int = None, file_uuid: str = None) -> List[Dict]:
|
||||
"""Query PG for TMDb identities with profile photos
|
||||
|
||||
Args:
|
||||
limit: Max identities to process
|
||||
file_uuid: Filter by file_uuid via file_identities table
|
||||
|
||||
Returns:
|
||||
List of {id, uuid, name, tmdb_id, tmdb_profile}
|
||||
@@ -63,20 +64,34 @@ def get_tmdb_identities(limit: int = None) -> List[Dict]:
|
||||
|
||||
if SCHEMA == "public":
|
||||
table = "identities"
|
||||
file_table = "file_identities"
|
||||
else:
|
||||
table = f"{SCHEMA}.identities"
|
||||
file_table = f"{SCHEMA}.file_identities"
|
||||
|
||||
query = f"""
|
||||
SELECT id, uuid, name, tmdb_id, tmdb_profile
|
||||
FROM {table}
|
||||
WHERE source = 'tmdb' AND tmdb_profile IS NOT NULL
|
||||
ORDER BY id
|
||||
"""
|
||||
if file_uuid:
|
||||
query = f"""
|
||||
SELECT DISTINCT i.id, i.uuid, i.name, i.tmdb_id, i.tmdb_profile
|
||||
FROM {table} i
|
||||
JOIN {file_table} fi ON fi.identity_id = i.id
|
||||
WHERE i.source = 'tmdb' AND i.tmdb_profile IS NOT NULL
|
||||
AND fi.file_uuid = %s
|
||||
ORDER BY i.id
|
||||
"""
|
||||
if limit:
|
||||
query += f" LIMIT {limit}"
|
||||
cur.execute(query, (file_uuid,))
|
||||
else:
|
||||
query = f"""
|
||||
SELECT id, uuid, name, tmdb_id, tmdb_profile
|
||||
FROM {table}
|
||||
WHERE source = 'tmdb' AND tmdb_profile IS NOT NULL
|
||||
ORDER BY id
|
||||
"""
|
||||
if limit:
|
||||
query += f" LIMIT {limit}"
|
||||
cur.execute(query)
|
||||
|
||||
if limit:
|
||||
query += f" LIMIT {limit}"
|
||||
|
||||
cur.execute(query)
|
||||
rows = cur.fetchall()
|
||||
cur.close()
|
||||
conn.close()
|
||||
@@ -180,7 +195,7 @@ def extract_face_embedding(image_path: str) -> Optional[List[float]]:
|
||||
return None
|
||||
|
||||
|
||||
def generate_seed_embeddings(limit: int = None, dry_run: bool = False) -> Dict:
|
||||
def generate_seed_embeddings(limit: int = None, dry_run: bool = False, file_uuid: str = None) -> Dict:
|
||||
"""Generate embeddings for all TMDb identities
|
||||
|
||||
Args:
|
||||
@@ -198,14 +213,14 @@ def generate_seed_embeddings(limit: int = None, dry_run: bool = False) -> Dict:
|
||||
"errors": [],
|
||||
}
|
||||
|
||||
identities = get_tmdb_identities(limit)
|
||||
identities = get_tmdb_identities(limit, file_uuid)
|
||||
result["total"] = len(identities)
|
||||
|
||||
if not identities:
|
||||
print("[SEED] No TMDb identities with profile photos")
|
||||
print(f"[SEED] No TMDb identities with profile photos{' for ' + file_uuid if file_uuid else ''}")
|
||||
return result
|
||||
|
||||
print(f"[SEED] Found {len(identities)} TMDb identities")
|
||||
print(f"[SEED] Found {len(identities)} TMDb identities{' for ' + file_uuid if file_uuid else ''}")
|
||||
|
||||
if not dry_run:
|
||||
ensure_seeds_collection()
|
||||
@@ -259,6 +274,7 @@ def generate_seed_embeddings(limit: int = None, dry_run: bool = False) -> Dict:
|
||||
name=name,
|
||||
embedding=embedding,
|
||||
source="tmdb",
|
||||
file_uuid=file_uuid,
|
||||
tmdb_id=tmdb_id,
|
||||
)
|
||||
result["success"] += 1
|
||||
@@ -280,12 +296,13 @@ def main():
|
||||
parser.add_argument("--dry-run", action="store_true", help="Don't push to Qdrant")
|
||||
parser.add_argument("--tmdb-api-key", help="TMDb API key (optional, for rate limiting)")
|
||||
parser.add_argument("--output", help="Output JSON file path")
|
||||
parser.add_argument("--file-uuid", help="File UUID to generate seeds for")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.tmdb_api_key:
|
||||
TMDB_API_KEY = args.tmdb_api_key
|
||||
|
||||
result = generate_seed_embeddings(args.limit, args.dry_run)
|
||||
result = generate_seed_embeddings(args.limit, args.dry_run, args.file_uuid)
|
||||
|
||||
output_json = json.dumps(result, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user