feat(pkb): Integrate pgvector and create Dify replacement plan

Summary:
- Migrate PostgreSQL to pgvector/pgvector:pg15 Docker image
- Successfully install and verify pgvector 0.8.1 extension
- Create comprehensive Dify-to-pgvector migration plan
- Update PKB module documentation with pgvector status
- Update system documentation with pgvector integration

Key changes:
- docker-compose.yml: Switch to pgvector/pgvector:pg15 image
- Add EkbDocument and EkbChunk data model design
- Design R-C-R-G hybrid retrieval architecture
- Add clinical data JSONB fields (pico, studyDesign, regimen, safety, criteria, endpoints)
- Create detailed 10-day implementation roadmap

Documentation updates:
- PKB module status: pgvector RAG infrastructure ready
- System status: pgvector 0.8.1 integrated
- New: Dify replacement development plan (01-Dify替换为pgvector开发计划.md)
- New: Enterprise medical knowledge base solution V2

Tested: PostgreSQL with pgvector verified, frontend and backend functionality confirmed
This commit is contained in:
2026-01-20 00:00:58 +08:00
parent 1ece9a4ae8
commit dfc0fe0b9a
289 changed files with 1897 additions and 41 deletions

View File

@@ -51,5 +51,6 @@ Status: Day 1 complete (11/11 tasks), ready for Day 2

View File

@@ -281,5 +281,6 @@

View File

@@ -0,0 +1,23 @@
# 基于已有的 postgres:15-alpine 镜像构建 pgvector 版本
# pgvector 版本0.8.0(与阿里云 RDS PostgreSQL 15 保持一致)
FROM postgres:15-alpine
# 使用阿里云镜像源加速 Alpine 包下载
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 复制本地下载的 pgvector 源码包
COPY pgvector-0.8.0.tar.gz /tmp/pgvector-0.8.0.tar.gz
# 安装编译依赖并编译 pgvector禁用 LLVM bitcode 编译)
RUN apk add --no-cache --virtual .build-deps \
build-base \
&& cd /tmp \
&& tar -xzf pgvector-0.8.0.tar.gz \
&& cd pgvector-0.8.0 \
&& sed -i 's/^with_llvm.*/with_llvm = no/' /usr/local/lib/postgresql/pgxs/src/Makefile.global \
&& make USE_PGXS=1 PG_CONFIG=/usr/local/bin/pg_config \
&& make USE_PGXS=1 PG_CONFIG=/usr/local/bin/pg_config install \
&& cd / \
&& rm -rf /tmp/pgvector-0.8.0 /tmp/pgvector-0.8.0.tar.gz \
&& apk del .build-deps

View File

@@ -227,5 +227,6 @@ https://iit.xunzhengyixue.com/api/v1/iit/health

View File

@@ -156,5 +156,6 @@ https://iit.xunzhengyixue.com/api/v1/iit/health

View File

@@ -57,5 +57,6 @@

View File

@@ -317,5 +317,6 @@ npx tsx src/modules/iit-manager/test-patient-wechat-url-verify.ts

View File

@@ -179,5 +179,6 @@ npm run dev

View File

@@ -58,3 +58,4 @@ main()

View File

@@ -52,3 +52,4 @@ main()

View File

@@ -47,3 +47,4 @@ main()

View File

@@ -79,3 +79,4 @@ main()

View File

@@ -42,3 +42,4 @@ main()

View File

@@ -83,3 +83,4 @@ main()

View File

@@ -30,3 +30,4 @@ main()

View File

@@ -118,3 +118,4 @@ main()

View File

@@ -89,3 +89,4 @@ main()

View File

@@ -75,3 +75,4 @@ main()

View File

@@ -117,3 +117,4 @@ main()

View File

@@ -28,3 +28,4 @@ ON CONFLICT (id) DO NOTHING;

View File

@@ -60,3 +60,4 @@ ON CONFLICT (id) DO NOTHING;

View File

@@ -76,5 +76,6 @@ WHERE table_schema = 'dc_schema'

View File

@@ -114,5 +114,6 @@ ORDER BY ordinal_position;

View File

@@ -127,5 +127,6 @@ runMigration()

View File

@@ -61,5 +61,6 @@ COMMENT ON COLUMN "dc_schema"."dc_tool_c_sessions"."column_mapping" IS '列名

View File

@@ -88,5 +88,6 @@ COMMENT ON COLUMN dc_schema.dc_tool_c_sessions.expires_at IS '过期时间(创

View File

@@ -128,5 +128,6 @@ Write-Host ""

View File

@@ -238,5 +238,6 @@ function extractCodeBlocks(obj, blocks = []) {

View File

@@ -37,3 +37,4 @@ CREATE TABLE IF NOT EXISTS platform_schema.job_common (

View File

@@ -111,3 +111,4 @@ CREATE OR REPLACE FUNCTION platform_schema.delete_queue(queue_name text) RETURNS

View File

@@ -257,5 +257,6 @@ checkDCTables();

View File

@@ -12,3 +12,4 @@ CREATE SCHEMA IF NOT EXISTS capability_schema;

View File

@@ -209,5 +209,6 @@ createAiHistoryTable()

View File

@@ -196,5 +196,6 @@ createToolCTable()

View File

@@ -193,5 +193,6 @@ createToolCTable()

View File

@@ -315,3 +315,4 @@ main()
}) })
.finally(() => prisma.$disconnect()); .finally(() => prisma.$disconnect());

View File

@@ -122,3 +122,4 @@ main()

View File

@@ -342,3 +342,4 @@ runTests().catch(error => {

View File

@@ -88,3 +88,4 @@ testAPI().catch(console.error);

View File

@@ -118,3 +118,4 @@ async function testDeepSearch() {
// ========== 运行 ========== // ========== 运行 ==========
testDeepSearch().catch(console.error); testDeepSearch().catch(console.error);

View File

@@ -307,3 +307,4 @@ verifySchemas()

View File

@@ -195,3 +195,4 @@ export const jwtService = new JWTService();

View File

@@ -325,5 +325,6 @@ export function getBatchItems<T>(

View File

@@ -78,3 +78,4 @@ export interface VariableValidation {

View File

@@ -199,3 +199,4 @@ export function createOpenAIStreamAdapter(

View File

@@ -205,3 +205,4 @@ export async function streamChat(

View File

@@ -23,3 +23,4 @@ export { THINKING_TAGS } from './types';

View File

@@ -98,3 +98,4 @@ export type SSEEventType =

View File

@@ -84,3 +84,4 @@ export async function moduleRoutes(fastify: FastifyInstance) {

View File

@@ -114,3 +114,4 @@ export interface PaginatedResponse<T> {

View File

@@ -161,3 +161,4 @@ export const ROLE_DISPLAY_NAMES: Record<UserRole, string> = {

View File

@@ -236,3 +236,4 @@ async function matchIntent(query: string): Promise<{

View File

@@ -90,3 +90,4 @@ export async function uploadAttachment(
} }

View File

@@ -19,3 +19,4 @@ export { aiaRoutes };

View File

@@ -361,5 +361,6 @@ runTests().catch((error) => {

View File

@@ -340,5 +340,6 @@ Content-Type: application/json

View File

@@ -276,5 +276,6 @@ export const conflictDetectionService = new ConflictDetectionService();

View File

@@ -226,5 +226,6 @@ curl -X POST http://localhost:3000/api/v1/dc/tool-c/test/execute \

View File

@@ -280,5 +280,6 @@ export const streamAIController = new StreamAIController();

View File

@@ -189,5 +189,6 @@ logger.info('[SessionMemory] 会话记忆管理器已启动', {

View File

@@ -123,5 +123,6 @@ checkTableStructure();

View File

@@ -110,5 +110,6 @@ checkProjectConfig().catch(console.error);

View File

@@ -92,5 +92,6 @@ main();

View File

@@ -549,5 +549,6 @@ URL: https://iit.xunzhengyixue.com/api/v1/iit/patient-wechat/callback

View File

@@ -184,5 +184,6 @@ console.log('');

View File

@@ -501,5 +501,6 @@ export const patientWechatService = new PatientWechatService();

View File

@@ -146,5 +146,6 @@ testDifyIntegration().catch(error => {

View File

@@ -175,5 +175,6 @@ testIitDatabase()

View File

@@ -161,5 +161,6 @@ if (hasError) {

View File

@@ -187,5 +187,6 @@ async function testUrlVerification() {

View File

@@ -268,5 +268,6 @@ main().catch((error) => {

View File

@@ -152,5 +152,6 @@ Write-Host ""

View File

@@ -245,5 +245,6 @@ export interface CachedProtocolRules {

View File

@@ -60,3 +60,4 @@ export default async function healthRoutes(fastify: FastifyInstance) {

View File

@@ -138,3 +138,4 @@ Content-Type: application/json

View File

@@ -123,3 +123,4 @@ Write-Host " - 删除任务: DELETE $BaseUrl/api/v1/rvw/tasks/{taskId}" -Foregr

View File

@@ -37,3 +37,4 @@ export * from './services/utils.js';

View File

@@ -128,3 +128,4 @@ export function validateAgentSelection(agents: string[]): void {

View File

@@ -426,5 +426,6 @@ SET session_replication_role = 'origin';

View File

@@ -128,5 +128,6 @@ WHERE key = 'verify_test';

View File

@@ -271,5 +271,6 @@ verifyDatabase()

View File

@@ -61,5 +61,6 @@ export {}

View File

@@ -84,5 +84,6 @@ Write-Host "✅ 完成!" -ForegroundColor Green

View File

@@ -11,3 +11,4 @@ SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN ('p

View File

@@ -174,3 +174,4 @@ DELETE {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases/{{testKbId}}

View File

@@ -371,5 +371,6 @@ runAdvancedTests().catch(error => {

View File

@@ -437,5 +437,6 @@ runAllTests()

View File

@@ -395,5 +395,6 @@ runAllTests()

View File

@@ -31,3 +31,4 @@ main()

View File

@@ -29,3 +29,4 @@ main()

View File

@@ -41,3 +41,4 @@ main()

View File

@@ -30,3 +30,4 @@ main()

View File

@@ -170,3 +170,4 @@ main()

Binary file not shown.

View File

@@ -179,5 +179,6 @@ Set-Location ..

View File

@@ -1,9 +1,9 @@
version: '3.8' version: '3.8'
services: services:
# PostgreSQL 数据库 # PostgreSQL 数据库 (with pgvector extension)
postgres: postgres:
image: postgres:15-alpine image: pgvector/pgvector:pg15
container_name: ai-clinical-postgres container_name: ai-clinical-postgres
environment: environment:
POSTGRES_DB: ai_clinical_research POSTGRES_DB: ai_clinical_research

View File

@@ -1,13 +1,13 @@
# AIclinicalresearch 系统当前状态与开发指南 # AIclinicalresearch 系统当前状态与开发指南
> **文档版本:** v3.7 > **文档版本:** v3.8
> **创建日期:** 2025-11-28 > **创建日期:** 2025-11-28
> **维护者:** 开发团队 > **维护者:** 开发团队
> **最后更新:** 2026-01-18 > **最后更新:** 2026-01-19
> **重大进展:** 🎉 **ASL 智能文献检索DeepSearchMVP 完成** > **重大进展:** 🎉 **pgvector 向量数据库集成完成PKB RAG 基础设施就绪**
> - 🆕 集成 unifuncs DeepSearch APIAI 驱动的 PubMed 自动检索 > - 🆕 pgvector 0.8.1 已安装,支持 HNSW/IVFFlat 索引
> - ✅ SSE 实时流式显示 AI 思考过程 > - ✅ 与阿里云 RDS pgvector 0.8.0 完全兼容
> - ✅ 自然语言输入,自动生成检索策略 > - ✅ PKB 模块 RAG 检索功能基础设施已就绪
> **部署状态:** ✅ 生产环境运行中 | 公网地址http://8.140.53.236/ > **部署状态:** ✅ 生产环境运行中 | 公网地址http://8.140.53.236/
> **文档目的:** 快速了解系统当前状态为新AI助手提供上下文 > **文档目的:** 快速了解系统当前状态为新AI助手提供上下文
@@ -100,7 +100,8 @@
- 架构增量演进legacy + common + modules - 架构增量演进legacy + common + modules
**数据库** **数据库**
- PostgreSQL 15 Docker: postgres:15-alpine - PostgreSQL 15 Docker: pgvector/pgvector:pg15
- **pgvector 0.8.1** ✅ 2026-01-19 新增(向量数据库扩展,支持 RAG
- 12个Schema隔离platform/aia/pkb/asl/dc/iit/ssa/st/rvw/admin/common/capability ✅新增) - 12个Schema隔离platform/aia/pkb/asl/dc/iit/ssa/st/rvw/admin/common/capability ✅新增)
**云原生部署** **云原生部署**
@@ -120,9 +121,52 @@
--- ---
## 🚀 当前开发状态2026-01-18 ## 🚀 当前开发状态2026-01-19
### 🏆 最新进展:AIA V2.1 Prompt管理集成2026-01-18 ### 🏆 最新进展:pgvector 向量数据库集成2026-01-19
#### ✅ pgvector 0.8.1 安装成功
**背景**
- PKB 模块需要实现 RAG 检索功能
- 原计划依赖 Dify 知识库,现改为 PostgreSQL 原生 pgvector 方案
- 与 Postgres-Only 架构理念一致,减少外部依赖
**完成工作**
- ✅ Docker 镜像迁移:`postgres:15-alpine``pgvector/pgvector:pg15`
- ✅ pgvector 扩展安装:版本 0.8.1
- ✅ 数据安全执行双重备份SQL dump + Volume tarball
- ✅ 功能验证:前后端服务重启后功能全部正常
- ✅ 数据完整性用户数据、pg-boss 队列函数全部正常
**技术细节**
| 项目 | 说明 |
|------|------|
| Docker 镜像 | `pgvector/pgvector:pg15` |
| pgvector 版本 | 0.8.1 |
| 支持索引类型 | HNSW、IVFFlat |
| 最大向量维度 | 16000 维 |
| 阿里云 RDS 兼容性 | ✅ 完全兼容RDS 为 0.8.0 |
**版本兼容性说明**
- 开发环境pgvector 0.8.1
- 生产环境(阿里云 RDSpgvector 0.8.0
- 兼容性0.8.x 系列向后兼容,数据格式和 API 一致
**文件变更**
- `docker-compose.yml`:更新 postgres 服务镜像
- `Dockerfile.postgres-pgvector`:自定义构建文件(备用)
- `backup_before_pgvector_20260119.sql`:迁移前备份
- `postgres_volume_backup_20260119.tar`Volume 备份
**下一步**
- 设计 `pkb_schema.document_embeddings` 向量表
- 集成 Embedding 服务OpenAI/智谱)
- 实现 RAG 检索 API
---
### 🏆 历史进展AIA V2.1 Prompt管理集成2026-01-18
#### ✅ AIA 模块 Prompt 管理系统集成 #### ✅ AIA 模块 Prompt 管理系统集成
@@ -378,7 +422,7 @@ data: [DONE]\n\n
**详细文档:** [AIA模块状态与开发指南](../../03-业务模块/AIA-AI智能问答/00-模块当前状态与开发指南.md) **详细文档:** [AIA模块状态与开发指南](../../03-业务模块/AIA-AI智能问答/00-模块当前状态与开发指南.md)
#### 3. PKB模块 - 个人知识库 🎉 **前端V3设计完成** #### 3. PKB模块 - 个人知识库 🎉 **pgvector RAG基础设施就绪**
**开发进度** **开发进度**
-**后端API**100%完成v1 + v2双路由运行 -**后端API**100%完成v1 + v2双路由运行
@@ -387,7 +431,7 @@ data: [DONE]\n\n
-**全文阅读模式**90%完成Chat组件集成 -**全文阅读模式**90%完成Chat组件集成
-**逐篇精读模式**85%完成(文档选择+对话) -**逐篇精读模式**85%完成(文档选择+对话)
- 🔧 **批处理模式**70%完成UI完成API待调试 - 🔧 **批处理模式**70%完成UI完成API待调试
- **RAG检索模式**0%(后端待实现 - 🟡 **RAG检索模式**基础设施就绪pgvector 0.8.1 已安装),业务逻辑待实现
**核心功能** **核心功能**
- 知识库CRUD + 文档管理 - 知识库CRUD + 文档管理
@@ -400,11 +444,12 @@ data: [DONE]\n\n
- ✅ Zustand状态管理 - ✅ Zustand状态管理
- ✅ 复用shared/components/Chat通用组件 - ✅ 复用shared/components/Chat通用组件
- ✅ 单层Header + 紧凑工作模式栏设计 - ✅ 单层Header + 紧凑工作模式栏设计
-**pgvector 0.8.1 已集成**2026-01-19
**待解决问题** **待解决问题**
- 🔧 批处理API执行待调试 - 🔧 批处理API执行待调试
- 🔧 知识资产页面导航条待完善 - 🔧 知识资产页面导航条待完善
- 🔧 UI与原型图精细化对比 - 🔧 RAG 检索业务逻辑待实现向量表设计、Embedding服务
**详细文档**[PKB模块当前状态](../03-业务模块/PKB-个人知识库/00-模块当前状态与开发指南.md) **详细文档**[PKB模块当前状态](../03-业务模块/PKB-个人知识库/00-模块当前状态与开发指南.md)
@@ -896,7 +941,8 @@ AIclinicalresearch/
| **2026-01-02** | **REDCap对接方案** 🏆 | ✅ REDCap环境部署 + DET+REST API方案确定 | | **2026-01-02** | **REDCap对接方案** 🏆 | ✅ REDCap环境部署 + DET+REST API方案确定 |
| **2026-01-07 上午** | **PKB前端V3** 🎉 | ✅ PKB模块前端V3设计实现完成Dashboard+Workspace+3种工作模式 | | **2026-01-07 上午** | **PKB前端V3** 🎉 | ✅ PKB模块前端V3设计实现完成Dashboard+Workspace+3种工作模式 |
| **2026-01-07 下午** | **PKB批处理完善** 🏆 | ✅ 批处理完整流程调试通过(执行+进度+结果导出)+ 文档上传功能 + UI优化 | | **2026-01-07 下午** | **PKB批处理完善** 🏆 | ✅ 批处理完整流程调试通过(执行+进度+结果导出)+ 文档上传功能 + UI优化 |
| **当前** | **PKB模块生产可用** | ✅ 核心功能全部实现90%),具备生产环境部署条件 | | **2026-01-19** | **pgvector集成** 🎉 | ✅ pgvector 0.8.1 安装成功PKB RAG基础设施就绪 |
| **当前** | **PKB模块生产可用** | ✅ 核心功能全部实现90%pgvector已集成RAG业务逻辑待开发 |
| **2026-01-07 晚** | **RVW模块开发完成** 🎉 | ✅ Phase 1-3完成后端迁移+数据库扩展+前端重构) | | **2026-01-07 晚** | **RVW模块开发完成** 🎉 | ✅ Phase 1-3完成后端迁移+数据库扩展+前端重构) |
--- ---
@@ -1001,7 +1047,8 @@ AIclinicalresearch/
### 环境要求 ### 环境要求
``` ```
Node.js: v22.18.0+ Node.js: v22.18.0+
PostgreSQL: 15+当前使用15.14 PostgreSQL: 15+当前使用15.14Docker镜像: pgvector/pgvector:pg15
pgvector: 0.8.1(向量数据库扩展)
npm: 10+ npm: 10+
``` ```
@@ -1194,14 +1241,15 @@ if (items.length >= 50) {
## 🌟 技术亮点 ## 🌟 技术亮点
1.**Platform-Only 架构**:统一任务管理,零代码重复 🏆 **新!** 1.**Platform-Only 架构**:统一任务管理,零代码重复 🏆
2.**智能双模式处理**:小任务快速响应,大任务可靠执行 🏆 **新!** 2.**智能双模式处理**:小任务快速响应,大任务可靠执行 🏆
3.**适配器模式**:存储/缓存/日志支持本地↔云端零代码切换 3.**pgvector 向量数据库**PostgreSQL 原生 RAG 支持 🏆 **2026-01-19 新增!**
4.**10个Schema一次性完成**:架构一次到位 4.**适配器模式**:存储/缓存/日志支持本地↔云端零代码切换
5.**Prisma自动路由**Schema迁移后代码无需修改 5.**12个Schema隔离**:架构一次到位
6.**4个LLM集成**DeepSeek、Qwen、GPT、Claude 6.**Prisma自动路由**Schema迁移后代码无需修改
7.**增量演进**:新旧并存,降低风险 7.**4个LLM集成**DeepSeek、Qwen、GPT、Claude
8.**云原生就绪**为SAE部署做好准备 8.**增量演进**新旧并存,降低风险
9.**云原生就绪**为SAE部署做好准备
--- ---
@@ -1213,9 +1261,9 @@ if (items.length >= 50) {
--- ---
**文档版本**v3.1 **文档版本**v3.8
**最后更新**2026-01-10 **最后更新**2026-01-19
**下次更新**RVW生产环境部署 或 ASL智能文献筛选模块启动 **下次更新**PKB RAG检索功能实现 或 生产环境pgvector部署
--- ---

View File

@@ -618,5 +618,6 @@ async saveProcessedData(recordId, newData) {

View File

@@ -231,3 +231,4 @@ const userId = 'test'; // ❌ 应该用 getUserId(request)

Some files were not shown because too many files have changed in this diff Show More