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 ?? '-' }} 已构建 +