Files
AIclinicalresearch/backend/test-pkb-migration.http
HaHafeng 40c2f8e148 feat(rag): Complete RAG engine implementation with pgvector
Major Features:
- Created ekb_schema (13th schema) with 3 tables: KB/Document/Chunk
- Implemented EmbeddingService (text-embedding-v4, 1024-dim vectors)
- Implemented ChunkService (smart Markdown chunking)
- Implemented VectorSearchService (multi-query + hybrid search)
- Implemented RerankService (qwen3-rerank)
- Integrated DeepSeek V3 QueryRewriter for cross-language search
- Python service: Added pymupdf4llm for PDF-to-Markdown conversion
- PKB: Dual-mode adapter (pgvector/dify/hybrid)

Architecture:
- Brain-Hand Model: Business layer (DeepSeek) + Engine layer (pgvector)
- Cross-language support: Chinese query matches English documents
- Small Embedding (1024) + Strong Reranker strategy

Performance:
- End-to-end latency: 2.5s
- Cost per query: 0.0025 RMB
- Accuracy improvement: +20.5% (cross-language)

Tests:
- test-embedding-service.ts: Vector embedding verified
- test-rag-e2e.ts: Full pipeline tested
- test-rerank.ts: Rerank quality validated
- test-query-rewrite.ts: Cross-language search verified
- test-pdf-ingest.ts: Real PDF document tested (Dongen 2003.pdf)

Documentation:
- Added 05-RAG-Engine-User-Guide.md
- Added 02-Document-Processing-User-Guide.md
- Updated system status documentation

Status: Production ready
2026-01-21 20:24:29 +08:00

181 lines
4.8 KiB
HTTP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
###
# PKB - API
# v1v2<EFBFBD>?
###
@baseUrl = http://localhost:3000
@userId = user-mock-001
### ============================================
### 3.1: <EFBFBD>?
### ============================================
### 1. PKB v2<EFBFBD>?
GET {{baseUrl}}/api/v1/pkb/health
Accept: application/json
### ============================================
### 3.2: CRUD
### ============================================
### 2. v1<EFBFBD>?
GET {{baseUrl}}/api/v1/knowledge-bases
Accept: application/json
### 3. v2<EFBFBD>?
GET {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases
Accept: application/json
### 4. v2<EFBFBD>?
POST {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases
Content-Type: application/json
{
"name": "v2-{{$timestamp}}",
"description": "v2 API"
}
### 5. v1 - <EFBFBD>?
POST {{baseUrl}}/api/v1/knowledge-bases
Content-Type: application/json
{
"name": "v1-{{$timestamp}}",
"description": "v1 API"
}
### 6. v2<EFBFBD>?
# ID
@kbId = f6ebe476-c50f-4222-83d2-c2525edc6054
GET {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases/{{kbId}}
Accept: application/json
### 7. v1 - <EFBFBD>?
GET {{baseUrl}}/api/v1/knowledge-bases/{{kbId}}
Accept: application/json
### 8. v2<EFBFBD>?
PUT {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases/{{kbId}}
Content-Type: application/json
{
"name": "v2",
"description": "v2 API<EFBFBD>?
}
### 9. v2<EFBFBD>?
GET {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases/{{kbId}}/stats
Accept: application/json
### 10. v1 - <EFBFBD>?
GET {{baseUrl}}/api/v1/knowledge-bases/{{kbId}}/stats
Accept: application/json
### ============================================
### 3.3: RAG<EFBFBD>?
### ============================================
### 11. RAGv2<EFBFBD>?
GET {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases/{{kbId}}/search?query=<EFBFBD>?top_k=5
Accept: application/json
### 12. RAGv1 - <EFBFBD>?
GET {{baseUrl}}/api/v1/knowledge-bases/{{kbId}}/search?query=<EFBFBD>?top_k=5
Accept: application/json
### ============================================
### 3.4:
### ============================================
### 13. v2<EFBFBD>?
GET {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases/{{kbId}}/document-selection?max_files=7&max_tokens=750000
Accept: application/json
### 14. v1 - <EFBFBD>?
GET {{baseUrl}}/api/v1/knowledge-bases/{{kbId}}/document-selection?max_files=7&max_tokens=750000
Accept: application/json
### ============================================
### 3.5:
### ============================================
### 15.
GET {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases/{{kbId}}
Accept: application/json
### 16. v2<EFBFBD>?
# ID
@docId = your-document-id
GET {{baseUrl}}/api/v1/pkb/knowledge/documents/{{docId}}
Accept: application/json
### ============================================
### 3.6: <EFBFBD>?
### ============================================
### 17. v2<EFBFBD>?
GET {{baseUrl}}/api/v1/pkb/batch-tasks/batch/templates
Accept: application/json
### 18. v2<EFBFBD>?
POST {{baseUrl}}/api/v1/pkb/batch-tasks/batch/execute
Content-Type: application/json
{
"kb_id": "{{kbId}}",
"document_ids": [],
"template_type": "preset",
"template_id": "clinical_research_method",
"model_type": "deepseek-v3",
"task_name": "v2"
}
### ============================================
### 3.7:
### ============================================
### 19. v2<EFBFBD>?
GET {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases/00000000-0000-0000-0000-000000000000
Accept: application/json
### 20. v2<EFBFBD>?
GET {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases/{{kbId}}/search?query=&top_k=0
Accept: application/json
### 21. top_kv2<EFBFBD>?
GET {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases/{{kbId}}/search?query=&top_k=1000
Accept: application/json
### ============================================
### 3.8:
### ============================================
### 22. v2<EFBFBD>?
# @testKbId = ID
DELETE {{baseUrl}}/api/v1/pkb/knowledge/knowledge-bases/{{testKbId}}
###