2026年6月22日/ 案例
SmartKB 企业智能知识库
Java 21 + Spring AI 的 Advanced RAG 知识库项目,覆盖文档解析、切片、Embedding、pgvector 检索、流式问答、引用定位、Redis 会话记忆和 RAG 评测。
运行画面
Screens / Motion



问题
企业知识库需要回答可追溯、会话可恢复、检索质量可评测,并且本地能完整跑通上传、入库、问答和引用定位。
方案
我围绕 Advanced RAG 闭环设计了文档上传、UTF-8 解析、切片、Ollama Embedding、pgvector 入库、Hybrid Search、查询改写、过滤、重排序、SSE 流式回答、引用片段定位和 Redis ChatMemory。
展示重点
SmartKB 主要记录 RAG 主链路:文档如何进入知识库、回答如何追溯到原文、检索质量如何被评测。
Upload -> Chunk -> Embed -> Retrieve -> Rerank -> Stream -> Cite
工程讲解
可以从文档入库和引用定位开始讲,重点解释 Redis 会话记忆、Advanced RAG 分阶段反馈和评测报告。生产级 HA、TLS、托管 Secret 等暂不放进首版,后续按部署场景逐步补齐。
实现细节
SmartKB 的主演示链路是上传中文知识文档,解析并切片后写入 pgvector,通过普通 RAG 和 Advanced RAG 两种模式进行流式问答。Advanced 模式会展示查询改写、检索、过滤、重排和生成等阶段反馈,让 RAG 过程可见。
项目实现了 Redis ChatMemory,刷新或重启后同一 conversationId 可以恢复上下文;引用片段可以跳回原始文档 chunk,避免回答变成没有依据的文本生成。内置评测集会对比普通向量召回和 Advanced RAG 的 Recall@K、Top1、MRR 和引用覆盖。
这个项目适合展示 AI 应用工程能力:既有 Spring AI 和模型接口,也有数据存储、向量检索、流式体验、评测、可观测和 Docker Compose 一键运行。重点是把 RAG 从一次问答拆成可运行、可检查的工程链路。
SmartKB's main demo path uploads a Chinese knowledge document, parses and chunks it, stores vectors in pgvector, then runs streaming QA in both normal RAG and Advanced RAG modes. Advanced mode exposes query rewriting, retrieval, filtering, re-ranking and generation stages so the pipeline is not a black box.
Redis ChatMemory lets the same conversationId recover context after refresh or restart. Citations jump back to source chunks, preventing answers from becoming ungrounded generation. The built-in evaluation set compares vector retrieval and Advanced RAG across Recall@K, Top1, MRR and citation coverage.
This project is a strong AI application engineering showcase: it combines Spring AI and model APIs with storage, vector retrieval, streaming UX, evaluation, observability and Docker Compose delivery. It is more defensible than a simple chatbot demo.
复盘