From 5add3a070d7735543078221098296997e582c789 Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Mon, 18 May 2026 23:53:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=9F=A5=E8=AF=86=E5=9B=BE=E8=B0=B1?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=A2=9E=E5=8A=A0=E5=AE=9E=E4=BD=93/?= =?UTF-8?q?=E5=85=B3=E7=B3=BB=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - KnowledgeGraphRepository 新增 count_by_db_id 方法 - MilvusGraphService.get_status 返回 entity_count 和 relationship_count - 知识图谱管理面板展示实体与关系计数 - 修复重置按钮在构建中不可见的问题 - 调整默认并发数为 50 Co-authored-by: xerrors --- .../yuxi/knowledge/graphs/milvus_graph_service.py | 6 +++++- .../yuxi/repositories/knowledge_graph_repository.py | 10 ++++++++++ backend/test/unit/graphs/test_milvus_graph_build.py | 5 ++++- web/src/components/KnowledgeGraphSection.vue | 12 ++++++++++-- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/backend/package/yuxi/knowledge/graphs/milvus_graph_service.py b/backend/package/yuxi/knowledge/graphs/milvus_graph_service.py index 3a5cd91d..3e23eb3e 100644 --- a/backend/package/yuxi/knowledge/graphs/milvus_graph_service.py +++ b/backend/package/yuxi/knowledge/graphs/milvus_graph_service.py @@ -70,11 +70,13 @@ class MilvusGraphService: kb = await self._get_milvus_kb(db_id) params = dict(kb.additional_params or {}) config = params.get(GRAPH_CONFIG_KEY) or {} - total_chunks, pending_chunks, indexed_chunks = await asyncio.gather( + total_chunks, pending_chunks, indexed_chunks, graph_counts = await asyncio.gather( self.chunk_repo.count_by_db_id(db_id), self.chunk_repo.count_graph_pending_by_db_id(db_id), self.chunk_repo.count_graph_indexed_by_db_id(db_id), + self.graph_repo.count_by_db_id(db_id), ) + entity_count, relationship_count = graph_counts build_task_status = None build_task_progress = 0 @@ -106,6 +108,8 @@ class MilvusGraphService: "total_chunks": total_chunks, "pending_chunks": pending_chunks, "indexed_chunks": indexed_chunks, + "entity_count": entity_count, + "relationship_count": relationship_count, "build_task_status": build_task_status, "build_task_progress": build_task_progress, } diff --git a/backend/package/yuxi/repositories/knowledge_graph_repository.py b/backend/package/yuxi/repositories/knowledge_graph_repository.py index b743355e..e1fadfd8 100644 --- a/backend/package/yuxi/repositories/knowledge_graph_repository.py +++ b/backend/package/yuxi/repositories/knowledge_graph_repository.py @@ -15,6 +15,16 @@ from yuxi.storage.postgres.models_knowledge import ( class KnowledgeGraphRepository: + async def count_by_db_id(self, db_id: str) -> tuple[int, int]: + async with pg_manager.get_async_session_context() as session: + entity_count = await session.scalar( + select(func.count()).select_from(KnowledgeGraphEntity).where(KnowledgeGraphEntity.db_id == db_id) + ) + triple_count = await session.scalar( + select(func.count()).select_from(KnowledgeGraphTriple).where(KnowledgeGraphTriple.db_id == db_id) + ) + return int(entity_count or 0), int(triple_count or 0) + async def upsert_chunk_graph( self, *, diff --git a/backend/test/unit/graphs/test_milvus_graph_build.py b/backend/test/unit/graphs/test_milvus_graph_build.py index 69509b13..05dd36d8 100644 --- a/backend/test/unit/graphs/test_milvus_graph_build.py +++ b/backend/test/unit/graphs/test_milvus_graph_build.py @@ -114,7 +114,8 @@ async def test_milvus_graph_service_configure_persists_updated_concurrency(): count_graph_pending_by_db_id=AsyncMock(return_value=0), count_graph_indexed_by_db_id=AsyncMock(return_value=0), ) - service = MilvusGraphService(kb_repo=Repo(), chunk_repo=chunk_repo) + graph_repo = SimpleNamespace(count_by_db_id=AsyncMock(return_value=(3, 2))) + service = MilvusGraphService(kb_repo=Repo(), chunk_repo=chunk_repo, graph_repo=graph_repo) await service.configure( "kb_test", @@ -125,6 +126,8 @@ async def test_milvus_graph_service_configure_persists_updated_concurrency(): status = await service.get_status("kb_test") assert status["config"]["extractor_options"]["concurrency_count"] == 9 + assert status["entity_count"] == 3 + assert status["relationship_count"] == 2 def test_milvus_graph_service_writes_chunk_entity_and_relation(): diff --git a/web/src/components/KnowledgeGraphSection.vue b/web/src/components/KnowledgeGraphSection.vue index e2dd18d5..d717181c 100644 --- a/web/src/components/KnowledgeGraphSection.vue +++ b/web/src/components/KnowledgeGraphSection.vue @@ -157,6 +157,14 @@ {{ graphBuildStatus?.indexed_chunks ?? '-' }} 已构建 +
+ {{ graphBuildStatus?.entity_count ?? '-' }} + 实体 +
+
+ {{ graphBuildStatus?.relationship_count ?? '-' }} + 关系 +
修改配置 - 重置 + 重置
@@ -412,7 +420,7 @@ const graphConfigForm = reactive({ extractor_type: 'llm', model_spec: '', schema: '', - concurrency_count: 5, + concurrency_count: 50, model_params_text: '', spacy_model: 'zh_core_web_sm', entity_labels_text: ''