diff --git a/wwwroot/knowledge_bases_list/upload_file.dspy b/wwwroot/knowledge_bases_list/upload_file.dspy index 91c1add..5bebc4a 100644 --- a/wwwroot/knowledge_bases_list/upload_file.dspy +++ b/wwwroot/knowledge_bases_list/upload_file.dspy @@ -106,7 +106,10 @@ async def ingest_doc(doc_id, kb_id, file_name, ext_l, real_path): fd = json.loads(resp) results = fd.get("results", []) if results and isinstance(results[0], dict): - face_count = len(results[0].get("faces", results[0].get("detections", []))) + faces = results[0].get("faces", results[0].get("detections", [])) + face_count = len(faces) + if faces and isinstance(faces[0], dict): + meta_parts['face_bboxes'] = [f.get("bbox", {}) for f in faces[:10]] meta_parts['face'] = face_count except: pass @@ -133,13 +136,16 @@ async def ingest_doc(doc_id, kb_id, file_name, ext_l, real_path): with open(tmp_img, 'rb') as fi: frame_data = fi.read() img_b64 = base64.b64encode(frame_data).decode() + frame_bboxes = [] try: client = StreamHttpClient() resp = await client.request('POST', 'https://media.opencomputing.net:10443/face/api/detect', json={"images": [img_b64]}) fd = json.loads(resp) results = fd.get("results", []) if results and isinstance(results[0], dict): - face_count = len(results[0].get("faces", results[0].get("detections", []))) + faces = results[0].get("faces", results[0].get("detections", [])) + face_count = len(faces) + frame_bboxes = [f.get("bbox", {}) for f in faces[:10]] if faces else [] except: pass # --- CLIP image embedding for video frame --- try: @@ -158,12 +164,16 @@ async def ingest_doc(doc_id, kb_id, file_name, ext_l, real_path): {"id": doc_id + "_c0", "vector": img_embeddings[0], "text": file_name} ]} await client3.request('POST', 'https://vectordb.opencomputing.net:10443/v1/upsert', json=vdb_data) + chunk_meta = {"start_time": 0} + if frame_bboxes: + chunk_meta["bboxes"] = frame_bboxes async with db.sqlorContext('rag') as sor: await sor.sqlExe( - "INSERT INTO document_chunks (id, doc_id, kb_id, chunk_index, content, vector_id, created_at) " - "VALUES (${id}$, ${doc_id}$, ${kb_id}$, 0, ${content}$, ${vid}$, NOW())", + "INSERT INTO document_chunks (id, doc_id, kb_id, chunk_index, content, vector_id, metadata, created_at) " + "VALUES (${id}$, ${doc_id}$, ${kb_id}$, 0, ${content}$, ${vid}$, ${meta}$, NOW())", {"id": doc_id + "_c0", "doc_id": doc_id, "kb_id": kb_id, - "content": file_name, "vid": doc_id + "_c0"}) + "content": file_name, "vid": doc_id + "_c0", + "meta": json.dumps(chunk_meta, ensure_ascii=False)}) except: pass os.remove(tmp_img)