feat: 完成 issue #46 RAG 知识库模板化接入(工艺规范/SOP/国标)

- core/rag-kb:领域 RAG 知识库按模板配置(PRD 5.4/7.3,EPIC #6 子任务)
- templating.py:知识源三类分类 + 模板命名推导 + 零依赖轻量 YAML 配置加载
- documents.py:文档段落抽取分块,chunk 携带 文档/章节/段落 溯源信息
- store.py:from_template_config 按模板自动构建 + 中英混合词频检索 + 类别过滤
- config/kb.template.yaml:ti-cl4 模板 RAG 库资产示例(工艺规范/SOP/国标)
- tests:29 用例全绿(模板化/分块溯源/检索排序/类别过滤/配置校验)
This commit is contained in:
2026-08-04 16:31:31 +08:00
parent 9c3e59695a
commit 1fb1d278d5
11 changed files with 1135 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
"""iAOP-Core · 领域 RAG 知识库(RAG KB)—— 模板化接入。
对应 PRD 5.4「④ LLM 网关 + RAG」与 Issue #46(EPIC #6 子任务):
领域 RAG 知识库改为**按模板配置**(工艺规范 / SOP / 国标 三类知识源),
换行业只改模板资产(`config/kb.template.yaml` + 文档集),内核零改动;
检索返回**命中文档片段 + 来源**(引用溯源,PRD 5.4)。
模块:
- templating 知识源分类 + 模板命名推导(collection/索引/namespace)
+ 轻量 YAML 配置加载(零依赖);
- documents 文档模型 + 段落抽取分块(保留 文档/章节/段落 溯源信息);
- store 模板化知识库(from_template_config 构建)+ 检索 + 类别过滤。
测试:`python -m unittest discover -s tests -v`(在 core/rag-kb 目录下执行)。
"""
__version__ = "0.1.0"
from .documents import Chunk, KbDocument, build_document, chunk_document
from .store import RagKnowledgeBase, RetrievalHit
from .templating import (
KbSourceConfig,
KbTemplateConfig,
KbTemplateNaming,
KnowledgeSourceKind,
load_kb_config,
sanitize,
)
__all__ = [
"KnowledgeSourceKind",
"KbTemplateNaming",
"KbTemplateConfig",
"KbSourceConfig",
"load_kb_config",
"sanitize",
"KbDocument",
"Chunk",
"build_document",
"chunk_document",
"RagKnowledgeBase",
"RetrievalHit",
]