Skip to content

Commit 24f3d03

Browse files
committed
fix(知识图谱): 修正节点和关系统计方法,排除知识库自动构建的图谱
更新 GraphView.vue 中的统计描述,明确说明不包含知识库创建的图谱 修改 graphbase.py 中的查询逻辑,只统计带有特定标签的节点和关系 更新 changelog 中相关问题的状态 #236
1 parent 9481117 commit 24f3d03

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

docs/changelog/update.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
### v2.0 PreRelease
55

66
💭 **Features Todo**
7-
- [x] 知识库使用 LightRAG(GraphRAG 轻量版)重构(🌟🌟🌟🌟🌟)
8-
- [x] 集成 MinerU 处理 PDF 文件。(🌟🌟🌟)
9-
- [x] 优化现有向量模型的逻辑,全局配置的向量模型作为新建知识库的默认模型,但是查询的时候,使用对应数据库的向量模型查询(单例模式)(🌟🌟🌟)
10-
- [x] 多类型知识库支持(🌟🌟🌟🌟🌟)
7+
- [x] 知识库使用 LightRAG(GraphRAG 轻量版)重构
8+
- [x] 集成 MinerU 处理 PDF 文件
9+
- [x] 优化现有向量模型的逻辑,全局配置的向量模型作为新建知识库的默认模型,但是查询的时候,使用对应数据库的向量模型查询(单例模式)
10+
- [x] 多类型知识库支持
1111
- [x] 设计问答知识库,支持针对问答对的调优
1212
- [x] 添加了批量上传文件的脚本,并优化文件信息
1313

@@ -18,7 +18,7 @@
1818
- [x] 与最新的 LightRAG 版本兼容性存在问题 #233
1919
- [x] 切换知识库之后,检索结果没有刷新
2020
- [x] 文件上传模块 UI的边距、配色有问题
21-
- [ ] 知识图谱页面的节点数量统计方法 #236
21+
- [x] 知识图谱页面的节点数量统计方法 #236
2222
- [ ] 当没有手动添加节点的时候,尝试检索,会出现为创建索引的情况 #236
2323

2424
# 💯 More:

src/knowledge/graphbase.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def _index_exists(tx, index_name):
343343
def query_by_vector(tx, text, threshold):
344344
# 首先检查索引是否存在
345345
if not _index_exists(tx, "entityEmbeddings"):
346-
raise Exception("向量索引不存在,请先创建索引")
346+
raise Exception("向量索引不存在,请先创建索引,或当前图谱中未上传任何三元组(知识库中自动构建的,不会在此处展示和检索)。")
347347

348348
embedding = self.get_embedding(text)
349349
result = tx.run("""
@@ -437,9 +437,11 @@ def get_graph_info(self, graph_name="neo4j"):
437437
assert self.driver is not None, "Database is not connected"
438438
self.use_database(graph_name)
439439
def query(tx):
440-
entity_count = tx.run("MATCH (n) RETURN count(n) AS count").single()["count"]
441-
relationship_count = tx.run("MATCH ()-[r]->() RETURN count(r) AS count").single()["count"]
442-
triples_count = tx.run("MATCH (n)-[r]->(m) RETURN count(n) AS count").single()["count"]
440+
# 只统计包含Entity标签的节点
441+
entity_count = tx.run("MATCH (n:Entity) RETURN count(n) AS count").single()["count"]
442+
# 只统计包含RELATION标签的关系
443+
relationship_count = tx.run("MATCH ()-[r:RELATION]->() RETURN count(r) AS count").single()["count"]
444+
triples_count = tx.run("MATCH (n:Entity)-[r:RELATION]->(m:Entity) RETURN count(n) AS count").single()["count"]
443445

444446
# 获取所有标签
445447
labels = tx.run("CALL db.labels() YIELD label RETURN collect(label) AS labels").single()["labels"]

web/src/views/GraphView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ const graphDescription = computed(() => {
351351
const modelName = graphInfo.value?.embed_model_name || '未上传文件';
352352
const unindexed = unindexedCount.value > 0 ? `${unindexedCount.value}个节点未索引` : '';
353353
354-
return `${dbName} - 共 ${entityCount} 实体,${relationCount} 个关系。向量模型:${modelName}${unindexed}`;
354+
return `${dbName} - 共 ${entityCount} 实体,${relationCount} 个关系(不含知识库创建的图谱)。向量模型:${modelName}${unindexed}`;
355355
});
356356
357357
// 为未索引节点添加索引

0 commit comments

Comments
 (0)