2026年6月22日/ 案例

SmartKB 企业智能知识库

Java 21 + Spring AI 的 Advanced RAG 知识库项目,覆盖文档解析、切片、Embedding、pgvector 检索、流式问答、引用定位、Redis 会话记忆和 RAG 评测。

115
Tests
8
Eval cases
6/6
Memory checks

运行画面

Screens / Motion

RAG 问答演示:上传文档后进行流式回答,并保留引用定位入口。
SmartKB Advanced RAG 阶段反馈
Advanced RAG 模式展示查询改写、检索、过滤、重排和生成阶段。
SmartKB 引用片段定位
引用片段可以回到原始文档 chunk,用于检查回答来源。
SmartKB RAG 评测报告
评测页记录 Recall@K、Top1、MRR 和引用覆盖等指标。

问题

企业知识库需要回答可追溯、会话可恢复、检索质量可评测,并且本地能完整跑通上传、入库、问答和引用定位。

方案

我围绕 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.

复盘

RAG 项目要重点展示可信度:引用、定位、评测和可恢复会话比聊天框本身更重要。
Advanced RAG 需要把检索链路拆开:查询改写、召回、过滤、重排和生成都要能单独观察。
当前版本聚焦本地可运行的 RAG 主链路:文档入库、检索、流式回答、引用定位和评测;权限、多租户、高可用等生产能力放在后续路线。