feat: 重构图谱抽取 — 支持建筑规范文档的 8 种实体类型
GraphRAG CI/CD / build-and-deploy (push) Successful in 6m15s

- 实体类型改为:构件/设备/设施/指标/场所/材料/措施/条款
- 中文 prompt + 建筑规范领域 Few-shot 示例
- 前端图谱颜色、筛选项同步更新
- QA agent 系统提示词适配建筑规范领域
This commit is contained in:
2026-06-18 16:30:58 +08:00
parent 4f203e3b56
commit a46ceb94de
6 changed files with 77 additions and 39 deletions
+15 -16
View File
@@ -83,17 +83,14 @@ def make_tools(G: nx.Graph) -> list:
def get_entities_by_type(entity_type: str) -> str:
"""List all entities of a specific type.
Args:
entity_type: TECHNOLOGY, CONCEPT, PERSON, ORGANIZATION, or LOCATION.
entity_type: 构件, 设备, 设施, 指标, 场所, 材料, 措施, 条款, etc.
"""
t_upper = entity_type.strip().upper()
valid = {"TECHNOLOGY", "CONCEPT", "PERSON", "ORGANIZATION", "LOCATION"}
if t_upper not in valid:
present = sorted({d.get("type","") for _, d in G.nodes(data=True)})
return f"Unknown type '{entity_type}'. Present: {present}"
matches = [d for _, d in G.nodes(data=True) if d.get("type","") == t_upper]
t = entity_type.strip()
matches = [d for _, d in G.nodes(data=True) if d.get("type","") == t]
if not matches:
return f"No {t_upper} entities found."
lines = [f"Found {len(matches)} {t_upper} entities:"]
present = sorted({d.get("type","") for _, d in G.nodes(data=True)})
return f"No '{entity_type}' entities found. Present types: {present}"
lines = [f"Found {len(matches)} {t} entities:"]
for m in matches[:30]:
lines.append(f" \"{m['name']}\" (page={m.get('page',0)}, id={m['id']})")
if len(matches) > 30:
@@ -148,15 +145,17 @@ def run_qa(
)
system_prompt = (
"You are a helpful assistant with access to a knowledge graph (KG) built from the user's documents.\n"
"You are a helpful assistant with access to a knowledge graph (KG) built from building code documents.\n"
"The KG contains entities extracted from building fire protection codes (建筑防火规范).\n"
"\n"
"Entity types include: 构件 (building components), 设备 (fire equipment), 设施 (facilities),\n"
"指标 (technical parameters), 场所 (building types/spaces), 材料 (materials),\n"
"措施 (fire measures), 条款 (regulation clauses).\n"
"\n"
"Guidelines:\n"
"- If the question is clearly unrelated to the KG (greetings, math, general knowledge, etc.), "
"answer directly WITHOUT using any tools.\n"
"- If the question might be answered by the KG (topics related to entities in the documents), "
"use the tools to search and explore before answering.\n"
"- When you DO use the KG, cite the entity names and types you found.\n"
"- If the KG has no relevant information, say so honestly and answer from general knowledge if possible.\n"
"- Use tools to search and explore the KG before answering.\n"
"- Cite the entity names and types you found.\n"
"- If the KG has no relevant information, say so honestly.\n"
"\n"
"Available tools: search entities by name, get neighbors, list entities by type, get graph overview."
)