diff --git a/backend/app/api/graph.py b/backend/app/api/graph.py index f20d1a6a..766df089 100644 --- a/backend/app/api/graph.py +++ b/backend/app/api/graph.py @@ -424,7 +424,7 @@ def build_graph(): # 添加文本(progress_callback 签名是 (msg, progress_ratio)) def add_progress_callback(msg, progress_ratio): - progress = 15 + int(progress_ratio * 40) # 15% - 55% + progress = 15 + int(progress_ratio * 75) # 15% - 90% task_manager.update_task( task_id, message=msg, diff --git a/backend/app/services/graphiti_client.py b/backend/app/services/graphiti_client.py index c8f667fb..f1cebc77 100644 --- a/backend/app/services/graphiti_client.py +++ b/backend/app/services/graphiti_client.py @@ -267,14 +267,17 @@ class GraphitiClient: edge_types: Optional[Dict] = None, progress_callback=None, ): - """Add multiple text episodes sequentially (Graphiti processes one at a time).""" + """Add multiple text episodes sequentially with real-time progress.""" total = len(texts) + import time as _time for i, text in enumerate(texts): + # Report progress BEFORE processing (so user sees "正在处理 2/5...") if progress_callback: progress_callback( - f"Processing episode {i + 1}/{total}", - (i + 1) / total, + f"正在处理第 {i + 1}/{total} 个文本块(Graphiti 实体提取中...)", + i / total, ) + start = _time.time() try: self.add_episode( graph_id, text, source_description, @@ -283,9 +286,18 @@ class GraphitiClient: except Exception as e: logger.error(f"Failed to add episode {i + 1}/{total}: {e}") raise + elapsed = _time.time() - start + logger.info(f"Episode {i + 1}/{total} processed in {elapsed:.1f}s") + + # Report completion of this episode + if progress_callback: + progress_callback( + f"第 {i + 1}/{total} 个文本块处理完成(用时 {elapsed:.0f}s)", + (i + 1) / total, + ) # Small delay to avoid rate limiting if i < total - 1: - time.sleep(0.5) + _time.sleep(0.3) # ========== Search ==========