博客内容Blog Content

升级网页AI知识库聊天机器人 Upgrade Web AI Knowledge Base Chatbot

BlogType : Website releaseTime : 2025-09-01 23:00:00

使用SpringAI+SSE等技术重构了原来的聊天机器人,实现更快的加载、更准确的回复、以及更合理的架构设计 Refactored the original chatbot using technologies like SpringAI and SSE to achieve faster loading, more accurate responses, and a more reasonable architectural design.

背景 Background

在之前的v1版本中,虽然使用纯SpringBoot原生框架实现了RAG搜索,但仍有以下问题:

  • 调用大模型接口使用同步模式,需要大模型回复完才把内容进行前端加载,看不到中间结果+需要等待时间长

  • 没有上下文记忆功能

  • 不支持markdown格式

  • 不支持联网搜索

  • 手动维护mysql知识库较繁琐

In the previous v1 version, although the RAG search was implemented using the native SpringBoot framework, there were still the following issues:

  • Calling large model APIs used a synchronous mode, which required the model to finish generating a response before loading it on the frontend. This caused long waiting times without any intermediate output.

  • No context memory functionality.

  • No support for Markdown format.

  • No support for online search.

  • Manual maintenance of the MySQL knowledge base was cumbersome.




架构优化点 Architecture Optimization Points

本次v2优化,添加了以下功能:

  • 引入了SpringAI,集成了知识库维护、上下文记忆等功能,无需手动实现

  • 引入了SSE(server-sent events)优化前端,使得模型回答途中的流输出得到前端加载,同时支持markdown格式

  • 引入了SearXNG搜索引擎,能支持联网查询,并将相关结果整合到回答中

In this v2 upgrade, the following features were added:

  • Introduced SpringAI, which integrates features such as knowledge base maintenance and context memory without manual implementation.

  • Introduced SSE (Server-Sent Events) to optimize the frontend, enabling streaming output of model responses to be loaded in real-time, with Markdown format support.

  • Integrated the SearXNG search engine to support online queries and incorporate relevant results into answers.




待实现功能 Features to Be Implemented

待支持相关功能:

  • 提供MCP相关支持提高模型能力,比如内部接口获取网页数据和知识库,作为知识库和实时查询的补充


Planned features to be supported:

  • Provide MCP-related support to enhance model capabilities, such as obtaining webpage data and knowledge base content via internal APIs, as a supplement to the knowledge base and real-time search.




开发期间挑战 Challenges During Development

  • 知识库redis-stack和其他数据使用的redis需要分开,代码单独处理

  • tomcat版本问题,需要从直接的9.x版本升级到11.x版本,同时将jdk8升级到jdk21

  • SpingBoot+thymeleaf前端传contextPath参数问题,和之前版本不同

  • 服务器部署后发送SSE问题,需要对Nginx和后端代码进行调整

  • SSE需要维持心跳避免连接被关闭

  • The Redis stack used for the knowledge base needed to be separated from other Redis data, requiring separate handling in code.

  • Tomcat version issues: needed to upgrade from the direct 9.x version to 11.x, and also upgrade JDK from 8 to 21.

  • ContextPath parameter passing issue in SpringBoot + Thymeleaf frontend, which differs from previous versions.

  • SSE transmission issues after server deployment required adjustments to both Nginx and backend code.

  • SSE needs heartbeat to prevent connection from being closed.