- 新增 routing_config.py 路由配置模型 - StrategyType: DEFAULT/ENHANCED 策略类型 - RagRuntimeMode: DIRECT/REACT/AUTO 运行模式 - RoutingConfig: 路由配置类 - StrategyContext: 策略上下文 - StrategyResult: 策略结果 - 新增 strategy_router.py 策略路由器 - RollbackManager: 回滚管理器 - DefaultPipeline: 默认检索管道 - EnhancedPipeline: 增强检索管道 - StrategyRouter: 策略路由器 - 新增 mode_router.py 模式路由器 - ComplexityAnalyzer: 复杂度分析器 - ModeRouter: 模式路由器 - 新增 strategy_integration.py 统一集成层 - RetrievalStrategyIntegration: 策略集成器 - 更新 __init__.py 导出新模块 |
||
|---|---|---|
| .. | ||
| app | ||
| docs/progress | ||
| exports | ||
| migrations | ||
| scripts | ||
| tests | ||
| tools | ||
| .dockerignore | ||
| Dockerfile | ||
| README.md | ||
| check_kb_collections.py | ||
| check_qdrant.py | ||
| pyproject.toml | ||
| test_kb_metadata_search.py | ||
| test_kb_search_with_metadata.py | ||
| test_metadata_filter_only.py | ||
README.md
AI Service
Python AI Service for intelligent chat with RAG support.
Features
- Multi-tenant isolation via X-Tenant-Id header
- SSE streaming support via Accept: text/event-stream
- RAG-powered responses with confidence scoring
Prerequisites
- PostgreSQL 12+
- Qdrant vector database
- Python 3.10+
Installation
pip install -e ".[dev]"
Database Initialization
Option 1: Using Python script (Recommended)
# Create database and tables
python scripts/init_db.py --create-db
# Or just create tables (database must exist)
python scripts/init_db.py
Option 2: Using SQL script
# Connect to PostgreSQL and run
psql -U postgres -f scripts/init_db.sql
Configuration
Create a .env file in the project root:
AI_SERVICE_DATABASE_URL=postgresql+asyncpg://postgres:password@localhost:5432/ai_service
AI_SERVICE_QDRANT_URL=http://localhost:6333
AI_SERVICE_LLM_API_KEY=your-api-key
AI_SERVICE_LLM_BASE_URL=https://api.openai.com/v1
AI_SERVICE_LLM_MODEL=gpt-4o-mini
AI_SERVICE_DEBUG=true
Running
uvicorn app.main:app --host 0.0.0.0 --port 8000
API Endpoints
Chat API
POST /ai/chat- Generate AI reply (supports SSE streaming)GET /ai/health- Health check
Admin API
GET /admin/kb/documents- List documentsPOST /admin/kb/documents- Upload documentGET /admin/kb/index/jobs/{jobId}- Get indexing job statusDELETE /admin/kb/documents/{docId}- Delete documentPOST /admin/rag/experiments/run- Run RAG experimentGET /admin/sessions- List chat sessionsGET /admin/sessions/{sessionId}- Get session details