# 易智Spring
**Repository Path**: wb04307201/easy-ai-spring-boot-starter
## Basic Information
- **Project Name**: 易智Spring
- **Description**: 这不是一个AI大模型,但是可以帮你快速集成AI大模型到Spring项目中,并通过“检索增强生成(RAG)”的方式建立专家知识库帮助大模型回答问题。
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 29
- **Forks**: 8
- **Created**: 2024-05-28
- **Last Updated**: 2025-08-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: llm, RAG, SpringAI, AI
## README
# easy-ai-spring-boot-starter
# 易智Spring
[](https://jitpack.io/#com.gitee.wb04307201/easy-ai-spring-boot-starter)
[](https://gitee.com/wb04307201/easy-ai-spring-boot-starter)
[](https://gitee.com/wb04307201/easy-ai-spring-boot-starter)
[](https://github.com/wb04307201/easy-ai-spring-boot-starter)
[](https://github.com/wb04307201/easy-ai-spring-boot-starter)
  
> 这不是一个AI大模型,但是可以帮你快速集成AI大模型到Spring项目中,
> 并通过“检索增强生成(RAG)”的方式建立专家知识库帮助大模型回答问题。
>
> 核心功能依赖于[Spring AI](https://docs.spring.io/spring-ai/reference/index.html)实现,RAG运行原理如下
> 
## 代码示例
1. 使用[易智Spring](https://gitee.com/wb04307201/easy-ai-spring-boot-starter)实现的[AI大模型Demo](https://gitee.com/wb04307201/easy-ai-demo)
## 快速开始
### 引入依赖
增加 JitPack 仓库
```xml
jitpack.io
https://jitpack.io
```
引入jar
```xml
com.github.wb04307201
easy-ai-spring-boot-starter
0.6.3
```
### 安装向量数据库
通过docker安装chromadb数据库
```shell
docker run -d --name chromadb -p 8000:8000 chromadb/chroma
```
### 安装大语言模型
默认通过[ollama](https://ollama.com/)使用大模型,下载并安装
```shell
# 拉取qwen2模型
ollama pull qwen2
# 拉取deepseek-r1模型
ollama pull deepseek-r1
```
### 添加相关配置
```yaml
spring:
application:
name: spring_ai_demo
ai:
ollama:
chat:
options:
# model: llama3
# model: qwen2/
model: deepseek-r1
embedding:
options:
model: qwen2
init:
pull-model-strategy: always
timeout: 60s
max-retries: 1
base-url: "http://localhost:11434"
vectorstore:
chroma:
client:
host: http://localhost
port: 8000
collection-name: SpringAiCollection
initialize-schema: true
easy:
defaultSystem:
enableRag: true
userTextAdvise: \n上下文信息如下,用---------------------包围\n\n---------------------\n{question_answer_context}\n---------------------\n\n基于上下文和提供的历史信息(而非先验知识),回复用户评论。如果答案不在上下文中,请告知用户无法回答这个问题。\n
fileStorageServiceClass: cn.wubo.easy.ai.document.impl.LocalDocumentStorageServiceImpl
fileStorageRecordClass: cn.wubo.easy.ai.document.impl.MemDocumentStorageRecordImpl
enableWeb: true
enableRest: true
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
```
### 在启动类上加上`@EnableEasyAi`注解
```java
@EnableEasyAi
@SpringBootApplication
public class EasyAiDemoApplication {
public static void main(String[] args) {
SpringApplication.run(EasyAiDemoApplication.class, args);
}
}
```
### 使用检索增强生成(RAG)辅助对话
当未上传知识库时

显然开始胡说八道了
现在让我们上传一些知识库,访问文档上传界面http://ip:端口/easy/ai/list

状态列显示“向量存储完”即文档已转入知识库
访问聊天界面http://ip:端口/easy/ai/chat

## 高级
### 使用其他大模型API
这里以[智谱AI](https://open.bigmodel.cn/)为例,如何对接大模型API
修改项目依赖,支持的大模型平台可到[Spring AI](https://docs.spring.io/spring-ai/reference/index.html)查看
```xml
com.gitee.wb04307201
easy-ai-spring-boot-starter
0.6.2
org.springframework.ai
spring-ai-ollama-spring-boot-starter
org.springframework.ai
spring-ai-zhipuai-spring-boot-starter
1.0.0-SNAPSHOT
```
修改配置项目
```yaml
spring:
ai:
zhipuai:
api-key: 智谱AI API Key
```
> 除了大模型API外,向量数据库也可以参照上面的方式进行替换