From d5a908077a556d60cf39ecbbb3317b3f0dd3039d Mon Sep 17 00:00:00 2001 From: liyizhouAI Date: Mon, 13 Apr 2026 15:31:16 +0800 Subject: [PATCH] perf: upgrade Graphiti LLM to Qwen 32B + improve progress feedback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Upgrade from Qwen2.5-7B to Qwen2.5-32B-Instruct (faster, better quality) - Add real-time progress messages: "正在处理第 X/Y 个文本块" - Log per-episode processing time - Expand progress range from 15-55% to 15-90% (no more episode polling step) - Add GRAPHITI_LLM_* separate config for graph building LLM Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- backend/app/api/graph.py | 2 +- backend/app/services/graphiti_client.py | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) 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 ==========