# Spring AI RAG Demo **Repository Path**: martinzh717/spring-ai-rag-demo ## Basic Information - **Project Name**: Spring AI RAG Demo - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2025-07-07 - **Last Updated**: 2025-11-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🚀 Spring RAG Demo > 基于 Spring AI 和 Ollama 的 RAG(检索增强生成)演示项目 ## 📋 项目简介 这是一个使用 Spring AI 框架构建的 RAG (Retrieval-Augmented Generation) 演示项目,展示了如何利用本地 Ollama 模型来处理 PDF 文档并回答相关问题。项目集成了向量存储、文档嵌入和智能问答等功能。 ## 🎯 主要功能 - 📄 **PDF 文档处理**:自动读取和解析 PDF 文档 - 🔍 **向量化存储**:将文档内容转换为向量并存储 - 🤖 **智能问答**:基于文档内容回答用户问题 - 🏠 **本地部署**:使用 Ollama 本地模型,无需外部 API ## 🛠️ 技术栈 - **Java 17** - **Spring AI 1.0.0** - **Ollama** (qwen2.5:latest) - **Maven** ## 🏗️ 系统架构 ![图1:Spring RAG系统架构图](images/Spring-RAG系统架构图.png) ## 📊 工作流程 ![图2:RAG系统工作流程时序图](images/RAG系统工作流程时序图.png) ## 🚀 快速开始 ### 前置条件 1. **安装 Java 17+** 2. **安装 Ollama**: ```bash # macOS brew install ollama # 启动 Ollama 服务 ollama serve ``` 3. **下载模型**: ```bash ollama pull qwen2.5:latest ``` ### 运行项目 ```bash # 克隆项目 git clone https://gitee.com/martinzh717/spring-ai-rag-demo cd spring-rag-demo # 编译运行 mvn clean compile exec:java -Dexec.mainClass="cn.jishuba.spring.rag.SpringRagDemoApplication" ``` ## 📁 项目结构 ``` spring-rag-demo/ ├── 📄 pom.xml # Maven 配置文件 ├── 📖 README.md # 项目说明文档 └── src/ └── main/ ├── java/ │ └── cn/jishuba/spring/rag/ │ └── 🚀 SpringRagDemoApplication.java └── resources/ └── 📄 2025-Microsoft-AI-in-Education-Report.pdf ``` ## 🔧 配置说明 项目使用以下默认配置: - **Ollama 模型**:`qwen2.5:latest` - **向量存储**:`SimpleVectorStore` - **文档类型**:PDF - **运行模式**:命令行应用 ## 📝 示例用法 项目启动后会自动: 1. 📄 读取 `2025-Microsoft-AI-in-Education-Report.pdf` 文档 2. 🔄 将文档内容向量化并存储 3. 🤖 使用 Ollama 模型回答预设问题:"请概括文档中的内容" 4. 📊 输出分析结果 ## 🎨 自定义配置 你可以轻松修改以下配置: - **更换 PDF 文档**:替换 `resources` 目录下的 PDF 文件 - **切换模型**:修改 `OllamaOptions` 中的模型名称 - **自定义问题**:修改 `user()` 方法中的问题内容 ## 👨‍💻 开发者 - **Martin Zhang** - [martinzh@qq.com](mailto:martinzh@qq.com) - **网站**: [https://jishuba.cn/](https://jishuba.cn/) ## 📄 许可证 本项目采用开源许可证,详情请查看 LICENSE 文件。 ## 🤝 贡献 欢迎提交 Issue 和 Pull Request! --- ⭐ 如果这个项目对你有帮助,请给个 Star 支持一下!