14 - 配置与基础设施
一、配置文件
主配置文件:src/main/resources/application.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| server: port: 9999 servlet: encoding: charset: UTF-8 force: true enabled: true
spring: ai: openai: api-key: @dashscope.api.key@ base-url: https://dashscope.aliyuncs.com/compatible-mode/ chat: options: model: qwen-plus temperature: 0.7
embedding: base-url: https://dashscope.aliyuncs.com/compatible-mode/ api-key: @dashscope.api.key@ options: model: text-embedding-v4 dimmension: 1024
datasource: url: jdbc:mysql://127.0.0.1:3306/dodo?... username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver hikari: minimum-idle: 5 maximum-pool-size: 20 idle-timeout: 60000 connection-timeout: 30000 max-lifetime: 1800000
data: redis: host: localhost port: 6389 database: 0 timeout: 5s
mybatis-plus: mapper-locations: classpath:mapper/*.xml
servlet: multipart: enabled: true max-file-size: 50MB max-request-size: 50MB
minio: url: http://localhost:19000/ accessKey: minioadmin secretKey: minioadmin bucketName: rag-test2 endpoint: http://localhost:19000/
embeddings: store: host: localhost port: 5433 database: vector_store user: postgres password: postgres
tavily: api-key: tvly-dev-xxxxxx mcp-url: https://mcp.tavily.com/mcp/
grsai: nanobanana: api-key: sk-xxxxxx
logging: level: org: springframework: ai: INFO io: modelcontextprotocol: client: ERROR
skills: directory: C:\Users\Lenovo\.claude\skills
|
二、配置类(config/)
2.1 VectorStoreConfig
config/VectorStoreConfig.java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| @Configuration public class VectorStoreConfig {
@Bean(name = "pgVectorDataSource") public DataSource pgVectorDataSource( @Value("${embeddings.store.host}") String host, @Value("${embeddings.store.port}") String port, @Value("${embeddings.store.database}") String database, @Value("${embeddings.store.user}") String user, @Value("${embeddings.store.password}") String password) { HikariDataSource ds = new HikariDataSource(); ds.setJdbcUrl("jdbc:postgresql://" + host + ":" + port + "/" + database); ds.setUsername(user); ds.setPassword(password); ds.setDriverClassName("org.postgresql.Driver"); ds.setMaximumPoolSize(50); ds.setMinimumIdle(5); ds.setPoolName("PgVectorPool"); return ds; } }
|
说明:
- 自定义连接池名称
PgVectorPool - 池大小 50,最小空闲 5
- 与 MySQL DataSource 隔离
2.2 RedisConfig
config/RedisConfig.java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| @Configuration public class RedisConfig {
@Bean public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) { RedisTemplate<String, String> template = new RedisTemplate<>(); template.setConnectionFactory(factory); StringRedisSerializer stringSerializer = new StringRedisSerializer(); template.setKeySerializer(stringSerializer); template.setValueSerializer(stringSerializer); template.setHashKeySerializer(stringSerializer); template.setHashValueSerializer(stringSerializer); template.afterPropertiesSet(); return template; } }
|
说明:
- 全部使用 String 序列化(与 Redisson 兼容)
- Key/Value/Hash Key/Hash Value 都用 StringRedisSerializer
2.3 CorsConfig
1 2 3 4 5
| @Configuration public class CorsConfig { }
|
2.4 MinioClientConfiguration
config/MinioClientConfiguration.java:
1 2 3 4 5 6 7 8 9 10 11 12 13
| @Configuration public class MinioClientConfiguration { @Bean public MinioClient minioClient( @Value("${minio.url}") String url, @Value("${minio.accessKey}") String accessKey, @Value("${minio.secretKey}") String secretKey) { return MinioClient.builder() .endpoint(url) .credentials(accessKey, secretKey) .build(); } }
|
2.5 MySQLDataSourceConfig
config/MySQLDataSourceConfig.java 配置 MySQL + MyBatis-Plus。
三、基础设施依赖
3.1 关系数据库:MySQL
用途:
ai_session - 会话记录ai_file_info - 文件元数据ai_ppt_inst - PPT 实例ai_ppt_template - PPT 模板
连接池:HikariCP(Spring Boot 默认)
3.2 向量数据库:PostgreSQL + pgvector
用途:存储文档向量(1024 维)
Schema(自动创建):
1 2 3 4 5 6 7 8 9
| CREATE TABLE vector_file_info ( id UUID PRIMARY KEY, content TEXT, metadata JSON, embedding VECTOR(1024) );
CREATE INDEX vector_file_info_idx ON vector_file_info USING hnsw (embedding vector_cosine_ops);
|
3.3 对象存储:MinIO
Bucket 命名:rag-test2(可配置)
目录结构:
1 2 3 4 5 6
| rag-test2/ ├── file-{fileId}.{ext} # 原始文件 ├── ppt/{conversationId}/ │ ├── images/{ts}_{idx}.png # PPT 配图 │ └── {ts}.pptx # 生成的 PPT └── ...
|
访问策略:公共读(PUBLIC_READ)
3.4 缓存与 Pub/Sub:Redis
用途:
agent:task:{conversationId} - 任务注册- Topic
agent:stop - 停止广播
客户端:Redisson(用于分布式锁和 Pub/Sub)
3.5 搜索引擎:Tavily
MCP 端点:https://mcp.tavily.com/mcp/
鉴权:Bearer Token
超时:5 分钟
四、外部服务集成
4.1 大模型:通义千问(DashScope)
兼容 OpenAI API:
- Base URL:
https://dashscope.aliyuncs.com/compatible-mode/ - 模型:
qwen-plus(对话) / qwen3-vl-plus(多模态)
嵌入模型:
- 模型:
text-embedding-v4 - 维度:1024
多模态模型(图片识别):
- 模型:
qwen3-vl-plus - 用于
FileManageService.image2Text()
4.2 MCP 工具:Tavily
详见 04 WebSearch 智能体
4.3 图片生成:grsai / nanobanana
utils/ImageGenerationService.java 调用外部图片生成服务:
1 2 3 4 5 6 7 8 9 10
| @Service public class ImageGenerationService {
@Value("${grsai.nanobanana.api-key}") private String apiKey;
public String generateImage(String prompt) { } }
|
配置:
1 2 3
| grsai: nanobanana: api-key: sk-xxxxxx
|
使用场景:
- PPT 配图(
SchemaStrategy.processImageGeneration) - 其他需要 AI 生成图片的功能
4.4 Python PPT 渲染服务
service/PptPythonRenderService.java 调用外部 Python 服务:
1 2 3
| public interface PptPythonRenderService { String renderPpt(AiPptInst inst, String pptSchemaJson); }
|
实现:service/impl/PptPythonRenderServiceImpl.java
功能:
- 接收 PPT Schema JSON
- 调用 Python-pptx 渲染为 PPTX 文件
- 上传到 MinIO
- 返回文件 URL
五、端口与端点
| 组件 | 端口 | 说明 |
|---|
| Dodo-Agent | 9999 | 主服务 |
| MySQL | 3306 | 数据库 |
| Redis | 6389 | 缓存/Pub-Sub |
| MinIO | 19000 | 对象存储 |
| PostgreSQL | 5433 | 向量库 |
| Python PPT 渲染 | - | 独立服务 |
六、启动顺序
- MySQL - 启动数据库
- PostgreSQL + pgvector - 启动向量库
- Redis - 启动缓存
- MinIO - 启动对象存储
- Dodo-Agent - 启动应用
- Python PPT 渲染服务(可选)
七、健康检查
Endpoint:/actuator/health(如启用 actuator)
检查项:
- MySQL 连接
- Redis 连接
- MinIO 连接
- PgVector 连接
八、监控与日志
日志框架:SLF4J + Logback(Spring Boot 默认)
日志级别:
org.springframework.ai: INFOio.modelcontextprotocol.client: ERROR
关键日志:
AgentController - 收到请求 / 初始化 AgentBaseAgent - 工具调用 / 状态变更AgentTaskManager - 任务注册 / 停止FileManageService - 文件上传 / 解析 / 向量化EmbeddingService - RAG 检索PPTBuilderAgent - 状态机流转
九、扩展方向
- 配置中心:集成 Nacos / Apollo
- 链路追踪:集成 SkyWalking / Zipkin
- 监控指标:暴露 Micrometer 指标
- 多环境:dev / staging / prod 配置文件
- 密钥管理:集成 Vault