
Spring Boot3.4.3+DeepSeek-R1+Vector Databases构建专属AI Agent智能体(附源码)
·
Spring AI介绍
Spring AI
项目旨在简化包含人工智能功能的应用程序的开发,避免不必要的复杂性。
该项目从著名的 Python 项目(例如 LangChain 和 LlamaIndex)中汲取灵感,但 Spring AI 并非这些项目的直接移植。该项目的成立基于这样的信念:下一波生成式 AI 应用将不仅面向 Python 开发人员,还将遍及多种编程语言。
Spring AI 解决了 AI 集成的根本挑战:Connecting your enterprise Data and APIs with AI Models 。 |
|
---|---|
![]() |
|
Spring AI 提供了抽象概念,作为开发 AI 应用程序的基础。这些抽象概念具有多种实现,只需进行少量代码更改即可轻松更换组件。
Spring AI 提供以下功能:
- 跨 AI 提供商的可移植 API 支持聊天、文本转图像和嵌入模型。支持同步和流式 API 选项。还可访问特定于模型的功能。
- 支持所有主要AI 模型提供商,例如 Anthropic、OpenAI、Microsoft、Amazon、Google 和 Ollama。支持的模型类型包括:
- 结构化输出- 将 AI 模型输出映射到 POJO。
- 支持所有主要的矢量数据库提供商,例如 Apache Cassandra、Azure Cosmos DB、Azure Vector Search、Chroma、Elasticsearch、GemFire、MariaDB、Milvus、MongoDB Atlas、Neo4j、OpenSearch、Oracle、PostgreSQL/PGVector、PineCone、Qdrant、Redis、SAP Hana、Typesense 和 Weaviate。
- 跨 Vector Store 提供商的可移植 API,包括一种新颖的类似 SQL 的元数据过滤器 API。
- 工具/功能调用- 允许模型请求执行客户端工具和功能,从而根据需要访问必要的实时信息并采取行动。
- 可观察性——提供对 AI 相关操作的洞察。
- 用于数据工程的文档提取ETL 框架。
- AI 模型评估- 用于帮助评估生成的内容并防止产生幻觉反应的实用程序。
- 用于 AI 模型和向量存储的 Spring Boot 自动配置和启动器。
- ChatClient API - 用于与 AI 聊天模型通信的流畅 API,惯用语类似于 WebClient 和 RestClient API。
- 顾问 API——封装重复的生成式 AI 模式,转换发送到和来自语言模型 (LLM) 的数据,并提供跨各种模型和用例的可移植性。
- 支持聊天对话记忆和检索增强生成 (RAG)。
此功能集可让您实现常见的用例,例如“通过文档进行问答”或“通过文档进行聊天”。
后端项目展示
Maven依赖
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>1.0.0-M6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-zhipuai-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-zhipuai</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-pgvector-store-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-pdf-document-reader</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-tika-document-reader</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
后端代码片段
知识库向量表
历史会话向量表
前端项目展示
vite&react
项目演示
创建会话
DeepSeek第一轮对话
上传自己的业务数据训练
在这里插入图片描述
DeepSeek第二轮对话(RAG增强搜索)
总结
在 AI 智能体(AI Agent)开发的过程中,RAG(Retrieval-Augmented Generation)和 Tool Calling 已经成为两种至关重要的模式。RAG 通过结合检索技术和生成模型的强大能力,使智能体能够实时从外部数据源获取信息,并在生成过程中增强其知识深度和推理能力。通过这种方式,智能体不仅能依赖于模型的预训练知识,还能动态访问和处理更加广泛、详细的外部数据,从而显著提升其在复杂任务中的表现。与此同时,Tool Calling 模式为智能体提供了调用外部工具的能力,极大地扩展了其应用范围。智能体可以通过调用外部工具(如天气预报、地图导航、社交媒体平台等),完成更为复杂的任务和操作。这种灵活性使得智能体在各种实际场景中都能表现得更为高效和精确。
体验地址
https://lucifer-cloud.com/chat/
源码地址
更多推荐
所有评论(0)