🔄 MBE教育四层架构实施计划 - Cursor AI IDE版 + 知识库迁移方案
📅 创建时间
2026-02-02 04:00
🎯 项目概述
工具: Cursor AI IDE (AI-powered 开发环境)
目标: 完善MBE Education,覆盖L1-L4四层架构
特殊任务: 迁移现有知识库和专家系统
🤖 使用Cursor AI IDE的优势
Cursor AI特性:
✅ AI代码生成 - 快速创建组件
✅ 智能补全 - 提升开发效率
✅ 代码解释 - 理解现有代码
✅ 重构建议 - 优化代码质量
✅ 调试辅助 - 快速定位问题
开发策略:
1. 使用AI生成UI组件模板
2. 用AI理解现有专家系统
3. AI辅助迁移知识库
4. AI生成API接口
5. AI创建测试用例
📊 现有资产盘点
已有知识库 (Knowledge Bases)
总计: 17个知识库
分类统计:
教育类: 2个
- 高校专业选择 (0323a99c343d)
- 公务员考试 (e22dff89-51f)
健康类: 5个
- 运动教练 (e9ba75495a9c)
- 营养治疗师 (f21c2aed7d7b)
- 饮食大脑 (4964c9eff74f)
- 诊断学 (physical_exam_kb)
- 逻辑学 (logic_tutor_kb)
文化类: 3个
- 中国古建筑 (9eed8609b814)
- 日本茶道 (f7cdefb77b24)
- 烘焙 (ccea703c806f)
法律类: 2个
- 民事律师 (civil_lawyer)
- 证券律师 (62837b8c038e)
技术类: 3个
- 系统设计面试 (520adb076e77)
- AI记忆建模 (f7775710a4a2)
- 储能电池 (67e10ca55132)
商业类: 2个
- 解决方案销售 (f836247f2e8d)
- 建模导师 (modeling_expert_kb)
已有专家 (Experts)
总计: 17个动态专家
特点:
✅ 完整的专家档案 (id, name, description)
✅ 关键词系统 (keywords)
✅ 领域标签 (domains)
✅ 优先级设置 (priority)
✅ 问候语 (greeting)
✅ 系统提示词 (system_prompt)
✅ 启用状态 (enabled)
存储位置:
- knowledge_bases/experts/index.json
- knowledge_bases/index.json
- knowledge_bases/*_chunks.json (知识块)
🔄 知识库和专家迁移策略
Phase 0: 迁移准备 (1-2天)
0.1 评估现有专家质量
任务: 分析17个专家,筛选适合教育场景的专家
优先迁移 (高价值教育专家):
1. 高校专业选择导师 ⭐⭐⭐⭐⭐
- 直接匹配教育场景
- kb_id: 0323a99c343d
- 可创建"专业选择"课程
2. 逻辑学导师 ⭐⭐⭐⭐⭐
- 编程逻辑教学
- kb_id: logic_tutor_kb
- 可创建"逻辑思维"课程
3. 系统设计面试专家 ⭐⭐⭐⭐⭐
- 技术教育
- kb_id: 520adb076e77
- 可创建"系统设计"课程
次要迁移 (可选专家):
4. 运动教练 ⭐⭐⭐
5. 营养治疗师 ⭐⭐⭐
6. 公务员考试导师 ⭐⭐⭐
暂不迁移 (不适合教育场景):
- 民事律师 (专业性太强)
- 证券律师 (专业性太强)
- 储能电池 (过于专业)
- 解决方案销售 (商业类)
0.2 设计迁移架构
// 新的应用架构
mbe-education/
├── backend/
│ ├── knowledge_bases/ # 迁移的知识库
│ │ ├── experts/ # 专家索引
│ │ │ └── index.json
│ │ ├── chunks/ # 知识块
│ │ │ ├── logic_tutor_kb_chunks.json
│ │ │ ├── 0323a99c343d_chunks.json
│ │ │ └── ...
│ │ └── embeddings/ # 向量嵌入
│ │ ├── logic_tutor_kb_embeddings.npy
│ │ └── ...
│ ├── api/
│ │ ├── expert_router.py # 专家路由
│ │ └── knowledge_api.py # 知识库API
│ └── config/
│ └── expert_config.json # 专家配置
│
├── frontend/
│ ├── app/
│ │ ├── student/
│ │ │ └── learn/
│ │ │ └── [courseId]/
│ │ │ └── [lessonId]/
│ │ │ └── page.tsx # AI对话学习
│ │ └── admin/
│ │ └── experts/
│ │ ├── page.tsx # 专家管理
│ │ └── create/
│ │ └── page.tsx # 创建专家
│ └── lib/
│ └── expert-client.ts # 专家API客户端
Phase 0.3: 知识库迁移脚本
使用Cursor AI辅助创建迁移脚本
# scripts/migrate_knowledge_bases.py
"""
知识库迁移脚本
从 MBE核心 迁移知识库到 MBE Education应用
"""
import json
import shutil
from pathlib import Path
from typing import List, Dict
# 源路径 (MBE核心)
SOURCE_KB_DIR = Path("../../knowledge_bases")
SOURCE_EXPERTS = SOURCE_KB_DIR / "experts" / "index.json"
# 目标路径 (MBE Education)
TARGET_KB_DIR = Path("../opensource/mbe-education/backend/knowledge_bases")
TARGET_EXPERTS = TARGET_KB_DIR / "experts" / "index.json"
# 需要迁移的专家ID列表
EXPERTS_TO_MIGRATE = [
"dynamic_0323a99c343d", # 高校专业选择
"dynamic_logic_tutor_kb", # 逻辑学导师
"dynamic_520adb076e77", # 系统设计面试
"dynamic_e9ba75495a9c", # 运动教练
"dynamic_f21c2aed7d7b", # 营养治疗师
"dynamic_e22dff89-51f", # 公务员考试
]
def migrate_experts():
"""迁移专家配置"""
# 读取源专家索引
with open(SOURCE_EXPERTS) as f:
source_data = json.load(f)
# 筛选需要迁移的专家
experts_to_migrate = [
expert for expert in source_data["experts"]
if expert["id"] in EXPERTS_TO_MIGRATE
]
# 写入目标专家索引
TARGET_EXPERTS.parent.mkdir(parents=True, exist_ok=True)
target_data = {
"experts": experts_to_migrate,
"migrated_from": "mbe-core",
"migrated_at": datetime.now().isoformat()
}
with open(TARGET_EXPERTS, "w", encoding="utf-8") as f:
json.dump(target_data, f, ensure_ascii=False, indent=2)
print(f"✅ 迁移了 {len(experts_to_migrate)} 个专家")
return experts_to_migrate
def migrate_knowledge_chunks(experts: List[Dict]):
"""迁移知识块文件"""
chunks_dir = TARGET_KB_DIR / "chunks"
chunks_dir.mkdir(parents=True, exist_ok=True)
for expert in experts:
kb_id = expert["kb_id"]
source_chunks = SOURCE_KB_DIR / f"{kb_id}_chunks.json"
if source_chunks.exists():
target_chunks = chunks_dir / f"{kb_id}_chunks.json"
shutil.copy(source_chunks, target_chunks)
print(f"✅ 迁移知识块: {kb_id}")
else:
print(f"⚠️ 未找到知识块: {kb_id}")
def migrate_embeddings(experts: List[Dict]):
"""迁移向量嵌入 (如果存在)"""
embeddings_dir = TARGET_KB_DIR / "embeddings"
embeddings_dir.mkdir(parents=True, exist_ok=True)
for expert in experts:
kb_id = expert["kb_id"]
# 尝试多种可能的嵌入文件格式
for ext in [".npy", ".pkl", "_embeddings.npy", "_embeddings.pkl"]:
source_embed = SOURCE_KB_DIR / f"{kb_id}{ext}"
if source_embed.exists():
target_embed = embeddings_dir / f"{kb_id}{ext}"
shutil.copy(source_embed, target_embed)
print(f"✅ 迁移嵌入: {kb_id}{ext}")
break
def create_course_mappings(experts: List[Dict]):
"""为每个专家创建对应的课程"""
course_mappings = []
for expert in experts:
course = {
"id": f"course_{expert['kb_id']}",
"name": expert["name"].replace("专家", "").replace("导师", ""),
"expert_id": expert["id"],
"kb_id": expert["kb_id"],
"description": expert["description"],
"level": "入门" if expert["priority"] < 7 else "中级",
"estimated_hours": 10,
"knowledge_points": [] # 从chunks自动生成
}
course_mappings.append(course)
# 保存课程映射
courses_file = TARGET_KB_DIR / "course_mappings.json"
with open(courses_file, "w", encoding="utf-8") as f:
json.dump(course_mappings, f, ensure_ascii=False, indent=2)
print(f"✅ 创建了 {len(course_mappings)} 个课程映射")
if __name__ == "__main__":
print("🔄 开始迁移知识库和专家...")
# 1. 迁移专家配置
experts = migrate_experts()
# 2. 迁移知识块
migrate_knowledge_chunks(experts)
# 3. 迁移向量嵌入
migrate_embeddings(experts)
# 4. 创建课程映射
create_course_mappings(experts)
print("✅ 迁移完成!")
使用方法:
# 在Cursor中打开终端
cd scripts
python migrate_knowledge_bases.py
🚀 使用Cursor AI的四层架构实施
Phase 1: L4 最终用户层 (Week 1-2)
1.1 使用Cursor AI创建学习界面
Prompt给Cursor:
创建一个AI学习对话界面组件:
- 路径: frontend/app/student/[id]/learn/[courseId]/[lessonId]/page.tsx
- 功能:
1. 左侧显示知识点大纲
2. 中间是AI对话区 (WebSocket实时通信)
3. 右侧是练习区 (代码编辑器)
4. 调用 /api/expert/ask 与专家对话
5. 显示惊讶度指标
- 技术栈: Next.js 14, TypeScript, Tailwind CSS, Framer Motion
- 参考: VSCode的布局风格
Cursor会生成:
- 完整的React组件
- WebSocket集成代码
- API调用逻辑
- 样式文件
1.2 集成现有专家系统
Backend API创建 (让Cursor帮忙):
# backend/api/expert_api.py
"""
专家API - 连接前端和专家系统
"""
from fastapi import APIRouter, HTTPException
from src.knowledge.expert_router import route_to_expert
from src.knowledge.dynamic_expert import DynamicExpertManager
router = APIRouter(prefix="/api/expert", tags=["expert"])
@router.post("/ask")
async def ask_expert(
query: str,
student_id: str,
course_id: str,
lesson_id: str
):
"""学生向专家提问"""
try:
# 1. 根据课程ID找到对应的专家
expert_id = get_expert_by_course(course_id)
# 2. 调用专家路由
result = await route_to_expert(
query=query,
student_id=student_id,
context={"course_id": course_id, "lesson_id": lesson_id}
)
# 3. 记录学习数据
await record_learning(student_id, course_id, result)
return {
"answer": result["answer"],
"confidence": result["confidence"],
"surprise": result["surprise"],
"expert_used": result["expert_id"]
}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
1.3 创建课程与专家的映射
自动生成课程 (Cursor辅助):
// frontend/lib/course-generator.ts
/**
* 从迁移的专家自动生成课程
*/
interface Expert {
id: string;
name: string;
description: string;
kb_id: string;
keywords: string[];
domains: string[];
}
interface Course {
id: string;
name: string;
description: string;
expert_id: string;
difficulty: 'beginner' | 'intermediate' | 'advanced';
lessons: Lesson[];
}
function generateCoursesFromExperts(experts: Expert[]): Course[] {
return experts.map(expert => ({
id: `course_${expert.kb_id}`,
name: expert.name.replace(/专家|导师/, ''),
description: expert.description,
expert_id: expert.id,
difficulty: expert.priority > 7 ? 'advanced' : 'intermediate',
lessons: generateLessonsFromKeywords(expert.keywords)
}));
}
function generateLessonsFromKeywords(keywords: string[]): Lesson[] {
// 根据关键词自动生成课程大纲
// Cursor AI可以帮助优化这个逻辑
const topKeywords = keywords.slice(0, 10);
return topKeywords.map((kw, idx) => ({
id: `lesson_${idx}`,
title: `${kw}基础`,
order: idx,
estimated_minutes: 30
}));
}
Phase 2: L3 应用开发者层 (Week 3-4)
2.1 创建Expert API文档
使用Cursor生成OpenAPI文档:
# docs/api/expert-api.yaml
openapi: 3.0.0
info:
title: MBE Education Expert API
version: 1.0.0
description: 调用专家系统进行AI教学
paths:
/api/expert/list:
get:
summary: 获取所有可用专家
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Expert'
/api/expert/ask:
post:
summary: 向专家提问
requestBody:
content:
application/json:
schema:
type: object
properties:
query:
type: string
description: 学生的问题
student_id:
type: string
course_id:
type: string
expert_id:
type: string
description: 可选,指定专家
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/ExpertResponse'
components:
schemas:
Expert:
type: object
properties:
id:
type: string
name:
type: string
description:
type: string
keywords:
type: array
items:
type: string
ExpertResponse:
type: object:
properties:
answer:
type: string
confidence:
type: number
surprise:
type: number
expert_used:
type: string
Cursor可以自动:
- 生成完整的API文档
- 创建API测试用例
- 生成客户端SDK
Phase 3: L2 专家市场层 (Week 5-7)
3.1 专家创建工具 (复用迁移逻辑)
管理界面 (Cursor生成):
// frontend/app/admin/experts/create/page.tsx
'use client';
export default function CreateExpertPage() {
// Cursor会生成完整的专家创建表单
// 包括:
// 1. 文件上传 (PDF/DOCX/TXT)
// 2. 自动提取关键词
// 3. 配置专家参数
// 4. 预览专家效果
// 5. 发布到系统
}
Backend处理 (复用dynamic_expert.py):
# backend/api/expert_management.py
"""
专家管理API - 复用现有的DynamicExpertManager
"""
from src.knowledge.dynamic_expert import DynamicExpertManager
expert_manager = DynamicExpertManager()
@router.post("/admin/experts/create")
async def create_expert(
name: str,
description: str,
files: List[UploadFile],
user_role: str = "developer" # 权限检查
):
"""创建新专家 - 复用现有逻辑"""
# 这个功能已经在dynamic_expert.py中实现
# 只需要包装成API接口
kb_id = await expert_manager.create_from_files(
files=files,
name=name,
description=description
)
return {"expert_id": f"dynamic_{kb_id}", "status": "created"}
📋 完整的8周实施计划 (Cursor AI加速版)
Week 1: L4 学生端 + 知识库迁移
Day 1-2: 迁移准备
- 运行迁移脚本
- 验证专家可用性
- 创建课程映射
Cursor任务:
"创建知识库迁移脚本,从../../knowledge_bases迁移6个教育专家"
Day 3-4: 学习中心
- 课程列表页面
- 专家驱动的课程展示
Cursor任务:
"创建课程列表组件,从backend/knowledge_bases/course_mappings.json读取数据"
Day 5-7: AI学习对话
- WebSocket集成
- 调用Expert API
- 实时对话界面
Cursor任务:
"创建AI对话学习页面,使用WebSocket连接/api/expert/ask,显示惊讶度"
Week 2: L4 教师端
Day 1-3: 课程创建工具
- 选择专家
- 生成课程大纲
- AI辅助内容生成
Cursor任务:
"创建课程创建表单,可以选择已有专家,AI生成课程大纲"
Day 4-5: 学习数据分析
- 整合HOPE数据
- 可视化惊讶度分布
Cursor任务:
"创建学习分析页面,展示学生惊讶度热力图和知识点掌握度"
Day 6-7: 测试和优化
Week 3-4: L3 开发者工具
Day 1-2: API文档系统
- OpenAPI生成
- Swagger UI集成
Cursor任务:
"从expert_api.py自动生成OpenAPI文档,创建Swagger UI页面"
Day 3-4: SDK开发
- Python SDK
- JavaScript SDK
Cursor任务:
"创建Python SDK封装/api/expert/*端点,支持同步和异步调用"
Day 5-7: 沙盒环境
Week 5-7: L2 专家市场
Day 1-3: 专家管理界面
- 列表/创建/编辑
- 复用dynamic_expert
Cursor任务:
"创建专家管理后台,复用src/knowledge/dynamic_expert.py的功能"
Day 4-7: 专家训练和发布
Week 8: L1 核心监控
Day 1-5: 监控和文档
- 系统监控面板
- 完整文档整理
🎯 Cursor AI使用技巧
1. 代码生成Prompt模板
Context: MBE Education - AI驱动的学习平台
Tech Stack: Next.js 14, FastAPI, TypeScript, Python
Goal: [具体目标]
Create [组件/API/功能]:
- File: [文件路径]
- Requirements:
1. [需求1]
2. [需求2]
3. [需求3]
- Style: [设计风格]
- Integration: [需要集成的API/组件]
Please generate complete, production-ready code with:
- Error handling
- TypeScript types
- Comments in Chinese
- Responsive design
2. 理解现有代码
Explain this code:
[粘贴 dynamic_expert.py 的代码]
How can I integrate it into MBE Education's API?
What modifications are needed?
3. 重构建议
Refactor this component to:
- Use Framer Motion for animations
- Follow MBE Education's design system
- Improve performance
- Add error boundaries
📊 迁移检查清单
知识库迁移
✅ 步骤:
1. 运行迁移脚本
2. 验证文件完整性
3. 测试专家响应
4. 创建课程映射
5. 更新前端配置
✅ 验证:
- [ ] 所有chunks文件已复制
- [ ] 所有embeddings文件已复制
- [ ] experts/index.json正确
- [ ] 专家可以正常回答
- [ ] 课程映射已生成
专家系统集成
✅ 步骤:
1. 包装dynamic_expert为API
2. 创建专家路由端点
3. 前端调用测试
4. 性能优化
5. 缓存配置
✅ 验证:
- [ ] API响应< 500ms
- [ ] 专家匹配准确
- [ ] 惊讶度计算正确
- [ ] HOPE学习生效
- [ ] 缓存工作正常
🎊 完成后的系统状态
MBE Education v2.0:
✅ 17个迁移的专家 (6个教育相关优先)
✅ 完整的L1-L4四层架构
✅ 学生AI学习界面
✅ 教师课程创建工具
✅ 开发者API和SDK
✅ 专家市场和管理
✅ 核心监控面板
技术栈:
✅ Cursor AI辅助开发
✅ Next.js 14 + FastAPI
✅ 复用MBE Core专家系统
✅ WebSocket实时通信
✅ HOPE惊讶度学习
✅ TITANS检索系统
💡 关键优势
使用Cursor AI
开发速度:
传统开发: 8周
Cursor辅助: 4-6周 (提升33-50%)
代码质量:
AI生成: 基础框架
人工审核: 逻辑优化
结果: 高质量+高效率
学习曲线:
AI解释现有代码
AI提供最佳实践
快速理解MBE架构
迁移现有资产
避免重复开发:
✅ 17个专家直接可用
✅ 知识库无需重建
✅ 专家路由已优化
✅ HOPE系统成熟
快速启动:
✅ 第一周就有可用专家
✅ 立即提供AI教学
✅ 展示核心价值
准备好开始了吗? 🚀
下一步:
- ✅ 审核迁移计划
- ✅ 运行迁移脚本
- ✅ 用Cursor开始开发
完成时间: 2026-02-02 04:00
文档类型: 实施计划 + 迁移方案
工具: Cursor AI IDE
预计周期: 4-6周 (AI加速)