feat: 知识图谱状态增加实体/关系数量统计
- KnowledgeGraphRepository 新增 count_by_db_id 方法 - MilvusGraphService.get_status 返回 entity_count 和 relationship_count - 知识图谱管理面板展示实体与关系计数 - 修复重置按钮在构建中不可见的问题 - 调整默认并发数为 50 Co-authored-by: xerrors <xerrors@qq.com>
This commit is contained in:
parent
82af923cf1
commit
5add3a070d
@ -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,
|
||||
}
|
||||
|
||||
@ -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,
|
||||
*,
|
||||
|
||||
@ -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():
|
||||
|
||||
@ -157,6 +157,14 @@
|
||||
<span class="stat-value">{{ graphBuildStatus?.indexed_chunks ?? '-' }}</span>
|
||||
<span class="stat-label">已构建</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-value">{{ graphBuildStatus?.entity_count ?? '-' }}</span>
|
||||
<span class="stat-label">实体</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-value">{{ graphBuildStatus?.relationship_count ?? '-' }}</span>
|
||||
<span class="stat-label">关系</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="build-actions">
|
||||
<a-button
|
||||
@ -202,7 +210,7 @@
|
||||
>
|
||||
修改配置
|
||||
</a-button>
|
||||
<a-button size="small" type="text" danger @click="confirmResetGraph">重置</a-button>
|
||||
<a-button size="small" type="text" danger v-if="!isBuildActive" @click="confirmResetGraph">重置</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -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: ''
|
||||
|
||||
Loading…
Reference in New Issue
Block a user