Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
黄南光
/
wiki_knowledge
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit d606f761
authored
Jun 25, 2026
by
黄南光
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改摄入
1 parent
4a54c312
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
386 additions
and
110 deletions
frontend/src/app/rag/page.tsx
skills/llm-ingest/SKILL.md
skills/llm-ingest/references/golden-examples.md
skills/llm-ingest/references/schema-summary.md
skills/llm-lint/references/岗位Agent知识库-schema.md
src/api/routes/ingest.py
src/api/routes/lint.py
src/rag/service.py
src/tools/wiki_tools.py
frontend/src/app/rag/page.tsx
View file @
d606f76
...
@@ -11,7 +11,7 @@ import {
...
@@ -11,7 +11,7 @@ import {
} from "lucide-react";
} from "lucide-react";
import { cn } from "@/lib/utils";
import { cn } from "@/lib/utils";
import type { RagChunk, RagFile, RagMessage, RagReasoningStep } from "@/lib/rag-types";
import type { RagChunk, RagFile, RagMessage, RagReasoningStep } from "@/lib/rag-types";
import { clearRagHistory, deleteRagAction, fetchRagChunk, fetchRagChunks, fetchRagFiles, fetchRagStats,
importReferenceFiles, postRagAction, streamRagQuery, uploadRagFiles
} from "@/lib/rag-api";
import { clearRagHistory, deleteRagAction, fetchRagChunk, fetchRagChunks, fetchRagFiles, fetchRagStats,
postRagAction, streamRagQuery
} from "@/lib/rag-api";
const statusColor: Record<string, string> = {
const statusColor: Record<string, string> = {
Pending: "bg-amber-50 text-amber-700 border-amber-200",
Pending: "bg-amber-50 text-amber-700 border-amber-200",
...
@@ -32,6 +32,29 @@ const getFileIcon = (format: string) => {
...
@@ -32,6 +32,29 @@ const getFileIcon = (format: string) => {
return <FileText className="w-4 h-4 text-slate-500" />;
return <FileText className="w-4 h-4 text-slate-500" />;
};
};
const metadataLabels: Record<string, string> = {
chunk_id: "切片ID",
file_id: "文件ID",
parent_chunk_id: "父切片ID",
chunk_level: "层级",
chunk_index: "序号",
source_index: "引用序号",
source_name: "来源",
title_path: "标题",
page_number: "页码",
slide_number: "幻灯片",
sheet_name: "工作表",
row_start: "起始行",
row_end: "结束行",
status: "状态",
intent_type: "意图",
page_type: "页面类型",
brand: "品牌",
business_category: "业务分类",
parse_method: "解析方式",
parse_methods: "解析方式列表",
};
interface UploadQueueItem {
interface UploadQueueItem {
file: File;
file: File;
name: string;
name: string;
...
@@ -104,6 +127,10 @@ export default function RagWorkspace() {
...
@@ -104,6 +127,10 @@ export default function RagWorkspace() {
const chatEndRef = useRef<HTMLDivElement>(null);
const chatEndRef = useRef<HTMLDivElement>(null);
const chatAbortRef = useRef<AbortController | null>(null);
const chatAbortRef = useRef<AbortController | null>(null);
const actionRunning = useRef(false);
const actionRunning = useRef(false);
const selectedMetadataEntries = useMemo(
() => selectedChunk ? buildChunkMetadataEntries(selectedChunk) : [],
[selectedChunk]
);
const handleUploadSelect = (e: React.ChangeEvent<HTMLInputElement>) => {
const handleUploadSelect = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files.length > 0) {
if (e.target.files && e.target.files.length > 0) {
...
@@ -700,18 +727,45 @@ export default function RagWorkspace() {
...
@@ -700,18 +727,45 @@ export default function RagWorkspace() {
<aside className="border-t border-slate-100 bg-white p-4 lg:border-l lg:border-t-0 flex flex-col h-full overflow-hidden">
<aside className="border-t border-slate-100 bg-white p-4 lg:border-l lg:border-t-0 flex flex-col h-full overflow-hidden">
{selectedChunk ? (
{selectedChunk ? (
<>
<>
<div className="mb-3 flex items-center gap-2 font-semibold shrink-0">
<div className="mb-3 flex items-center justify-between gap-2 font-semibold shrink-0">
<div className="flex items-center gap-2">
<Eye className="h-4 w-4 text-blue-600" />
<Eye className="h-4 w-4 text-blue-600" />
切片元数据
切片元数据
</div>
</div>
<div className="space-y-2 text-xs text-slate-600 bg-slate-50 p-3 rounded-lg border border-slate-100 shrink-0">
<span className="rounded-full bg-blue-50 px-2 py-0.5 text-[11px] font-medium text-blue-700 border border-blue-100">
<div className="flex"><span className="w-12 text-slate-400">来源</span><span className="flex-1 font-medium truncate" title={selectedChunk.source_name}>{selectedChunk.source_name}</span></div>
{selectedMetadataEntries.length} 个字段
<div className="flex"><span className="w-12 text-slate-400">标题</span><span className="flex-1 line-clamp-2">{selectedChunk.title_path || "-"}</span></div>
</span>
<div className="flex"><span className="w-12 text-slate-400">位置</span><span className="flex-1">{chunkPosition(selectedChunk)}</span></div>
<div className="flex"><span className="w-12 text-slate-400">业务</span><span className="flex-1">{[selectedChunk.brand, selectedChunk.business_category].filter(Boolean).join(" / ") || "-"}</span></div>
<div className="flex"><span className="w-12 text-slate-400">解析</span><span className="flex-1">{String(selectedChunk.metadata_json?.parse_method || "-")}</span></div>
{!!selectedChunk.metadata_json?.row_start && <div className="flex"><span className="w-12 text-slate-400">行号</span><span className="flex-1">{String(selectedChunk.metadata_json.row_start)}-{String(selectedChunk.metadata_json.row_end || selectedChunk.metadata_json.row_start)}</span></div>}
</div>
</div>
<details open className="rounded-lg border border-slate-100 bg-slate-50 p-3 text-xs text-slate-600 shrink-0">
<summary className="cursor-pointer select-none font-semibold text-slate-700">
全部元数据字段
</summary>
<div className="mt-3 max-h-72 space-y-2 overflow-auto pr-1">
{selectedMetadataEntries.length > 0 ? (
selectedMetadataEntries.map(([key, value]) => (
<div key={key} className="rounded-md border border-slate-200 bg-white p-2">
<div className="mb-1 flex items-start justify-between gap-2">
<span className="font-medium text-slate-700">{metadataLabels[key] || key}</span>
<code className="shrink-0 rounded bg-slate-100 px-1.5 py-0.5 text-[10px] text-slate-500">{key}</code>
</div>
{isStructuredMetadataValue(value) ? (
<pre className="max-h-40 overflow-auto whitespace-pre-wrap break-all rounded bg-slate-50 p-2 text-[11px] leading-5 text-slate-600">
{formatMetadataValue(value)}
</pre>
) : (
<div className="max-h-24 overflow-auto whitespace-pre-wrap break-all leading-5 text-slate-600">
{formatMetadataValue(value)}
</div>
)}
</div>
))
) : (
<div className="rounded-md border border-dashed border-slate-200 bg-white p-3 text-center text-slate-400">
暂无元数据
</div>
)}
</div>
</details>
<div className="mt-4 flex-1 overflow-auto">
<div className="mt-4 flex-1 overflow-auto">
<div className="text-xs font-semibold text-slate-400 mb-2">完整内容</div>
<div className="text-xs font-semibold text-slate-400 mb-2">完整内容</div>
<pre className="whitespace-pre-wrap rounded-lg border border-slate-200 bg-white p-3 text-sm leading-7 text-slate-800 font-sans shadow-sm">{selectedChunk.content}</pre>
<pre className="whitespace-pre-wrap rounded-lg border border-slate-200 bg-white p-3 text-sm leading-7 text-slate-800 font-sans shadow-sm">{selectedChunk.content}</pre>
...
@@ -1173,3 +1227,56 @@ function chunkPosition(chunk: RagChunk) {
...
@@ -1173,3 +1227,56 @@ function chunkPosition(chunk: RagChunk) {
return "-";
return "-";
}
}
function buildChunkMetadataEntries(chunk: RagChunk): [string, unknown][] {
const metadata =
chunk.metadata_json && typeof chunk.metadata_json === "object" && !Array.isArray(chunk.metadata_json)
? chunk.metadata_json
: {};
const merged: Record<string, unknown> = {
chunk_id: chunk.chunk_id,
file_id: chunk.file_id,
parent_chunk_id: chunk.parent_chunk_id,
chunk_level: chunk.chunk_level,
chunk_index: chunk.chunk_index,
source_index: chunk.source_index,
source_name: chunk.source_name,
title_path: chunk.title_path,
page_number: chunk.page_number,
slide_number: chunk.slide_number,
sheet_name: chunk.sheet_name,
row_start: chunk.row_start,
row_end: chunk.row_end,
status: chunk.status,
intent_type: chunk.intent_type,
page_type: chunk.page_type,
brand: chunk.brand,
business_category: chunk.business_category,
...metadata,
};
return Object.entries(merged)
.filter(([, value]) => value !== undefined && value !== "")
.sort(([left], [right]) => {
const leftKnown = metadataLabels[left] ? 0 : 1;
const rightKnown = metadataLabels[right] ? 0 : 1;
if (leftKnown !== rightKnown) return leftKnown - rightKnown;
return left.localeCompare(right);
});
}
function isStructuredMetadataValue(value: unknown) {
return Array.isArray(value) || (typeof value === "object" && value !== null);
}
function formatMetadataValue(value: unknown) {
if (value === null) return "-";
if (value === undefined) return "-";
if (typeof value === "boolean") return value ? "true" : "false";
if (typeof value === "string") return value || "-";
if (typeof value === "number") return Number.isFinite(value) ? String(value) : "-";
try {
return JSON.stringify(value, null, 2);
} catch {
return String(value);
}
}
skills/llm-ingest/SKILL.md
View file @
d606f76
...
@@ -4,7 +4,7 @@ description: |
...
@@ -4,7 +4,7 @@ description: |
触发场景:用户说"摄入"/"处理来源"/"添加新资料"/"把这个文档加到知识库"
触发场景:用户说"摄入"/"处理来源"/"添加新资料"/"把这个文档加到知识库"
适配岗位 Agent 业务知识库(汽车后市场 × 50+ 品牌),不适用于个人技术知识库。
适配岗位 Agent 业务知识库(汽车后市场 × 50+ 品牌),不适用于个人技术知识库。
一次完整摄入 = 1 个 sources 摘要 + 0..N 个下游页面(按 10 种 type 路由产出)。
一次完整摄入 = 1 个 sources 摘要 + 0..N 个下游页面(按 10 种 type 路由产出)。
关键约束:10 种页面类型、强 schema 校验、
10 维标签体系
、品牌严格枚举、强制打标、延保话术合规校验。
关键约束:10 种页面类型、强 schema 校验、
5 维结构化过滤字段(series/brand/business_category/sub_business/role)+ 自由 tags、slug 全局唯一与规范命名
、品牌严格枚举、强制打标、延保话术合规校验。
不做:矛盾扫描(Q7 决策,移交 llm-lint)。
不做:矛盾扫描(Q7 决策,移交 llm-lint)。
---
---
...
@@ -49,28 +49,45 @@ description: |
...
@@ -49,28 +49,45 @@ description: |
完成分析后,你(Planner角色)
**必须直接输出 JSON 结构**
,供下游并发处理,例:
完成分析后,你(Planner角色)
**必须直接输出 JSON 结构**
,供下游并发处理,例:
```
json
```
json
{
{
"global_tags"
:
[
"鸿蒙智行"
,
"鸿蒙智行"
,
"权益类"
,
"延保"
,
"驻店销售"
],
"global_dims"
:
{
"series"
:
"鸿蒙智行"
,
"brand"
:
[
"问界"
,
"智界"
,
"享界"
,
"尊界"
,
"尚界"
],
"business_category"
:
"权益类"
,
"sub_business"
:
"售后延保"
,
"role"
:
[
"驻店销售"
]
},
"pages"
:
[
"pages"
:
[
{
{
"type"
:
"sources"
,
"type"
:
"sources"
,
"slug"
:
"产品手册"
,
"slug"
:
"
鸿蒙智行官方延保
产品手册"
,
"file_path"
:
"ware/wiki/sources/鸿蒙智行/产品手册.md"
,
"file_path"
:
"ware/wiki/sources/鸿蒙智行/
鸿蒙智行官方延保
产品手册.md"
,
"title"
:
"产品手册"
,
"title"
:
"
鸿蒙智行官方延保
产品手册"
,
"related_links"
:
[
"[[
ware/wiki/products/整车延保.md
]]"
],
"related_links"
:
[
"[[
鸿蒙智行官方延保
]]"
],
"source_content_range"
:
"全局摘要"
"source_content_range"
:
"全局摘要"
},
},
{
{
"type"
:
"products"
,
"type"
:
"products"
,
"slug"
:
"
整车
延保"
,
"slug"
:
"
鸿蒙智行官方
延保"
,
"file_path"
:
"ware/wiki/products/
整车
延保.md"
,
"file_path"
:
"ware/wiki/products/
鸿蒙智行官方
延保.md"
,
"title"
:
"
整车
延保"
,
"title"
:
"
鸿蒙智行官方
延保"
,
"related_links"
:
[
"[[
ware/wiki/sources/鸿蒙智行/产品手册.md
]]"
],
"related_links"
:
[
"[[
鸿蒙智行官方延保产品手册
]]"
],
"source_content_range"
:
"从第1章到第2章的保修范围"
"source_content_range"
:
"从第1章到第2章的保修范围"
}
}
]
]
}
}
```
```
**关键约束**
:每个页面的
`source_content_range`
必须互斥,不允许分配重叠的原文段落,以彻底杜绝并发生成的页面内容重叠!
**关键约束**
:
-
`global_dims`
是 5 个结构化过滤维度(不再是扁平 5 元数组):
`series`
(单值)、
`brand`
(列表)、
`business_category`
(单值)、
`sub_business`
(单值)、
`role`
(列表)。不确定填「未知
[
待确认
]
」,基线外品牌附「
[
待审批
]
」。
-
`source_content_range`
**按主题归集,不按物理位置/页码切分**
:同一主题/产品的内容(即使跨页、分散、或分成常规价表 + 限时礼惠/赠送/活动等多个子表)必须整体归入同一页;务必覆盖原文每一处,
**不要遗漏页边/跨页/表格末尾的零散行**
。各页主题尽量不重叠,但
**完整性优先**
——宁可完整归入最相关页,也不要让内容落空。
**2.3 规范命名规则(杜绝同义碎片化,极重要)**
slug 必须按「
**作用域实体 + 产品线/主题**
」命名,并保证
**全局唯一**
:
-
**系列级产品**
(一个产品跨多个同系品牌,如鸿蒙智行官方延保覆盖问界/智界/享界/尊界/尚界)→
**按品牌系列建一页**
,slug=
`{品牌系列}{产品线}`
(如
`鸿蒙智行官方延保`
),各车型价格/参数在
**页内分节**
,
`brand`
字段列全部适用品牌。
-
**单品牌产品**
→
**按品牌建页**
,slug=
`{品牌}{产品线}`
(如
`岚图整车延保`
)。
-
实体/政策/流程/话术同理带作用域前缀,
**严禁裸名**
(不要
`整车延保`
,要
`岚图整车延保`
或
`鸿蒙智行官方延保`
)。
-
**复用优先**
:系统会把现有页面注册表注入你的上下文;若已存在描述同一真实产品/实体的页面,
**直接复用其 slug**
(系统会自动把本次内容合并入既有页面)。
-
**slug 全局唯一**
:同一 slug 全库只对应一个页面;同一 slug 再次出现(哪怕来自不同来源文件)会
**合并**
进既有页面,仅当与
**不同 type**
的页面撞名才会被打回。
-
**目录结构(扁平)**
:
`file_path`
一律——
**只有 sources 用 `ware/wiki/sources/{品牌系列}/{slug}.md`,其余所有 type 一律 `ware/wiki/{type}/{slug}.md`,不加任何品牌/系列子目录**
(系统会强制按此归一化路径)。
## Step 3:页面规范写作 (Phase 2: Concurrent Writing)
## Step 3:页面规范写作 (Phase 2: Concurrent Writing)
...
@@ -84,18 +101,17 @@ description: |
...
@@ -84,18 +101,17 @@ description: |
**3.1 YAML frontmatter 结构(必须严格遵循)**
**3.1 YAML frontmatter 结构(必须严格遵循)**
每个 wiki 页面必须以下列 YAML frontmatter 开头。**缺少任何一个共有字段会被 Python 网关直接打回重试**。
每个 wiki 页面必须以下列 YAML frontmatter 开头。**缺少任何一个共有字段会被 Python 网关直接打回重试**。
共有字段模板(
8
个,全部必填):
共有字段模板(
12
个,全部必填):
```
yaml
```
yaml
---
---
schema_version
:
v1.3
schema_version
:
v1.3
type
:
<entities|products|concepts|procedures|scripts|policies|comparisons|troubleshooting|sources|synthesis>
type
:
<entities|products|concepts|procedures|scripts|policies|comparisons|troubleshooting|sources|synthesis>
title
:
<页面标题,中文>
title
:
<页面标题,中文>
tags
:
series
:
<品牌系列,单值,无系列填 通用品牌>
-
<品牌名>
brand
:
[
<品牌1>
,
<品牌2>
]
# 列表;系列级产品列全部适用品牌
-
<品牌系列>
business_category
:
<业务大类,单值:轻改类 | 权益类 | 二手车类>
-
<业务大类>
sub_business
:
<子业务,单值>
-
<子业务>
role
:
[
<岗位>
]
# 列表;面向所有岗位用 [通用]
-
<岗位>
related
:
related
:
-
<相关页面slug1>
-
<相关页面slug1>
-
<相关页面slug2>
-
<相关页面slug2>
...
@@ -103,30 +119,35 @@ sources:
...
@@ -103,30 +119,35 @@ sources:
-
<raw文件相对路径>
-
<raw文件相对路径>
created
:
YYYY-MM-DD
created
:
YYYY-MM-DD
updated
:
YYYY-MM-DD
updated
:
YYYY-MM-DD
tags
:
[]
# 可选,自由检索标注,见 3.2
---
---
```
```
⚠️ 各 type 的额外必填字段请严格参照注入到你上下文中的 `schema-summary.md` 和 `golden-examples.md`。
> `series/brand/business_category/sub_business/role` 必须使用规划阶段「全局锁定」的 5 维值。
⚠️ 各 type 的额外必填字段(如 entity 的 `brand`/`entity_type`、product 的额外字段、script 的 `scenario`/`script_type`/`skill_tag` 等)请严格参照注入到你上下文中的 `schema-summary.md` 和 `golden-examples.md`。
**3.2 tags 标注指引(可选、自由标注)**
`tags[]` **不再承载 5 维过滤维度**(那些已是上面的结构化字段)。tags 仅用于**横切检索关键词**,从下列建议词表中挑选合适的,没有就写 `tags: []`:
- 功能场景:`异议处理`、`产品参数`、`质保政策`、`合规红线`、`系统排障`、`促销活动`、`客户分类`、`销售技巧`
- 辅助标签:`FAQ`、`错误码`、`案例研究`、`对比分析`
- 允许在词表基础上自由补充贴切的检索词;**必须去重**;**严禁**把品牌/系列/业务大类/子业务/岗位塞进 tags。
## Step 4:建立交叉引用
## Step 4:建立交叉引用
- **必须带全路径** wikilink:`[[ware/wiki/路径/xxx.md]]` ✅
- **必须用 slug 简写** wikilink:`[[页面slug]]` ✅(如 `[[岚图整车延保]]`)
- **禁止使用简写** wikilink:`[[页面slug]]` ❌
- **禁止全路径/带后缀** wikilink:`[[ware/wiki/路径/xxx.md]]` ❌
- slug 全局唯一,故简写无歧义;`related` 字段与正文链接均使用 slug。
- **引用范围收紧**(避免过度引用):
- **引用范围收紧**(避免过度引用):
- 只能引用在你的 `source_content_range` 内明确提到过的事物。
- 只能引用在你的 `source_content_range` 内明确提到过的事物。
- 所创建的所有双向链接 `[[页面
名称
]]` 必须限制在分配给你的 `related_links` 列表内。
- 所创建的所有双向链接 `[[页面
slug
]]` 必须限制在分配给你的 `related_links` 列表内。
## Step 5:系统自动保存与同步 (Phase 3)
## Step 5:系统自动保存与同步 (Phase 3)
**无需你执行!**
**无需你执行!**
- Python 脚本会自动将你合格的输出保存到目标路径。
- Python 脚本会自动将你合格的输出保存到目标路径。
- 如果
文件已存在,Python 脚本会自动执行内容追加 (Append)
。
- 如果
目标页已存在:同一来源的 SOURCE 块会被**替换**、不同来源的内容会**合并**(按 `field_sources` 统一溯源)
。
- Python 脚本会
自动更新 `ware/wiki/index.md` 和
`ware/wiki/log.md`。
- Python 脚本会
按 type 分组**确定性全量重建** `ware/wiki/index.md`,并追加
`ware/wiki/log.md`。
**index.md 写入格式**(v2.0,符合 lint 1.5 要求):
**index.md 由系统全量重建**(你无需关心格式):按页面 frontmatter 的 `type` 分组、组内按 `series/brand` 排序,每行 `- [[slug]] — 标题`。
```
-
[
[page-slug
]
] — 页面标题
```
> 注意:使用 em dash(`—`)而非双横线(`--`),使用 slug(文件名不含路径和 .md)而非路径格式。
**log.md 写入格式**(v2.0,包含 wikilink 数量,供 lint 增量模式使用):
**log.md 写入格式**(v2.0,包含 wikilink 数量,供 lint 增量模式使用):
```
```
...
@@ -139,7 +160,7 @@ updated: YYYY-MM-DD
...
@@ -139,7 +160,7 @@ updated: YYYY-MM-DD
## 关键约束(再次强调)
## 关键约束(再次强调)
1.
**强 schema 校验移交 Python**
:缺失字段、带 think 标签会被自动拦截并要求你重写,请一次写对。
1.
**强 schema 校验移交 Python**
:缺失字段、带 think 标签会被自动拦截并要求你重写,请一次写对。
2.
**
专属领地(防重叠)**
:Writer 只能写自己被分配到的
`source_content_range`
,即使原文有其他丰富内容,只要不属于你,
**绝不触碰**
。
2.
**
按主题完整归集(防跨页丢失)**
:Writer 以
**主题归属**
判断内容归属,
**不以原文物理位置/页码判断**
。凡属于本页主题的内容,无论跨页、分散、还是分成常规价表 + 限时礼惠/赠送/活动等多个子表,
**全部纳入**
(页边/跨页/表末零散行最易遗漏,务必收齐);不属于本主题的不写,避免重复展开同一事实。完整性优先于不重叠
。
3.
**单一信息源原则**
(Wiki 核心理念):
3.
**单一信息源原则**
(Wiki 核心理念):
-
每条业务事实
**只在一个页面中完整展开**
。
-
每条业务事实
**只在一个页面中完整展开**
。
-
具体规则:除外责任/享权前提在 policies 页展开,理赔流程在 procedures 页展开,产品赔付表格、价格明细和 SKU 清单在 products 页完整展开。
**注意:Wiki 数据库对价格、数字和型号极度敏感,绝对不能精简或省略价格表、金额、年限、里程等核心数值,必须在页面中提供全量数据**
。
-
具体规则:除外责任/享权前提在 policies 页展开,理赔流程在 procedures 页展开,产品赔付表格、价格明细和 SKU 清单在 products 页完整展开。
**注意:Wiki 数据库对价格、数字和型号极度敏感,绝对不能精简或省略价格表、金额、年限、里程等核心数值,必须在页面中提供全量数据**
。
...
...
skills/llm-ingest/references/golden-examples.md
View file @
d606f76
...
@@ -9,31 +9,32 @@
...
@@ -9,31 +9,32 @@
**输入片段**
:
**输入片段**
:
> "鸿蒙智行辅助驾驶无忧服务产品包含整车延保服务。在原厂质保期满后,提供额外1年或3万公里的保修服务。除外责任包括:1. 易损件正常磨损;2. 人为损坏;3. 未在授权中心保养导致的故障... (共17条)。"
> "鸿蒙智行辅助驾驶无忧服务产品包含整车延保服务。在原厂质保期满后,提供额外1年或3万公里的保修服务。除外责任包括:1. 易损件正常磨损;2. 人为损坏;3. 未在授权中心保养导致的故障... (共17条)。"
**输出页面**
(
`ware/wiki/products/
整车
延保.md`
):
**输出页面**
(
`ware/wiki/products/
鸿蒙智行辅助驾驶无忧
延保.md`
):
```
markdown
```
markdown
---
---
schema_version: v1.3
schema_version: v1.3
type: products
type: products
title: 整车延保
title: 鸿蒙智行辅助驾驶无忧延保
tags:
series: 鸿蒙智行
brand:
-
问界
-
问界
-
鸿蒙智行
business_category: 权益类
-
权益类
sub_business: 售前延保
-
售前延保
role:
-
驻店销售
-
驻店销售
related:
related:
-
辅助驾驶无忧服务产品手册
-
鸿蒙智行
辅助驾驶无忧服务产品手册
-
延保免责条款
-
鸿蒙智行
延保免责条款
sources:
sources:
-
raw/鸿蒙智行辅助驾驶无忧服务产品手册260121.pdf
-
ware/
raw/鸿蒙智行辅助驾驶无忧服务产品手册260121.pdf
created: 2026-06-09
created: 2026-06-09
updated: 2026-06-09
updated: 2026-06-09
business_category: 权益类
tags:
sub_business: 售前延保
- 产品参数
---
---
#
整车
延保
#
鸿蒙智行辅助驾驶无忧
延保
整车延保是鸿蒙智行辅助驾驶无忧服务产品之一,旨在原厂质保期满后,为车主提供延长保修服务。
整车延保是鸿蒙智行辅助驾驶无忧服务产品之一,旨在原厂质保期满后,为车主提供延长保修服务。
...
@@ -46,9 +47,9 @@ sub_business: 售前延保
...
@@ -46,9 +47,9 @@ sub_business: 售前延保
## 除外责任
## 除外责任
> 本产品存在 17 条除外责任(如易损件正常磨损、人为损坏等)。
> 本产品存在 17 条除外责任(如易损件正常磨损、人为损坏等)。
> **详细条款请参见:** [[
ware/wiki/policies/延保免责条款.md
]]
> **详细条款请参见:** [[
鸿蒙智行延保免责条款
]]
```
```
*(注意:
严格遵循单一信息源原则,产品页不铺陈 17 条除外责任,而是使用 wikilink 引用 policy 页面。但在涉及价格明细、年限里程、保费金额等核心数值与表格时,必须 100% 全量保留,绝不可省略
。)*
*(注意:
① 单一信息源——产品页不铺陈 17 条除外责任,而用 slug wikilink 引用 policy 页;价格/年限/里程等核心数值与表格必须 100% 全量保留。② slug 用「作用域+产品线」命名,避免裸名「整车延保」;wikilink 一律 slug 简写
。)*
---
---
...
@@ -56,30 +57,32 @@ sub_business: 售前延保
...
@@ -56,30 +57,32 @@ sub_business: 售前延保
**输入片段**
:整个《鸿蒙智行辅助驾驶无忧服务产品手册260121.pdf》
**输入片段**
:整个《鸿蒙智行辅助驾驶无忧服务产品手册260121.pdf》
**输出页面**
(
`ware/wiki/sources/鸿蒙智行/辅助驾驶无忧服务产品手册.md`
):
**输出页面**
(
`ware/wiki/sources/鸿蒙智行/
鸿蒙智行
辅助驾驶无忧服务产品手册.md`
):
```
markdown
```
markdown
---
---
schema_version: v1.3
schema_version: v1.3
type: sources
type: sources
title: 辅助驾驶无忧服务产品手册
title: 鸿蒙智行辅助驾驶无忧服务产品手册
tags:
series: 鸿蒙智行
brand:
-
问界
-
问界
-
鸿蒙智行
business_category: 权益类
-
权益类
sub_business: 售前延保
-
售前延保
role:
-
通用
-
通用
related:
related:
-
整车
延保
-
鸿蒙智行辅助驾驶无忧
延保
-
延保免责条款
-
鸿蒙智行
延保免责条款
-
辅助驾驶功能定义与分类
-
辅助驾驶功能定义与分类
sources:
sources:
-
raw/鸿蒙智行辅助驾驶无忧服务产品手册260121.pdf
-
ware/
raw/鸿蒙智行辅助驾驶无忧服务产品手册260121.pdf
created: 2026-06-09
created: 2026-06-09
updated: 2026-06-09
updated: 2026-06-09
tags: []
---
---
# 辅助驾驶无忧服务产品手册 — 来源摘要
#
鸿蒙智行
辅助驾驶无忧服务产品手册 — 来源摘要
## 来源基本信息
## 来源基本信息
-
来源标题:鸿蒙智行辅助驾驶无忧服务产品手册
-
来源标题:鸿蒙智行辅助驾驶无忧服务产品手册
...
@@ -93,18 +96,18 @@ updated: 2026-06-09
...
@@ -93,18 +96,18 @@ updated: 2026-06-09
## 下游页面导航
## 下游页面导航
| type | 页面 | 一句话描述 |
| type | 页面 | 一句话描述 |
|------|------|-----------|
|------|------|-----------|
| products |
[
[
ware/wiki/products/整车延保.md
]
] | 介绍延保服务的保障期限与范围 |
| products |
[
[
鸿蒙智行辅助驾驶无忧延保
]
] | 介绍延保服务的保障期限与范围 |
| policies |
[
[
ware/wiki/policies/延保免责条款.md
]
] | 罗列 17 条延保服务的除外责任与合规红线 |
| policies |
[
[
鸿蒙智行延保免责条款
]
] | 罗列 17 条延保服务的除外责任与合规红线 |
| concepts |
[
[
ware/wiki/concepts/辅助驾驶功能定义与分类.md
]
] | 梳理辅助驾驶的核心功能定义 |
| concepts |
[
[
辅助驾驶功能定义与分类
]
] | 梳理辅助驾驶的核心功能定义 |
## 关键数据速查
## 关键数据速查
| 数据项 | 数值 |
| 数据项 | 数值 |
|--------|------|
|--------|------|
| 延保期限 | 1年/3万公里 |
| 延保期限 | 1年/3万公里 |
> 原始依据:`raw/鸿蒙智行辅助驾驶无忧服务产品手册260121.pdf`
> 原始依据:`
ware/
raw/鸿蒙智行辅助驾驶无忧服务产品手册260121.pdf`
```
```
*(注意:Sources 页仅做极简摘要和导航表,绝不将源文件逐字展开
。限制在 80 行以内
。)*
*(注意:Sources 页仅做极简摘要和导航表,绝不将源文件逐字展开
,限制在 80 行以内;导航链接一律 slug 简写
。)*
---
---
...
@@ -120,18 +123,21 @@ updated: 2026-06-09
...
@@ -120,18 +123,21 @@ updated: 2026-06-09
schema_version: v1.3
schema_version: v1.3
type: concepts
type: concepts
title: 辅助驾驶功能定义与分类
title: 辅助驾驶功能定义与分类
tags:
series: 鸿蒙智行
brand:
-
问界
-
问界
-
鸿蒙智行
business_category: 权益类
-
权益类
sub_business: 售前延保
-
售前延保
role:
-
驻店销售
-
驻店销售
related:
related:
-
辅助驾驶无忧服务产品手册
-
鸿蒙智行
辅助驾驶无忧服务产品手册
sources:
sources:
-
raw/鸿蒙智行辅助驾驶无忧服务产品手册260121.pdf
-
ware/
raw/鸿蒙智行辅助驾驶无忧服务产品手册260121.pdf
created: 2026-06-09
created: 2026-06-09
updated: 2026-06-09
updated: 2026-06-09
tags:
- 产品参数
---
---
# 辅助驾驶功能定义与分类
# 辅助驾驶功能定义与分类
...
...
skills/llm-ingest/references/schema-summary.md
View file @
d606f76
...
@@ -18,7 +18,9 @@
...
@@ -18,7 +18,9 @@
| source |
`wiki/sources/<品牌系列>/`
| — | 品牌系列 + 来源类型 + 业务大类 |
| source |
`wiki/sources/<品牌系列>/`
| — | 品牌系列 + 来源类型 + 业务大类 |
| synthesis |
`wiki/synthesis/`
| — | 品牌 + 业务大类 + 案例研究 |
| synthesis |
`wiki/synthesis/`
| — | 品牌 + 业务大类 + 案例研究 |
> 8 个共有字段:`schema_version`, `type`, `title`, `tags`, `related`, `sources`, `created`, `updated`
> 12 个共有字段(全部必填):`schema_version`, `type`, `title`, `series`, `brand`, `business_category`, `sub_business`, `role`, `related`, `sources`, `created`, `updated`
> `tags` 为可选自由检索标注(非必填,可为 `[]`)。
> 上表「推荐 tags 前缀」列为历史遗留语义参考;过滤维度现已是上面 5 个结构化字段,**不再塞进 tags**。
## YAML 模板
## YAML 模板
...
@@ -28,11 +30,16 @@
...
@@ -28,11 +30,16 @@
schema_version
:
v1.3
schema_version
:
v1.3
type
:
<10 种之一>
type
:
<10 种之一>
title
:
"
页面标题"
title
:
"
页面标题"
tags
:
[
品牌
,
品牌系列
,
业务大类
,
子业务
,
岗位
,
...
]
series
:
鸿蒙智行
# 品牌系列,单值;无系列填 通用品牌
related
:
[
slug
,
...
]
brand
:
[
问界
,
智界
]
# 适用品牌,列表;系列级产品列全部
sources
:
[
raw/sources/.../file.pdf
]
business_category
:
权益类
# 业务大类,单值:轻改类 | 权益类 | 二手车类
sub_business
:
售后延保
# 子业务,单值
role
:
[
驻店销售
]
# 适用岗位,列表;面向所有岗位用 [通用]
related
:
[
slug
,
...
]
# slug 简写,禁止全路径/.md
sources
:
[
ware/raw/file.pdf
]
created
:
YYYY-MM-DD
created
:
YYYY-MM-DD
updated
:
YYYY-MM-DD
updated
:
YYYY-MM-DD
tags
:
[]
# 可选自由标注:异议处理/合规红线/FAQ/错误码/案例研究 等
---
---
```
```
...
@@ -72,12 +79,14 @@ error_code: "AMOUNT_EXCEED" # 可选
...
@@ -72,12 +79,14 @@ error_code: "AMOUNT_EXCEED" # 可选
## 常见错误清单
## 常见错误清单
-
❌
`type`
与所在目录不一致(product 放进
`wiki/concepts/`
)
-
❌
`type`
与所在目录不一致(product 放进
`wiki/concepts/`
)
-
❌ tags 缺品牌(鸿蒙智行品牌页必须含品牌名 +
`鸿蒙智行`
)
-
❌ 缺少 5 维结构化字段之一(
`series`
/
`brand`
/
`business_category`
/
`sub_business`
/
`role`
)
-
❌
`brand`
/
`role`
写成字符串而非列表;
`business_category`
非法值
-
❌ 把品牌/系列/业务/岗位塞进
`tags`
(应放结构化字段,tags 仅自由检索标注)
-
❌ script 优秀/违规话术缺
`source_recording`
-
❌ script 优秀/违规话术缺
`source_recording`
-
❌ policy 合规红线类缺
`violation_type`
-
❌ policy 合规红线类缺
`violation_type`
-
❌ wikilink 简写(应使用全路径
`[[ware/wiki/路径/xxx.md]]`
,严禁简写)
-
❌ wikilink 用全路径或带
`.md`
(应使用 slug 简写
`[[页面slug]]`
)
-
❌ 裸名 slug 或撞名(应「作用域+产品线」命名且全局唯一)
-
❌ source 摘要页缺
`related[]`
-
❌ source 摘要页缺
`related[]`
-
❌ tags 漏岗位维度(无
`驻店销售`
/
`通用`
,查询无法按权限过滤)
-
❌
`schema_version`
不是
`v1.3`
-
❌
`schema_version`
不是
`v1.3`
-
❌
`created`
/
`updated`
非
`YYYY-MM-DD`
-
❌
`created`
/
`updated`
非
`YYYY-MM-DD`
...
...
skills/llm-lint/references/岗位Agent知识库-schema.md
View file @
d606f76
...
@@ -35,16 +35,25 @@
...
@@ -35,16 +35,25 @@
```
yaml
```
yaml
---
---
schema_version
:
v1.3
# 生成时的 schema 版本,用于后续迁移
schema_version
:
v1.3
# 生成时的 schema 版本,用于后续迁移
type
:
entit
y | product | concept | procedure | script | policy | comparison | troubleshooting | source
| synthesis
type
:
entit
ies | products | concepts | procedures | scripts | policies | comparisons | troubleshooting | sources
| synthesis
title
:
"
页面标题"
title
:
"
页面标题"
tags
:
[]
# 见下方标签体系
series
:
鸿蒙智行
# 【过滤维度】品牌系列,单值;无系列填 通用品牌
related
:
[]
# 关联的其他页面 slug(不含 .md),如 ["问界M7", "整车延保"]
brand
:
[
问界
,
智界
]
# 【过滤维度】适用品牌,列表;系列级产品列全部
sources
:
[]
# 来源文档路径,如 ["raw/sources/sales/问界延保产品手册.pdf"]
business_category
:
权益类
# 【过滤维度】业务大类,单值:轻改类 | 权益类 | 二手车类
sub_business
:
售后延保
# 【过滤维度】子业务,单值
role
:
[
驻店销售
]
# 【过滤维度】适用岗位,列表;面向所有岗位用 [通用]
related
:
[]
# 关联页面 slug(slug 简写,不含路径/.md),如 ["问界M7", "整车延保"]
sources
:
[]
# 来源文档路径,如 ["ware/raw/问界延保产品手册.pdf"]
created
:
2026-05-28
created
:
2026-05-28
updated
:
2026-05-28
updated
:
2026-05-28
tags
:
[]
# 可选,自由检索标注(功能场景/FAQ/错误码等),不再承载过滤维度
---
---
```
```
> **过滤维度结构化(v1.3)**:品牌/系列/业务大类/子业务/岗位这 5 个权限过滤维度,已从扁平 `tags[]` 升级为上面 5 个**独立结构化字段**(`series`/`brand`/`business_category`/`sub_business`/`role`),全部必填。`tags[]` 仅保留为自由检索标注。
> **type 取值**与目录一致,使用复数形式(`products`/`sources`/`entities` …)。
> **字段级溯源**:多源合并的页面,每个受追踪字段的来源记录在 `field_sources` 中;摄出按来源回收,保证无残留。
当 schema 更新到新版本时,告知 Claude Code:
当 schema 更新到新版本时,告知 Claude Code:
"搜
`schema_version`
不是最新版本的页面,按新 schema.md 重新打标并进行迁移。"
"搜
`schema_version`
不是最新版本的页面,按新 schema.md 重新打标并进行迁移。"
...
@@ -93,27 +102,29 @@ effective_date: "2026-01-01" # 生效日期(可选)
...
@@ -93,27 +102,29 @@ effective_date: "2026-01-01" # 生效日期(可选)
## 标签体系
## 标签体系
### 标签维度
> **重要(v1.3)**:下表前 5 个维度(品牌/品牌系列/业务大类/子业务/岗位)现已是 frontmatter 的**独立结构化字段** `brand`/`series`/`business_category`/`sub_business`/`role`,**不再写入 `tags[]`**。下表的取值枚举与半受控规则继续适用于这些结构化字段。其余维度(异议场景、话术性质、话术技巧等)按 type 进各自的专属字段,纯横切检索词才进 `tags[]`。
| 维度 | 规则 | 示例值 |
### 维度取值规则
|------|------|--------|
|
**品牌**
| 半受控:已知品牌用枚举值,LLM 可新增但须在 log.md 标记
`⚠️ 新品牌待确认`
|
`问界`
、
`享界`
、
`智界`
、
`尊界`
、
`尚界`
、
`岚图`
、
`零跑`
、
`丰田`
、
`比亚迪`
等(完整列表见下方) |
| 维度 | 对应字段 | 规则 | 示例值 |
|
**品牌系列**
| 可选,标注品牌归属的系列/厂商 |
`鸿蒙智行`
(覆盖问界/享界/智界/尊界/尚界)、
`通用品牌`
(其他所有非鸿蒙品牌) |
|------|------|------|--------|
|
**业务大类**
| 必选其一 |
`轻改类`
、
`权益类`
、
`二手车类`
|
|
**品牌**
|
`brand`
(列表)| 半受控:已知品牌用枚举值,LLM 可新增但须在 log.md 标记
`⚠️ 新品牌待确认`
|
`问界`
、
`享界`
、
`智界`
、
`尊界`
、
`尚界`
、
`岚图`
、
`零跑`
、
`丰田`
、
`比亚迪`
等(完整列表见下方) |
|
**子业务**
| 轻改按产品标记;权益按场景标记;二手车按本质标记 | 见下方完整列表 |
|
**品牌系列**
|
`series`
(单值)| 标注品牌归属的系列/厂商 |
`鸿蒙智行`
(覆盖问界/享界/智界/尊界/尚界)、
`通用品牌`
(其他所有非鸿蒙品牌) |
|
**岗位/角色**
| 按目标用户标记(权限过滤的核心维度) |
`驻店销售`
、
`区域运营`
、
`区域督导`
、
`业务经理`
、
`线上运营`
、
`产品经理`
、
`总部管理`
|
|
**业务大类**
|
`business_category`
(单值)| 必选其一 |
`轻改类`
、
`权益类`
、
`二手车类`
|
|
**异议场景**
| 话术中客户的核心异议类型 |
`价格敏感`
、
`价值怀疑`
、
`赠品防御`
、
`积分变现`
、
`周期焦虑`
、
`质保够用`
、
`条款信任`
、
`拖延观望`
|
|
**子业务**
|
`sub_business`
(单值)| 轻改按产品标记;权益按场景标记;二手车按本质标记 | 见下方完整列表 |
|
**话术性质**
| 仅 script 类型使用,区分话术合规性 |
`优秀话术`
(轻改萃取)、
`合规话术`
(延保过审)、
`违规话术`
(延保红线) |
|
**岗位/角色**
|
`role`
(列表)| 按目标用户标记(权限过滤的核心维度) |
`驻店销售`
、
`区域运营`
、
`区域督导`
、
`业务经理`
、
`线上运营`
、
`产品经理`
、
`总部管理`
|
|
**话术技巧**
| 优秀/合规话术中运用的方法标签 |
`算账法`
、
`锚点法`
、
`风险放大`
、
`框架转换`
、
`利益同盟`
、
`坦诚接纳`
、
`以退为进`
、
`损失厌恶`
|
|
**异议场景**
| script 的
`objection_type`
| 话术中客户的核心异议类型 |
`价格敏感`
、
`价值怀疑`
、
`赠品防御`
、
`积分变现`
、
`周期焦虑`
、
`质保够用`
、
`条款信任`
、
`拖延观望`
|
|
**功能场景**
| 按内容标记,可多个 |
`异议处理`
、
`产品参数`
、
`质保政策`
、
`合规红线`
、
`系统排障`
、
`促销活动`
、
`客户分类`
、
`销售技巧`
|
|
**话术性质**
| script 的
`script_type`
| 仅 script 类型使用,区分话术合规性 |
`优秀话术`
(轻改萃取)、
`合规话术`
(延保过审)、
`违规话术`
(延保红线) |
|
**页面类型标签**
| 按内容标记,辅助检索 |
`对比分析`
、
`案例研究`
、
`FAQ`
、
`错误码`
|
|
**话术技巧**
| script 的
`skill_tag`
| 优秀/合规话术中运用的方法标签 |
`算账法`
、
`锚点法`
、
`风险放大`
、
`框架转换`
、
`利益同盟`
、
`坦诚接纳`
、
`以退为进`
、
`损失厌恶`
|
|
**功能场景**
|
`tags[]`
| 按内容标记,可多个 |
`异议处理`
、
`产品参数`
、
`质保政策`
、
`合规红线`
、
`系统排障`
、
`促销活动`
、
`客户分类`
、
`销售技巧`
|
|
**页面类型标签**
|
`tags[]`
| 按内容标记,辅助检索 |
`对比分析`
、
`案例研究`
、
`FAQ`
、
`错误码`
|
### 标签规则
### 标签规则
1.
`brand`
字段
(entity 专属)与 tags 中的品牌标签必须一致
1.
`brand`
字段
值必须与文档实际适用品牌一致(entity 页 brand 与正文主体一致)
2.
`business_category`
字段
(product 专属)与 tags 中的业务大类标签必须一致
2.
`business_category`
字段
必须取
`轻改类 | 权益类 | 二手车类`
之一
3.
岗位标签可按实际适用范围多选。若内容面向所有岗位,使用
`通用`
标签替代
3.
`role`
可按实际适用范围多选。若内容面向所有岗位,使用
`通用`
4.
品牌
标签半受控:LLM 遇到文档中的新品牌,可自动新增标签
,但同时须在
`ware/wiki/log.md`
中记录
`⚠️ 新品牌待确认:[品牌名]`
4.
品牌
半受控:LLM 遇到文档中的新品牌,可自动新增
,但同时须在
`ware/wiki/log.md`
中记录
`⚠️ 新品牌待确认:[品牌名]`
### 当前已知品牌列表(受控基线)
### 当前已知品牌列表(受控基线)
...
...
src/api/routes/ingest.py
View file @
d606f76
This diff is collapsed.
Click to expand it.
src/api/routes/lint.py
View file @
d606f76
This diff is collapsed.
Click to expand it.
src/rag/service.py
View file @
d606f76
...
@@ -34,11 +34,6 @@ _query_semaphore = asyncio.Semaphore(RAG_QUERY_CONCURRENCY)
...
@@ -34,11 +34,6 @@ _query_semaphore = asyncio.Semaphore(RAG_QUERY_CONCURRENCY)
_llm_semaphore
=
asyncio
.
Semaphore
(
RAG_LLM_CONCURRENCY
)
_llm_semaphore
=
asyncio
.
Semaphore
(
RAG_LLM_CONCURRENCY
)
_index_semaphore
=
asyncio
.
Semaphore
(
RAG_INDEX_CONCURRENCY
)
_index_semaphore
=
asyncio
.
Semaphore
(
RAG_INDEX_CONCURRENCY
)
DEFAULT_REFERENCE_FILES
=
[
os
.
path
.
join
(
BASE_DIR
,
"src"
,
"ref"
,
"参考资料"
,
"鸿蒙智行官方服务产品价格总览.pdf"
),
os
.
path
.
join
(
BASE_DIR
,
"src"
,
"ref"
,
"参考资料"
,
"鸿蒙智行辅助驾驶无忧服务产品手册260121.pdf"
),
]
def
_lock_for
(
file_id
:
str
)
->
asyncio
.
Lock
:
def
_lock_for
(
file_id
:
str
)
->
asyncio
.
Lock
:
if
file_id
not
in
_file_locks
:
if
file_id
not
in
_file_locks
:
...
...
src/tools/wiki_tools.py
View file @
d606f76
...
@@ -207,6 +207,26 @@ def read_local_file(file_path: str, start_line: int = 1, end_line: int = None) -
...
@@ -207,6 +207,26 @@ def read_local_file(file_path: str, start_line: int = 1, end_line: int = None) -
content
=
[
TextBlock
(
type
=
"text"
,
text
=
f
"❌ 读取错误: {str(e)}"
)]
content
=
[
TextBlock
(
type
=
"text"
,
text
=
f
"❌ 读取错误: {str(e)}"
)]
)
)
_BR_RE
=
re
.
compile
(
r"\s*<br\s*/?>\s*"
,
re
.
IGNORECASE
)
def
normalize_br_tags
(
text
:
str
)
->
str
:
"""规范化 <br>/<br/>/<br /> 标签(表格感知):
- 表格行(含 `|`):cell 内换行替换为单个空格,保持列结构不被破坏;
- 普通正文行:<br> 还原为真实换行。
返回 (是否有改动, 规范化后文本) 由调用方按需判断;此处只返回文本。
"""
if
"<br"
not
in
text
.
lower
():
return
text
out
=
[]
for
line
in
text
.
split
(
"
\n
"
):
if
"|"
in
line
:
out
.
append
(
_BR_RE
.
sub
(
" "
,
line
))
else
:
out
.
append
(
_BR_RE
.
sub
(
"
\n
"
,
line
))
return
"
\n
"
.
join
(
out
)
def
batch_write_wiki_files
(
files
:
list
[
dict
],
source_ref
:
str
=
None
)
->
ToolResponse
:
def
batch_write_wiki_files
(
files
:
list
[
dict
],
source_ref
:
str
=
None
)
->
ToolResponse
:
"""
"""
批量将多个内容写入知识库目录。
批量将多个内容写入知识库目录。
...
@@ -467,6 +487,113 @@ def add_wiki_warning(file_path: str, warning_text: str) -> ToolResponse:
...
@@ -467,6 +487,113 @@ def add_wiki_warning(file_path: str, warning_text: str) -> ToolResponse:
except
Exception
as
e
:
except
Exception
as
e
:
return
ToolResponse
(
content
=
[
TextBlock
(
type
=
"text"
,
text
=
f
"❌ 添加警告失败: {str(e)}"
)])
return
ToolResponse
(
content
=
[
TextBlock
(
type
=
"text"
,
text
=
f
"❌ 添加警告失败: {str(e)}"
)])
# ==================================================================================
# index.md 确定性重建(供 ingest / egress / lint 复用)
# ==================================================================================
# type -> (展示分组标题, 排序权重)。同时兼容单复数两种写法。
_INDEX_TYPE_GROUPS
=
[
(
"entities"
,
"实体(entities/)"
),
(
"products"
,
"产品(products/)"
),
(
"concepts"
,
"概念(concepts/)"
),
(
"procedures"
,
"流程(procedures/)"
),
(
"scripts"
,
"话术(scripts/)"
),
(
"policies"
,
"政策(policies/)"
),
(
"comparisons"
,
"对比(comparisons/)"
),
(
"troubleshooting"
,
"系统排障(troubleshooting/)"
),
(
"sources"
,
"资料摘要(sources/)"
),
(
"synthesis"
,
"综合分析(synthesis/)"
),
]
# 单数/异体 type 值归一到上面的复数分组键
_INDEX_TYPE_ALIAS
=
{
"entity"
:
"entities"
,
"product"
:
"products"
,
"concept"
:
"concepts"
,
"procedure"
:
"procedures"
,
"script"
:
"scripts"
,
"policy"
:
"policies"
,
"comparison"
:
"comparisons"
,
"source"
:
"sources"
,
"syntheses"
:
"synthesis"
,
"synthesi"
:
"synthesis"
,
}
def
_normalize_index_type
(
raw_type
)
->
str
:
t
=
str
(
raw_type
or
""
)
.
strip
()
.
lower
()
return
_INDEX_TYPE_ALIAS
.
get
(
t
,
t
)
def
rebuild_index
(
wiki_dir
:
str
)
->
int
:
"""
扫描 wiki_dir 下所有页面的 frontmatter,按 type 分组(组内按 series/brand/slug 排序),
确定性地全量重建 index.md。返回纳入索引的页面数。
供 ingest(Phase3 收尾)、egress(删页后)、lint(Phase1 修复)复用,
取代历史上「只追加、易损坏」的索引维护方式。
"""
from
datetime
import
datetime
as
_dt
skip_names
=
{
"index.md"
,
"log.md"
}
skip_dirs
=
{
os
.
path
.
join
(
wiki_dir
,
"metadata"
),
os
.
path
.
join
(
wiki_dir
,
"lint_reports"
)}
# 收集页面元信息:group_key -> list of (sort_key, slug, title)
grouped
:
dict
[
str
,
list
]
=
{}
total
=
0
for
root
,
dirs
,
files
in
os
.
walk
(
wiki_dir
):
dirs
[:]
=
[
d
for
d
in
dirs
if
os
.
path
.
join
(
root
,
d
)
not
in
skip_dirs
]
for
fname
in
files
:
if
not
fname
.
endswith
(
".md"
)
or
fname
in
skip_names
:
continue
fpath
=
os
.
path
.
join
(
root
,
fname
)
slug
=
os
.
path
.
splitext
(
fname
)[
0
]
ptype
,
title
,
series
,
brand
=
""
,
slug
,
""
,
""
try
:
post
=
frontmatter
.
load
(
fpath
)
md
=
post
.
metadata
ptype
=
_normalize_index_type
(
md
.
get
(
"type"
))
title
=
str
(
md
.
get
(
"title"
)
or
slug
)
series
=
str
(
md
.
get
(
"series"
)
or
""
)
b
=
md
.
get
(
"brand"
)
brand
=
(
b
[
0
]
if
isinstance
(
b
,
list
)
and
b
else
str
(
b
or
""
))
if
b
else
""
except
Exception
:
ptype
=
""
group_key
=
ptype
if
ptype
in
dict
(
_INDEX_TYPE_GROUPS
)
else
"_其他"
sort_key
=
(
series
,
brand
,
slug
)
grouped
.
setdefault
(
group_key
,
[])
.
append
((
sort_key
,
slug
,
title
))
total
+=
1
# 组装 markdown
lines
=
[
"# 知识索引"
,
""
,
"> 本文件由系统在每次摄入/摄出/Lint 后自动全量重建,请勿手动编辑。"
,
f
"> 最后更新:{_dt.now().strftime('
%
Y-
%
m-
%
d
%
H:
%
M:
%
S')} | 页面总数:{total}"
,
""
,
]
for
group_key
,
heading
in
_INDEX_TYPE_GROUPS
:
entries
=
grouped
.
get
(
group_key
)
if
not
entries
:
continue
entries
.
sort
(
key
=
lambda
x
:
x
[
0
])
lines
.
append
(
f
"## {heading}"
)
for
_sort_key
,
slug
,
title
in
entries
:
if
title
and
title
!=
slug
:
lines
.
append
(
f
"- [[{slug}]] — {title}"
)
else
:
lines
.
append
(
f
"- [[{slug}]]"
)
lines
.
append
(
""
)
# 未识别 type 的兜底分组
others
=
grouped
.
get
(
"_其他"
)
if
others
:
others
.
sort
(
key
=
lambda
x
:
x
[
0
])
lines
.
append
(
"## 未分类"
)
for
_sort_key
,
slug
,
title
in
others
:
lines
.
append
(
f
"- [[{slug}]] — {title}"
if
title
and
title
!=
slug
else
f
"- [[{slug}]]"
)
lines
.
append
(
""
)
index_path
=
os
.
path
.
join
(
wiki_dir
,
"index.md"
)
with
open
(
index_path
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
"
\n
"
.
join
(
lines
)
.
rstrip
()
+
"
\n
"
)
return
total
def
remove_wiki_link
(
file_path
:
str
,
target
:
str
)
->
ToolResponse
:
def
remove_wiki_link
(
file_path
:
str
,
target
:
str
)
->
ToolResponse
:
"""
"""
将指定的断链转化为纯文本。例如 [[target]] 变为 target,[[target|别名]] 变为 别名。
将指定的断链转化为纯文本。例如 [[target]] 变为 target,[[target|别名]] 变为 别名。
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment