art
This commit is contained in:
parent
fffa431dde
commit
a0d38019c4
86
README.md
86
README.md
|
|
@ -1,53 +1,85 @@
|
||||||
# AI Assistant Java (Spring AI + pgvector)
|
# 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+
|
- Java 17 + Spring Boot 3.2
|
||||||
- PostgreSQL with pgvector
|
- Spring AI + Ollama
|
||||||
- Ollama (local inference)
|
- PostgreSQL + pgvector
|
||||||
|
- MyBatis-Plus
|
||||||
|
|
||||||
## Start pgvector (Docker)
|
## 快速启动
|
||||||
|
|
||||||
```
|
### 1. 启动 pgvector
|
||||||
|
|
||||||
|
```bash
|
||||||
docker run --name pgvector -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=assistant \
|
docker run --name pgvector -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=assistant \
|
||||||
-p 5432:5432 -d pgvector/pgvector:pg16
|
-p 5432:5432 -d pgvector/pgvector:pg16
|
||||||
```
|
```
|
||||||
|
|
||||||
## Start Ollama models
|
### 2. 启动 Ollama 模型
|
||||||
|
|
||||||
```
|
```bash
|
||||||
ollama pull qwen2.5:7b
|
ollama pull qwen2.5:7b # 对话模型
|
||||||
ollama pull bge-m3
|
ollama pull bge-m3 # Embedding 模型
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configure
|
### 3. 启动服务
|
||||||
|
|
||||||
- `src/main/resources/application.yml`
|
```bash
|
||||||
- `src/main/resources/domains.yml`
|
|
||||||
|
|
||||||
## Run
|
|
||||||
|
|
||||||
```
|
|
||||||
./mvnw spring-boot:run
|
./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",
|
"domain_id": "general",
|
||||||
"tenant_id": "customer_a",
|
"content": "SKU A001 是一款高端电子产品,库存预警阈值为100件"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 智能问答 (OpenAI 兼容)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
POST http://localhost:8010/v1/chat/completions
|
||||||
|
|
||||||
|
{
|
||||||
|
"model": "qwen2.5:7b",
|
||||||
"stream": true,
|
"stream": true,
|
||||||
"messages": [
|
"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)
|
||||||
|
```
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue