86 lines
1.5 KiB
Markdown
86 lines
1.5 KiB
Markdown
# AI Assistant Java (Spring AI + pgvector)
|
||
|
||
基于 RAG(检索增强生成)的仓配中心 AI 助手服务,提供 OpenAI 兼容 API。
|
||
|
||
## 技术栈
|
||
|
||
- Java 17 + Spring Boot 3.2
|
||
- Spring AI + Ollama
|
||
- PostgreSQL + pgvector
|
||
- MyBatis-Plus
|
||
|
||
## 快速启动
|
||
|
||
### 1. 启动 pgvector
|
||
|
||
```bash
|
||
docker run --name pgvector -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=assistant \
|
||
-p 5432:5432 -d pgvector/pgvector:pg16
|
||
```
|
||
|
||
### 2. 启动 Ollama 模型
|
||
|
||
```bash
|
||
ollama pull qwen2.5:7b # 对话模型
|
||
ollama pull bge-m3 # Embedding 模型
|
||
```
|
||
|
||
### 3. 启动服务
|
||
|
||
```bash
|
||
./mvnw spring-boot:run
|
||
```
|
||
|
||
## API 接口
|
||
|
||
### 知识录入
|
||
|
||
```bash
|
||
POST http://localhost:8010/ingest
|
||
|
||
{
|
||
"domain_id": "general",
|
||
"content": "SKU A001 是一款高端电子产品,库存预警阈值为100件"
|
||
}
|
||
```
|
||
|
||
### 智能问答 (OpenAI 兼容)
|
||
|
||
```bash
|
||
POST http://localhost:8010/v1/chat/completions
|
||
|
||
{
|
||
"model": "qwen2.5:7b",
|
||
"stream": true,
|
||
"messages": [
|
||
{"role": "user", "content": "SKU A001 的库存预警阈值是多少?"}
|
||
]
|
||
}
|
||
```
|
||
|
||
## 配置说明
|
||
|
||
`src/main/resources/application.yml`:
|
||
|
||
```yaml
|
||
assistant:
|
||
routing:
|
||
use-llm: true # 是否使用 LLM 进行域路由
|
||
fallback-domain: general # 默认域
|
||
vector:
|
||
table: assistant_vectors # 向量表名
|
||
dimension: 1024 # Embedding 维度
|
||
domains:
|
||
- id: general
|
||
name: 通用知识
|
||
keywords: []
|
||
```
|
||
|
||
## 架构
|
||
|
||
```
|
||
用户问题 → 域路由 → 相似度搜索(RAG) → LLM 生成回答
|
||
↓
|
||
向量知识库 (pgvector)
|
||
```
|