This commit is contained in:
kazusa 2026-01-07 20:40:24 +08:00
parent fffa431dde
commit a0d38019c4
1 changed files with 59 additions and 27 deletions

View File

@ -1,53 +1,85 @@
# AI Assistant Java (Spring AI + pgvector)
This module is an independent Spring Boot 3 service that provides an OpenAI-compatible API.
基于 RAG检索增强生成的仓配中心 AI 助手服务,提供 OpenAI 兼容 API。
## Requirements
## 技术栈
- Java 17+
- PostgreSQL with pgvector
- Ollama (local inference)
- Java 17 + Spring Boot 3.2
- Spring AI + Ollama
- PostgreSQL + pgvector
- MyBatis-Plus
## Start pgvector (Docker)
## 快速启动
```
### 1. 启动 pgvector
```bash
docker run --name pgvector -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=assistant \
-p 5432:5432 -d pgvector/pgvector:pg16
```
## Start Ollama models
### 2. 启动 Ollama 模型
```
ollama pull qwen2.5:7b
ollama pull bge-m3
```bash
ollama pull qwen2.5:7b # 对话模型
ollama pull bge-m3 # Embedding 模型
```
## Configure
### 3. 启动服务
- `src/main/resources/application.yml`
- `src/main/resources/domains.yml`
## Run
```
```bash
./mvnw spring-boot:run
```
## OpenAI-compatible endpoint
## API 接口
```
POST http://127.0.0.1:8010/v1/chat/completions
```
### 知识录入
Sample payload:
```bash
POST http://localhost:8010/ingest
```
{
"model": "local",
"tenant_id": "customer_a",
"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": "订单有多少?"}
{"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)
```