Major Changes: - Add StreamingService with OpenAI Compatible format - Upgrade Chat component V2 with Ant Design X integration - Implement AIA module with 12 intelligent agents - Update API routes to unified /api/v1 prefix - Update system documentation Backend (~1300 lines): - common/streaming: OpenAI Compatible adapter - modules/aia: 12 agents, conversation service, streaming integration - Update route versions (RVW, PKB to v1) Frontend (~3500 lines): - modules/aia: AgentHub + ChatWorkspace (100% prototype restoration) - shared/Chat: AIStreamChat, ThinkingBlock, useAIStream Hook - Update API endpoints to v1 Documentation: - AIA module status guide - Universal capabilities catalog - System overview updates - All module documentation sync Tested: Stream response verified, authentication working Status: AIA V2.0 core completed (85%)
609 lines
18 KiB
Markdown
609 lines
18 KiB
Markdown
# PKB - 涓<>汉鐭ヨ瘑搴撴ā鍧楋細鏁版嵁搴撹<E690B4>璁?
|
||
|
||
> **鐗堟湰锛?* v1.0
|
||
> **鏇存柊鏃堕棿锛?* 2025-11-12
|
||
> **鏁版嵁搴揝chema锛?* `pkb_schema`
|
||
> **鐘舵€侊細** 鉁?宸插疄鏂藉苟杩佺Щ
|
||
|
||
---
|
||
|
||
## 馃搵 鐩<>綍
|
||
|
||
1. [妯″潡姒傝堪](#妯″潡姒傝堪)
|
||
2. [Schema淇℃伅](#schema淇℃伅)
|
||
3. [鏁版嵁搴撹〃璁捐<EFBFBD>](#鏁版嵁搴撹〃璁捐<E79281>)
|
||
4. [琛ㄥ叧绯诲浘](#琛ㄥ叧绯诲浘)
|
||
5. [绱㈠紩璁捐<EFBFBD>](#绱㈠紩璁捐<E79281>)
|
||
6. [Phase 3鍔熻兘璇存槑](#phase-3鍔熻兘璇存槑)
|
||
7. [鍙樻洿鍘嗗彶](#鍙樻洿鍘嗗彶)
|
||
|
||
---
|
||
|
||
## 妯″潡姒傝堪
|
||
|
||
### 鍔熻兘瀹氫綅
|
||
|
||
**PKB锛圥ersonal Knowledge Base锛? 涓<>汉鐭ヨ瘑搴撴ā鍧?*鎻愪緵鏂囩尞绠$悊鍜屾櫤鑳介棶绛旇兘鍔涳紝鏍稿績鍔熻兘锛?
|
||
|
||
1. **鐭ヨ瘑搴撶<E690B4>鐞?* - 鍒涘缓鍜岀<E98D9C>鐞嗕釜浜虹煡璇嗗簱
|
||
2. **鏂囨。涓婁紶** - 鏀<>寔PDF/Word/TXT绛夋牸寮忔枃妗?
|
||
3. **鏅鸿兘闂<E58598>瓟** - 鍩轰簬鐭ヨ瘑搴撶殑RAG锛堟<E9949B>绱㈠<E7BBB1>寮虹敓鎴愶級瀵硅瘽
|
||
4. **鎵瑰<E98EB5>鐞嗕换鍔?* - 鎵归噺澶勭悊鏂囩尞鎻愬彇锛圥hase 3锛?
|
||
5. **浠诲姟妯℃澘** - 棰勫畾涔夌殑鎵瑰<E98EB5>鐞嗕换鍔℃ā鏉匡紙Phase 3锛?
|
||
|
||
### 鏍稿績涓氬姟鍦烘櫙
|
||
|
||
- 鐢ㄦ埛鍒涘缓鐭ヨ瘑搴擄紙濡?CLL鐩稿叧鐭ヨ瘑搴?锛?
|
||
- 涓婁紶PDF鏂囩尞鍒扮煡璇嗗簱
|
||
- 鑷<>姩鎻愬彇鏂囨湰骞跺悜閲忓寲
|
||
- 鍩轰簬鐭ヨ瘑搴撹繘琛屾櫤鑳介棶绛?
|
||
- 鎵归噺鎻愬彇鏂囩尞涓<E5B09E>殑缁撴瀯鍖栦俊鎭?
|
||
|
||
### 涓嶥ify骞冲彴闆嗘垚
|
||
|
||
PKB妯″潡娣卞害闆嗘垚Dify骞冲彴锛?
|
||
- 姣忎釜鐭ヨ瘑搴撳<E690B4>搴斾竴涓狣ify Dataset
|
||
- 姣忎釜鏂囨。瀵瑰簲涓€涓狣ify Document
|
||
- 浣跨敤Dify鐨勫悜閲忔<E996B2>绱㈠拰RAG鑳藉姏
|
||
|
||
---
|
||
|
||
## Schema淇℃伅
|
||
|
||
### Schema鍚嶇О
|
||
```sql
|
||
pkb_schema
|
||
```
|
||
|
||
### 鍒涘缓璇<E7BC93>彞
|
||
```sql
|
||
CREATE SCHEMA IF NOT EXISTS pkb_schema;
|
||
GRANT ALL ON SCHEMA pkb_schema TO aiclinical_admin;
|
||
```
|
||
|
||
### 鏁版嵁杩佺Щ
|
||
- **杩佺Щ鏃堕棿锛?* 2025-11-12
|
||
- **婧怱chema锛?* public
|
||
- **杩佺Щ鑴氭湰锛?* `docs/09-鏋舵瀯瀹炴柦/migration-scripts/004-migrate-pkb.sql`
|
||
- **鏁版嵁瀹屾暣鎬э細** 鉁?100%杩佺Щ鎴愬姛
|
||
|
||
---
|
||
|
||
## 鏁版嵁搴撹〃璁捐<E79281>
|
||
|
||
### 琛ㄥ垪琛?
|
||
|
||
| 琛ㄥ悕 | 鐢ㄩ€?| 琛屾暟锛堜及璁★級 | 鐘舵€?|
|
||
|------|------|------------|------|
|
||
| `knowledge_bases` | 鐭ヨ瘑搴?| 5-50/鐢ㄦ埛 | 鉁?宸查儴缃?|
|
||
| `documents` | 鏂囨。 | 10-1000/鐭ヨ瘑搴?| 鉁?宸查儴缃?|
|
||
| `batch_tasks` | 鎵瑰<E98EB5>鐞嗕换鍔?| 1-100/鐭ヨ瘑搴?| 鉁?Phase 3 |
|
||
| `batch_results` | 鎵瑰<E98EB5>鐞嗙粨鏋?| N鏉?浠诲姟 | 鉁?Phase 3 |
|
||
| `task_templates` | 浠诲姟妯℃澘 | 10-50/鐢ㄦ埛 | 鉁?Phase 3锛堥<E9949B>鐣欙級 |
|
||
|
||
**鎬昏<E98EAC>锛?* 5涓<35>〃锛?涓<>牳蹇冭〃 + 3涓狿hase 3琛<33>級
|
||
|
||
---
|
||
|
||
### 1. knowledge_bases - 鐭ヨ瘑搴撹〃
|
||
|
||
**鐢ㄩ€旓細** 瀛樺偍鐢ㄦ埛鍒涘缓鐨勪釜浜虹煡璇嗗簱
|
||
|
||
#### 琛ㄧ粨鏋?
|
||
|
||
| 瀛楁<E7809B>鍚?| 鏁版嵁绫诲瀷 | 绾︽潫 | 璇存槑 |
|
||
|--------|---------|------|------|
|
||
| id | TEXT | PRIMARY KEY | 鐭ヨ瘑搴撳敮涓€鏍囪瘑锛圲UID锛?|
|
||
| user_id | TEXT | NOT NULL, FK | 鎵€灞炵敤鎴稩D |
|
||
| name | TEXT | NOT NULL | 鐭ヨ瘑搴撳悕绉?|
|
||
| description | TEXT | NULL | 鐭ヨ瘑搴撴弿杩?|
|
||
| dify_dataset_id | TEXT | NOT NULL, UNIQUE | Dify骞冲彴鐨凞ataset ID |
|
||
| file_count | INTEGER | NOT NULL, DEFAULT 0 | 鏂囦欢鏁伴噺 |
|
||
| total_size_bytes | BIGINT | NOT NULL, DEFAULT 0 | 鎬绘枃浠跺ぇ灏忥紙瀛楄妭锛?|
|
||
| created_at | TIMESTAMPTZ | NOT NULL, DEFAULT now() | 鍒涘缓鏃堕棿 |
|
||
| updated_at | TIMESTAMPTZ | NOT NULL | 鏇存柊鏃堕棿 |
|
||
|
||
#### Prisma Model
|
||
|
||
```prisma
|
||
model KnowledgeBase {
|
||
id String @id @default(uuid())
|
||
userId String @map("user_id")
|
||
name String
|
||
description String?
|
||
difyDatasetId String @map("dify_dataset_id")
|
||
fileCount Int @default(0) @map("file_count")
|
||
totalSizeBytes BigInt @default(0) @map("total_size_bytes")
|
||
|
||
createdAt DateTime @default(now()) @map("created_at")
|
||
updatedAt DateTime @updatedAt @map("updated_at")
|
||
|
||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||
documents Document[]
|
||
batchTasks BatchTask[]
|
||
|
||
@@index([userId])
|
||
@@index([difyDatasetId])
|
||
@@map("knowledge_bases")
|
||
@@schema("pkb_schema")
|
||
}
|
||
```
|
||
|
||
#### 涓氬姟瑙勫垯
|
||
|
||
1. **Dify缁戝畾** - 姣忎釜鐭ヨ瘑搴撳<E690B4>搴斿敮涓€鐨凞ify Dataset
|
||
2. **缁熻<E7BC81>瀛楁<E7809B>** - `file_count`鍜宍total_size_bytes`闇€瀹炴椂鏇存柊
|
||
3. **鐢ㄦ埛闅旂<E99785>** - 閫氳繃`user_id`瀹炵幇鏁版嵁闅旂<EFBFBD>
|
||
4. **绾ц仈鍒犻櫎** - 鍒犻櫎鐭ヨ瘑搴撴椂锛屾枃妗e拰浠诲姟涔熻<E6B694>鍒犻櫎
|
||
|
||
---
|
||
|
||
### 2. documents - 鏂囨。琛?
|
||
|
||
**鐢ㄩ€旓細** 瀛樺偍鐭ヨ瘑搴撲腑鐨勬枃妗d俊鎭?
|
||
|
||
#### 琛ㄧ粨鏋?
|
||
|
||
| 瀛楁<E7809B>鍚?| 鏁版嵁绫诲瀷 | 绾︽潫 | 璇存槑 |
|
||
|--------|---------|------|------|
|
||
| id | TEXT | PRIMARY KEY | 鏂囨。鍞<E38082>竴鏍囪瘑锛圲UID锛?|
|
||
| kb_id | TEXT | NOT NULL, FK | 鎵€灞炵煡璇嗗簱ID |
|
||
| user_id | TEXT | NOT NULL, FK | 鎵€灞炵敤鎴稩D |
|
||
| filename | TEXT | NOT NULL | 鏂囦欢鍚?|
|
||
| file_type | TEXT | NOT NULL | 鏂囦欢绫诲瀷锛坧df/doc/txt绛夛級 |
|
||
| file_size_bytes | BIGINT | NOT NULL | 鏂囦欢澶у皬锛堝瓧鑺傦級 |
|
||
| file_url | TEXT | NOT NULL | 鏂囦欢瀛樺偍URL |
|
||
| dify_document_id | TEXT | NOT NULL | Dify骞冲彴鐨凞ocument ID |
|
||
| status | TEXT | NOT NULL, DEFAULT 'uploading' | 鐘舵€侊紙uploading/processing/completed/failed锛?|
|
||
| progress | INTEGER | NOT NULL, DEFAULT 0 | 澶勭悊杩涘害锛?-100锛?|
|
||
| error_message | TEXT | NULL | 閿欒<E996BF>淇℃伅 |
|
||
| segments_count | INTEGER | NULL | 鍒囩墖鏁伴噺 |
|
||
| tokens_count | INTEGER | NULL | Token鏁伴噺 |
|
||
| extraction_method | TEXT | NULL | 鎻愬彇鏂规硶锛坅uto/ocr/parse锛?|
|
||
| **Phase 2瀛楁<E7809B>** | | | **鍏ㄦ枃闃呰<E99783>鍔熻兘** |
|
||
| full_text | TEXT | NULL | 瀹屾暣鏂囨湰鍐呭<E98D90> |
|
||
| full_text_length | INTEGER | NULL | 鏂囨湰闀垮害 |
|
||
| metadata | JSONB | NULL | 鍏冩暟鎹<E69A9F>紙浣滆€呫€佹爣棰樸€佹憳瑕佺瓑锛?|
|
||
| created_at | TIMESTAMPTZ | NOT NULL, DEFAULT now() | 鍒涘缓鏃堕棿 |
|
||
| updated_at | TIMESTAMPTZ | NOT NULL | 鏇存柊鏃堕棿 |
|
||
|
||
#### Prisma Model
|
||
|
||
```prisma
|
||
model Document {
|
||
id String @id @default(uuid())
|
||
kbId String @map("kb_id")
|
||
userId String @map("user_id")
|
||
filename String
|
||
fileType String @map("file_type")
|
||
fileSizeBytes BigInt @map("file_size_bytes")
|
||
fileUrl String @map("file_url")
|
||
difyDocumentId String @map("dify_document_id")
|
||
status String @default("uploading")
|
||
progress Int @default(0)
|
||
errorMessage String? @map("error_message")
|
||
segmentsCount Int? @map("segments_count")
|
||
tokensCount Int? @map("tokens_count")
|
||
extractionMethod String? @map("extraction_method")
|
||
|
||
// Phase 2: 鍏ㄦ枃闃呰<E99783>鍔熻兘
|
||
fullText String? @map("full_text") @db.Text
|
||
fullTextLength Int? @map("full_text_length")
|
||
metadata Json?
|
||
|
||
createdAt DateTime @default(now()) @map("created_at")
|
||
updatedAt DateTime @updatedAt @map("updated_at")
|
||
|
||
knowledgeBase KnowledgeBase @relation(fields: [kbId], references: [id], onDelete: Cascade)
|
||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||
batchResults BatchResult[]
|
||
|
||
@@index([kbId])
|
||
@@index([userId])
|
||
@@index([status])
|
||
@@index([difyDocumentId])
|
||
@@index([extractionMethod])
|
||
@@map("documents")
|
||
@@schema("pkb_schema")
|
||
}
|
||
```
|
||
|
||
#### 涓氬姟瑙勫垯
|
||
|
||
1. **鐘舵€佹満** - `status`瀛楁<EFBFBD>绠$悊鏂囨。澶勭悊娴佺▼
|
||
- `uploading` 鈫?`processing` 鈫?`completed`
|
||
- 澶辫触鏃惰浆涓篳failed`
|
||
2. **Dify鍚屾<E98D9A>** - 姣忎釜鏂囨。瀵瑰簲Dify涓<79>殑涓€涓狣ocument
|
||
3. **鎻愬彇鏂规硶** - 鏀<>寔鑷<E5AF94>姩璇嗗埆銆丱CR銆佽В鏋愪笁绉嶆柟寮?
|
||
4. **Phase 2鎵╁睍** - `full_text`瀛楁<EFBFBD>鐢ㄤ簬鍏ㄦ枃闃呰<EFBFBD>鍜屾繁搴﹀垎鏋?
|
||
|
||
---
|
||
|
||
### 3. batch_tasks - 鎵瑰<E98EB5>鐞嗕换鍔¤〃 (Phase 3)
|
||
|
||
**鐢ㄩ€旓細** 鎵归噺澶勭悊鏂囩尞锛屾彁鍙栫粨鏋勫寲淇℃伅
|
||
|
||
#### 琛ㄧ粨鏋?
|
||
|
||
| 瀛楁<E7809B>鍚?| 鏁版嵁绫诲瀷 | 绾︽潫 | 璇存槑 |
|
||
|--------|---------|------|------|
|
||
| id | TEXT | PRIMARY KEY | 浠诲姟鍞<E5A79F>竴鏍囪瘑锛圲UID锛?|
|
||
| user_id | TEXT | NOT NULL, FK | 鎵€灞炵敤鎴稩D |
|
||
| kb_id | TEXT | NOT NULL, FK | 鎵€灞炵煡璇嗗簱ID |
|
||
| task_name | TEXT | NOT NULL | 浠诲姟鍚嶇О |
|
||
| task_type | TEXT | NOT NULL | 浠诲姟绫诲瀷锛坋xtract_info/summarize绛夛級 |
|
||
| prompt_template | TEXT | NOT NULL | Prompt妯℃澘 |
|
||
| model_name | TEXT | NOT NULL, DEFAULT 'gpt-4' | 浣跨敤鐨凩LM妯″瀷 |
|
||
| status | TEXT | NOT NULL, DEFAULT 'pending' | 鐘舵€侊紙pending/running/completed/failed锛?|
|
||
| total_documents | INTEGER | NOT NULL, DEFAULT 0 | 鎬绘枃妗f暟 |
|
||
| processed_count | INTEGER | NOT NULL, DEFAULT 0 | 宸插<E5AEB8>鐞嗘暟 |
|
||
| success_count | INTEGER | NOT NULL, DEFAULT 0 | 鎴愬姛鏁?|
|
||
| failed_count | INTEGER | NOT NULL, DEFAULT 0 | 澶辫触鏁?|
|
||
| error_message | TEXT | NULL | 閿欒<E996BF>淇℃伅 |
|
||
| created_at | TIMESTAMPTZ | NOT NULL, DEFAULT now() | 鍒涘缓鏃堕棿 |
|
||
| updated_at | TIMESTAMPTZ | NOT NULL | 鏇存柊鏃堕棿 |
|
||
|
||
#### Prisma Model
|
||
|
||
```prisma
|
||
model BatchTask {
|
||
id String @id @default(uuid())
|
||
userId String @map("user_id")
|
||
kbId String @map("kb_id")
|
||
taskName String @map("task_name")
|
||
taskType String @map("task_type")
|
||
promptTemplate String @map("prompt_template") @db.Text
|
||
modelName String @default("gpt-4") @map("model_name")
|
||
status String @default("pending")
|
||
totalDocuments Int @default(0) @map("total_documents")
|
||
processedCount Int @default(0) @map("processed_count")
|
||
successCount Int @default(0) @map("success_count")
|
||
failedCount Int @default(0) @map("failed_count")
|
||
errorMessage String? @map("error_message") @db.Text
|
||
|
||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||
knowledgeBase KnowledgeBase @relation(fields: [kbId], references: [id], onDelete: Cascade)
|
||
results BatchResult[]
|
||
|
||
createdAt DateTime @default(now()) @map("created_at")
|
||
updatedAt DateTime @updatedAt @map("updated_at")
|
||
|
||
@@index([userId])
|
||
@@index([kbId])
|
||
@@index([status])
|
||
@@index([createdAt])
|
||
@@map("batch_tasks")
|
||
@@schema("pkb_schema")
|
||
}
|
||
```
|
||
|
||
#### 涓氬姟瑙勫垯
|
||
|
||
1. **浠诲姟绫诲瀷** - 鏀<>寔澶氱<E6BEB6>鎵瑰<E98EB5>鐞嗙被鍨?
|
||
- `extract_info` - 鎻愬彇缁撴瀯鍖栦俊鎭?
|
||
- `summarize` - 鎵归噺鎽樿<E98EBD>
|
||
- `classify` - 鏂囩尞鍒嗙被
|
||
2. **鐘舵€佹満** - `status`绠$悊浠诲姟鎵ц<EFBFBD>鐘舵€?
|
||
3. **杩涘害璺熻釜** - 瀹炴椂鏇存柊璁℃暟鍣ㄥ瓧娈?
|
||
4. **妯″瀷閫夋嫨** - 鏀<>寔澶氱<E6BEB6>LLM妯″瀷
|
||
|
||
---
|
||
|
||
### 4. batch_results - 鎵瑰<E98EB5>鐞嗙粨鏋滆〃 (Phase 3)
|
||
|
||
**鐢ㄩ€旓細** 瀛樺偍鎵瑰<E98EB5>鐞嗕换鍔$殑姣忕瘒鏂囩尞缁撴灉
|
||
|
||
#### 琛ㄧ粨鏋?
|
||
|
||
| 瀛楁<E7809B>鍚?| 鏁版嵁绫诲瀷 | 绾︽潫 | 璇存槑 |
|
||
|--------|---------|------|------|
|
||
| id | TEXT | PRIMARY KEY | 缁撴灉鍞<E78189>竴鏍囪瘑锛圲UID锛?|
|
||
| task_id | TEXT | NOT NULL, FK | 鎵€灞炰换鍔<E68DA2>D |
|
||
| document_id | TEXT | NOT NULL, FK | 鎵€灞炴枃妗<E69E83>D |
|
||
| status | TEXT | NOT NULL, DEFAULT 'pending' | 鐘舵€侊紙pending/processing/completed/failed锛?|
|
||
| result_data | JSONB | NULL | 鎻愬彇鐨勭粨鏋勫寲鏁版嵁 |
|
||
| raw_output | TEXT | NULL | LLM鍘熷<E98D98>杈撳嚭 |
|
||
| tokens_used | INTEGER | NULL | 浣跨敤鐨凾oken鏁?|
|
||
| error_message | TEXT | NULL | 閿欒<E996BF>淇℃伅 |
|
||
| created_at | TIMESTAMPTZ | NOT NULL, DEFAULT now() | 鍒涘缓鏃堕棿 |
|
||
|
||
#### Prisma Model
|
||
|
||
```prisma
|
||
model BatchResult {
|
||
id String @id @default(uuid())
|
||
taskId String @map("task_id")
|
||
documentId String @map("document_id")
|
||
status String @default("pending")
|
||
resultData Json? @map("result_data")
|
||
rawOutput String? @map("raw_output") @db.Text
|
||
tokensUsed Int? @map("tokens_used")
|
||
errorMessage String? @map("error_message") @db.Text
|
||
|
||
task BatchTask @relation(fields: [taskId], references: [id], onDelete: Cascade)
|
||
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||
|
||
createdAt DateTime @default(now()) @map("created_at")
|
||
|
||
@@index([taskId])
|
||
@@index([documentId])
|
||
@@index([status])
|
||
@@map("batch_results")
|
||
@@schema("pkb_schema")
|
||
}
|
||
```
|
||
|
||
#### 涓氬姟瑙勫垯
|
||
|
||
1. **缁撴灉瀛樺偍** - `result_data`瀛樺偍JSON鏍煎紡鐨勭粨鏋勫寲鏁版嵁
|
||
2. **鍘熷<E98D98>杈撳嚭** - `raw_output`淇濈暀LLM鍘熷<EFBFBD>杈撳嚭锛屼究浜庤皟璇?
|
||
3. **Token缁熻<E7BC81>** - 璁板綍姣忕瘒鏂囩尞鐨凾oken娑堣€?
|
||
|
||
---
|
||
|
||
### 5. task_templates - 浠诲姟妯℃澘琛?(Phase 3, 鏆備笉瀹炵幇)
|
||
|
||
**鐢ㄩ€旓細** 瀛樺偍棰勫畾涔夌殑鎵瑰<E98EB5>鐞嗕换鍔℃ā鏉?
|
||
|
||
#### 琛ㄧ粨鏋?
|
||
|
||
| 瀛楁<E7809B>鍚?| 鏁版嵁绫诲瀷 | 绾︽潫 | 璇存槑 |
|
||
|--------|---------|------|------|
|
||
| id | TEXT | PRIMARY KEY | 妯℃澘鍞<E6BE98>竴鏍囪瘑锛圲UID锛?|
|
||
| user_id | TEXT | NOT NULL, FK | 鎵€灞炵敤鎴稩D |
|
||
| template_name | TEXT | NOT NULL | 妯℃澘鍚嶇О |
|
||
| task_type | TEXT | NOT NULL | 浠诲姟绫诲瀷 |
|
||
| prompt_template | TEXT | NOT NULL | Prompt妯℃澘 |
|
||
| output_fields | JSONB | NOT NULL, DEFAULT '{}' | 杈撳嚭瀛楁<E7809B>瀹氫箟 |
|
||
| model_name | TEXT | NOT NULL, DEFAULT 'gpt-4' | 榛樿<E6A69B>妯″瀷 |
|
||
| created_at | TIMESTAMPTZ | NOT NULL, DEFAULT now() | 鍒涘缓鏃堕棿 |
|
||
| updated_at | TIMESTAMPTZ | NOT NULL | 鏇存柊鏃堕棿 |
|
||
|
||
#### Prisma Model
|
||
|
||
```prisma
|
||
model TaskTemplate {
|
||
id String @id @default(uuid())
|
||
userId String @map("user_id")
|
||
templateName String @map("template_name")
|
||
taskType String @map("task_type")
|
||
promptTemplate String @map("prompt_template") @db.Text
|
||
outputFields Json @default("{}") @map("output_fields")
|
||
modelName String @default("gpt-4") @map("model_name")
|
||
|
||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||
|
||
createdAt DateTime @default(now()) @map("created_at")
|
||
updatedAt DateTime @updatedAt @map("updated_at")
|
||
|
||
@@index([userId])
|
||
@@map("task_templates")
|
||
@@schema("pkb_schema")
|
||
}
|
||
```
|
||
|
||
#### 涓氬姟瑙勫垯
|
||
|
||
1. **妯℃澘澶嶇敤** - 鐢ㄦ埛鍙<E59F9B>繚瀛樺父鐢ㄧ殑浠诲姟閰嶇疆
|
||
2. **瀛楁<E7809B>瀹氫箟** - `output_fields`瀹氫箟鏈熸湜鐨勮緭鍑虹粨鏋?
|
||
3. **鏆備笉瀹炵幇** - Phase 3棰勭暀锛屽悗缁<E68297>紑鍙?
|
||
|
||
---
|
||
|
||
## 琛ㄥ叧绯诲浘
|
||
|
||
```mermaid
|
||
erDiagram
|
||
PLATFORM_USERS ||--o{ KNOWLEDGE_BASES : "owns"
|
||
PLATFORM_USERS ||--o{ DOCUMENTS : "uploads"
|
||
PLATFORM_USERS ||--o{ BATCH_TASKS : "creates"
|
||
PLATFORM_USERS ||--o{ TASK_TEMPLATES : "defines"
|
||
|
||
KNOWLEDGE_BASES ||--o{ DOCUMENTS : "contains"
|
||
KNOWLEDGE_BASES ||--o{ BATCH_TASKS : "processes"
|
||
|
||
BATCH_TASKS ||--o{ BATCH_RESULTS : "generates"
|
||
DOCUMENTS ||--o{ BATCH_RESULTS : "analyzed_by"
|
||
|
||
PLATFORM_USERS {
|
||
text id PK
|
||
text email
|
||
text password
|
||
}
|
||
|
||
KNOWLEDGE_BASES {
|
||
text id PK
|
||
text user_id FK
|
||
text name
|
||
text dify_dataset_id
|
||
int file_count
|
||
bigint total_size_bytes
|
||
}
|
||
|
||
DOCUMENTS {
|
||
text id PK
|
||
text kb_id FK
|
||
text user_id FK
|
||
text filename
|
||
text file_type
|
||
text dify_document_id
|
||
text status
|
||
text full_text
|
||
jsonb metadata
|
||
}
|
||
|
||
BATCH_TASKS {
|
||
text id PK
|
||
text user_id FK
|
||
text kb_id FK
|
||
text task_name
|
||
text task_type
|
||
text status
|
||
int total_documents
|
||
int processed_count
|
||
}
|
||
|
||
BATCH_RESULTS {
|
||
text id PK
|
||
text task_id FK
|
||
text document_id FK
|
||
text status
|
||
jsonb result_data
|
||
text raw_output
|
||
}
|
||
|
||
TASK_TEMPLATES {
|
||
text id PK
|
||
text user_id FK
|
||
text template_name
|
||
text task_type
|
||
jsonb output_fields
|
||
}
|
||
```
|
||
|
||
### 璺⊿chema寮曠敤
|
||
|
||
**澶栭敭鍏崇郴锛?*
|
||
- `knowledge_bases.user_id` 鈫?`platform_schema.users.id`
|
||
- `documents.user_id` 鈫?`platform_schema.users.id`
|
||
- `batch_tasks.user_id` 鈫?`platform_schema.users.id`
|
||
- `task_templates.user_id` 鈫?`platform_schema.users.id`
|
||
|
||
**璇存槑锛?* Prisma鑷<61>姩澶勭悊璺⊿chema澶栭敭锛屽簲鐢ㄤ唬鐮佹棤闇€鍏冲績Schema鍓嶇紑
|
||
|
||
---
|
||
|
||
## 绱㈠紩璁捐<E79281>
|
||
|
||
### 涓婚敭绱㈠紩
|
||
鎵€鏈夎〃鐨刞id`瀛楁<E7809B>鑷<EFBFBD>姩鍒涘缓B-tree涓婚敭绱㈠紩銆?
|
||
|
||
### 澶栭敭绱㈠紩
|
||
|
||
| 琛ㄥ悕 | 绱㈠紩瀛楁<E7809B> | 鐢ㄩ€?|
|
||
|------|---------|------|
|
||
| knowledge_bases | user_id | 鏌ヨ<E98F8C>鐢ㄦ埛鐨勬墍鏈夌煡璇嗗簱 |
|
||
| knowledge_bases | dify_dataset_id | Dify鏁版嵁鍚屾<E98D9A> |
|
||
| documents | kb_id | 鏌ヨ<E98F8C>鐭ヨ瘑搴撶殑鎵€鏈夋枃妗?|
|
||
| documents | user_id | 鏌ヨ<E98F8C>鐢ㄦ埛鐨勬墍鏈夋枃妗?|
|
||
| documents | status | 杩囨护鏂囨。鐘舵€?|
|
||
| documents | dify_document_id | Dify鏁版嵁鍚屾<E98D9A> |
|
||
| documents | extraction_method | 鎸夋彁鍙栨柟娉曡繃婊?|
|
||
| batch_tasks | user_id | 鏌ヨ<E98F8C>鐢ㄦ埛鐨勪换鍔?|
|
||
| batch_tasks | kb_id | 鏌ヨ<E98F8C>鐭ヨ瘑搴撶殑浠诲姟 |
|
||
| batch_tasks | status | 杩囨护浠诲姟鐘舵€?|
|
||
| batch_results | task_id | 鏌ヨ<E98F8C>浠诲姟鐨勬墍鏈夌粨鏋?|
|
||
| batch_results | document_id | 鏌ヨ<E98F8C>鏂囨。鐨勫<E990A8>鐞嗙粨鏋?|
|
||
| batch_results | status | 杩囨护缁撴灉鐘舵€?|
|
||
| task_templates | user_id | 鏌ヨ<E98F8C>鐢ㄦ埛鐨勬ā鏉?|
|
||
|
||
### 鏃堕棿绱㈠紩
|
||
|
||
| 琛ㄥ悕 | 绱㈠紩瀛楁<E7809B> | 鐢ㄩ€?|
|
||
|------|---------|------|
|
||
| batch_tasks | created_at | 鎸夋椂闂存帓搴忎换鍔?|
|
||
|
||
---
|
||
|
||
## Phase 3鍔熻兘璇存槑
|
||
|
||
### 鎵瑰<E98EB5>鐞嗗伐浣滄祦绋?
|
||
|
||
```mermaid
|
||
sequenceDiagram
|
||
participant User
|
||
participant API
|
||
participant BatchTask
|
||
participant Document
|
||
participant LLM
|
||
participant BatchResult
|
||
|
||
User->>API: 鍒涘缓鎵瑰<E98EB5>鐞嗕换鍔?
|
||
API->>BatchTask: 鍒涘缓浠诲姟璁板綍
|
||
API->>Document: 鏌ヨ<E98F8C>鐭ヨ瘑搴撴枃妗e垪琛?
|
||
|
||
loop 姣忕瘒鏂囨。
|
||
BatchTask->>Document: 璇诲彇鏂囨。鍏ㄦ枃
|
||
BatchTask->>LLM: 璋冪敤LLM鎻愬彇淇℃伅
|
||
LLM-->>BatchTask: 杩斿洖缁撴瀯鍖栨暟鎹?
|
||
BatchTask->>BatchResult: 淇濆瓨缁撴灉
|
||
BatchTask->>BatchTask: 鏇存柊杩涘害
|
||
end
|
||
|
||
BatchTask->>API: 浠诲姟瀹屾垚
|
||
API-->>User: 杩斿洖缁撴灉姹囨€?
|
||
```
|
||
|
||
### 鎵瑰<E98EB5>鐞嗕换鍔$被鍨嬬ず渚?
|
||
|
||
1. **淇℃伅鎻愬彇** (`extract_info`)
|
||
- 鎻愬彇鐮旂┒鏂规硶銆佹牱鏈<E789B1>噺銆丳鍊肩瓑
|
||
- 杈撳嚭JSON鏍煎紡鐨勭粨鏋勫寲鏁版嵁
|
||
|
||
2. **鏂囩尞鎽樿<E98EBD>** (`summarize`)
|
||
- 鎵归噺鐢熸垚鏂囩尞鎽樿<E98EBD>
|
||
- 缁熶竴鏍煎紡鍜岄暱搴?
|
||
|
||
3. **鏂囩尞鍒嗙被** (`classify`)
|
||
- 鏍规嵁鐮旂┒绫诲瀷鍒嗙被
|
||
- 鏍囩<E98F8D>鍖栫<E98D96>鐞?
|
||
|
||
---
|
||
|
||
## 鍙樻洿鍘嗗彶
|
||
|
||
### v1.0 - 2025-11-12 - 鍒濆<E98D92>鐗堟湰 鉁?
|
||
|
||
**鍙樻洿鍐呭<E98D90>锛?*
|
||
1. 浠巂public` schema杩佺Щ鍒癭pkb_schema`
|
||
2. 5涓<35>〃鍏ㄩ儴杩佺Щ锛?
|
||
- knowledge_bases
|
||
- documents
|
||
- batch_tasks
|
||
- batch_results
|
||
- task_templates
|
||
3. 鍦≒risma涓<61>坊鍔燻@@schema("pkb_schema")`鏍囩<EFBFBD>
|
||
4. 鎵€鏈夋暟鎹?00%瀹屾暣杩佺Щ
|
||
|
||
**杩佺Щ鑴氭湰锛?* `docs/09-鏋舵瀯瀹炴柦/migration-scripts/004-migrate-pkb.sql`
|
||
|
||
**楠岃瘉鐘舵€侊細** 鉁?宸查獙璇侊紝鍔熻兘姝e父
|
||
|
||
**鐗规畩澶勭悊锛?*
|
||
- `batch_results.rawOutput` 鈫?`raw_output`锛堝垪鍚嶆槧灏勪慨姝o級
|
||
- `task_templates.outputFields` 鈫?`output_fields`锛堝垪鍚嶆槧灏勪慨姝o級
|
||
|
||
---
|
||
|
||
## 馃摎 鐩稿叧鏂囨。
|
||
|
||
- [Schema闅旂<EFBFBD>鏋舵瀯璁捐<EFBFBD>](../../../09-鏋舵瀯瀹炴柦/01-Schema闅旂<E99785>鏋舵瀯璁捐<E79281>锛?0涓<30>級.md)
|
||
- [Schema杩佺Щ瀹屾垚鎶ュ憡](../../../09-鏋舵瀯瀹炴柦/Schema杩佺Щ瀹屾垚鎶ュ憡.md)
|
||
- [Prisma閰嶇疆瀹屾垚鎶ュ憡](../../../09-鏋舵瀯瀹炴柦/Prisma閰嶇疆瀹屾垚鎶ュ憡.md)
|
||
- [蹇<>€熷姛鑳芥祴璇曟姤鍛奭(../../../09-鏋舵瀯瀹炴柦/蹇<>€熷姛鑳芥祴璇曟姤鍛?md)
|
||
- [AIA鏁版嵁搴撹<E690B4>璁℃枃妗<E69E83>(../../AIA-AI鏅鸿兘闂<E58598>瓟/02-鎶€鏈<E282AC><E98F88>璁?01-鏁版嵁搴撹<E690B4>璁?md)
|
||
|
||
---
|
||
|
||
**鏂囨。缁存姢鑰咃細** AI鍔╂墜
|
||
**鏈€鍚庢洿鏂帮細** 2025-11-12
|
||
**鏂囨。鐘舵€侊細** 鉁?宸插畬鎴愬苟楠岃瘉
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|