跪拜 Guibai
← Back to the summary

A 50,000-Line Enterprise Knowledge Base with Dual RAG+KAG Engines in Both Java and Python

Foreword

Recently, my enterprise intelligent knowledge base system was upgraded: a Python version of the backend microservice has been added.

It currently includes three projects:

  1. React frontend project
  2. Java backend project
  3. Python backend project

This system is very practical and can be directly written into your resume, adding significant value.

Through this system, you can learn frontend, Java, Python, and AI technologies together.

More project practices are on my technical website: susan.net.cn/project

1. Project Introduction

What does this project do?

Simply put: It makes enterprise knowledge truly flow.

Do you often encounter these situations in your company:

The Enterprise Intelligent Knowledge Base System was born to solve these problems.

It covers the entire chain from document creation, classified storage, hybrid intelligent search, permission approval, version management, to AI intelligent Q&A, AI writing, and knowledge graph analysis.

How large is the project?

Dimension Data
Backend Tech Stack Two options: Java Edition / Python Edition
Java Edition Microservice Modules 10, Java source files 192
Python Edition Microservice Modules 8, Python source files 120+
REST API Endpoints Nearly 200 (functionally equivalent across both backends)
Frontend Feature Pages 34
Database (MySQL) 9, totaling 29 business tables
Middleware Integrations Java Edition 7 types / Python Edition 7 types
Backend Code Volume Java Edition 20,000+ lines / Python Edition 15,000+ lines
Frontend Code Volume 16,000+ lines TypeScript/TSX
Total Code Volume 50,000+ lines (including both backends)

This project provides both Java and Python backend implementations, with completely equivalent functionality. You can choose one to learn and use based on your tech stack preference.

Both backends follow the same REST API specification, so the frontend requires no changes.

System Architecture Overview

image.png

Architecture Highlights: The project provides two independent backend implementations in Java and Python.

The Java edition is based on the Spring Cloud Alibaba microservice ecosystem, while the Python edition is based on FastAPI + LangChain.

Both backends are functionally equivalent (core capabilities like document management, search, AI Q&A, and permission control are completely identical) and share the same frontend.

Choose one based on your team's tech stack; the deployment plans are independent of each other.

2. Technologies Used

Java Backend Tech Stack

Technology Version Actual Use in the Project
Java 21 LTS Virtual threads, Record classes, pattern matching
Spring Boot 3.2.0 Basic framework for all microservices
Spring Cloud 2023.0.0 Microservice governance, inter-service calls
Spring Cloud Alibaba 2023.0.1.0 Nacos registration center & configuration center integration
Spring Cloud Gateway - Unified API gateway, routing, CORS
MyBatis Plus 3.5.8 ORM operations for all databases
Druid 1.2.20 Database connection pool + SQL monitoring
MySQL 8.0 9 business databases, 22+ tables
Redis 7.x Caching, Session, real-time leaderboards
Elasticsearch 7.x Full-text search + vector storage
MongoDB 6.x Document body content storage
Neo4j 5.x Knowledge graph node and relationship storage
RabbitMQ 3.x Asynchronous messages (transcoding, index sync, notifications)
LangChain4j 0.29.1 LLM integration framework, unified model calls
Knife4j 4.3.0 Auto-generates Swagger API documentation
JWT (JJWT) 0.12.3 Stateless authentication
Hutool 5.8.24 General utility library

Python Backend Tech Stack

In addition to the Java edition, the project also provides a complete Python backend implementation.

Both backends are functionally equivalent, have consistent API interfaces, and share the same frontend. If you specialize in Python, or your team is transitioning from Java to Python, you can directly choose this set:

Technology Version Actual Use in the Project
Python 3.12 Type hints, match-case pattern matching, asyncio coroutines
FastAPI 0.115+ High-performance async web framework, replacing Spring Boot, auto-generates Swagger docs
Pydantic 2.x Request/response data validation and model definition, replacing Java Bean Validation
SQLAlchemy 2.0+ Async ORM, replacing MyBatis Plus, managing CRUD for all business tables
Alembic - Database migration tool, replacing Flyway/Liquibase
Uvicorn + Gunicorn - ASGI multi-worker server, concurrency model replacing Tomcat/Nginx
FastAPI Users - JWT authentication + RBAC permission system, replacing Spring Security + JJWT
LangChain 0.3+ Unified LLM call orchestration, RAG Pipeline construction
LangGraph 0.2+ Multi-step AI Agent orchestration engine, state graph driven
OpenAI SDK 1.x Compatible with multiple model APIs (Tongyi Qianwen / DeepSeek / GLM-4)
Sentence-Transformers 3.x Local Embedding model (BGE-M3, 1024 dimensions)
Elasticsearch 7.x Full-text search + vector storage
MongoDB 6.x Document body content + auto-save history
Neo4j 5.x Knowledge graph node and relationship storage
Redis 7.x Cache, Session, Celery message Broker
Celery 5.4+ Async task queue (document parsing, vector embedding, video transcoding, push notifications)
RabbitMQ 3.x Optional message queue (complementary to Celery, cross-team decoupling)
httpx 0.28+ Async HTTP client, inter-service RPC calls
FastStream - Kafka/RabbitMQ event stream processing framework
tiktoken - Accurate Token counting and chunk boundary control

Why provide a Python edition? Many teams have disagreements on backend language selection: the Java camp values stability and enterprise ecosystem, while the Python camp values AI ecosystem and development efficiency.

This project directly implements both, with completely equivalent functionality, consistent API interfaces, and a shared frontend.

Use the Java edition if you prefer Java, or the Python edition if you prefer Python. No need to agonize over missing out by choosing one.

Frontend Tech Stack

Technology Version Actual Use in the Project
React 18.3.1 Core UI framework
TypeScript 5.3.3 Strict mode, zero type errors
Vite 5.1.0 Build tool, SWC compilation, sub-second hot reload
Ant Design 5.14.0 Enterprise UI component library, Chinese locale
React Router 6.22.0 Client-side routing + lazy loading + permission guards
Zustand 4.5.0 Lightweight state management + persist persistence
Axios 1.6.7 HTTP requests + token auto-refresh + retry queue
ECharts 5.6.0 Data visualization charts
react-markdown 9.0.1 Markdown rendering + GFM support
react-syntax-highlighter 16.1.1 Code block syntax highlighting
react-pdf 10.4.1 PDF online preview
mammoth 1.8.0 DOCX to HTML preview
xlsx 0.18.5 Excel spreadsheet parsing and preview

Middleware & Infrastructure

image.png

3. Feature Introduction

This system is not a CRUD shell.

I will break down the core features one by one.

3.1 Full Document Lifecycle Management

From the birth of a document to its archiving, every stage is managed:

image.png

Detailed Feature List:

3.2 File Management Center

A unified file management platform, not just for storing files, but for full-format online preview:

Category Supported Formats Preview Method
PDF .pdf react-pdf rendering, supports zoom and page turning
Word .doc / .docx mammoth to HTML rendering
Excel .xls / .xlsx SheetJS parsing into interactive tables
PPT .ppt / .pptx Backend extracts slides as image previews
Markdown .md react-markdown + code highlighting
Plain Text .txt Monospace font rendering
Image .png / .jpg / .gif / .bmp / .svg Native preview + thumbnails
Video .mp4 / .avi / .mov / .mkv / .webm HTML5 Video + HLS adaptive bitrate
Audio .mp3 / .wav / .flac / .aac / .ogg HTML5 Audio playback
Archive .zip / .rar / .7z File list display

Video files also support:

3.3 Intelligent Search

This is not a simple database LIKE fuzzy query, but an enterprise-grade search engine based on Elasticsearch:

image.png

Search Capabilities:

3.4 AI Intelligent Assistant (This is the most hardcore part)

This is not a "ChatGPT wrapper" that just calls an API.

This system implements a complete RAG + KAG dual-engine architecture:

Three conversation modes, adapting to different scenarios:

Mode Principle Applicable Scenario
Standard Chat Directly calls the large model General Q&A, casual chat, writing assistance
RAG Chat Retrieves relevant document snippets from the knowledge base, injects into Prompt "How do I integrate with our company's payment API?"
KAG Chat Combines entity relationships in the knowledge graph to enhance context "What systems does the payment system depend on?"

RAG (Retrieval-Augmented Generation):

image.png

KAG (Knowledge-Augmented Generation):

image.png

AI-Assisted Writing:

Dual Model Support:

3.5 Knowledge Graph Visualization

Builds a knowledge network based on the Neo4j graph database, supporting:

3.6 Permission Management (True Enterprise-Grade RBAC)

image.png

Complete Features:

3.7 Data Dashboard & Statistical Analysis

3.8 Real-time Notification System

3.9 Python Backend Implementation Plan

If you choose the Python backend, here are the highlights of several core modules in the Python version.

Functionally equivalent to the Java version, but the implementation is more aligned with the Python ecosystem's characteristics.

1. FastAPI Microservice System

The Python version is split into 8 independent FastAPI applications, routed through Nginx reverse proxy or Traefik as a gateway:

Module Port Responsibility
gateway-service 8000 Unified entry, JWT validation, CORS, rate limiting
auth-service 8001 User authentication, RBAC permissions, team management
document-service 8002 Document CRUD, categories, tags, comments, approval
file-service 8003 File upload/download, format conversion, HLS transcoding
search-service 8004 ES full-text search, search suggestions, hot search ranking
ai-service 8006 RAG/KAG chat, AI writing, LangGraph Agent
graph-service 8008 Neo4j knowledge graph node and relationship management
statistics-service 8005 Data dashboard, scheduled statistics, user activity

All services use the httpx async client for inter-service calls. JWT authentication is uniformly intercepted by FastAPI middleware, and the X-User-Id Header is passed through, consistent with the Java version's design.

2. Full-Link RAG Pipeline

Document Ingestion (triggered asynchronously by document-service)
  ├── LangChain RecursiveCharacterTextSplitter intelligent chunking
  │   ├── Adaptive semantic chunking (paragraph boundary aware, not brute-force truncation)
  │   └── Dynamic chunk_size (256~1024, automatically adjusted based on document type)
  ├── Celery EmbeddingTask → Sentence-Transformers BGE-M3 local Embedding
  │   ├── 1024-dimensional dense vector, supports Chinese and English
  │   └── GPU accelerated batch processing (batch_size=32)
  ├── ES dense_vector index writing (or optional Milvus)
  └── At query time: BM25 + Vector dual-path recall → RRF fusion

3. LangGraph Agent Workflow

The AI conversation in the Python version is not a simple one-question-one-answer, but a multi-step autonomous reasoning chain built through LangGraph:

Agent Type Capability Application Scenario
SearchAgent Retrieve documents by keyword, category, tag "Find the payment API document"
RAGAgent Semantic search + LLM answer generation "How to integrate the payment API?"
KAGAgent Knowledge graph traversal + relational reasoning "What systems are related to the payment system?"
WritingAgent Outline generation → Paragraph expansion → Polishing "Help me write a payment system integration guide"
SupervisorAgent Dispatch the above Agents, autonomously decide the call order "Analyze the overall architecture of the payment system"

All Agents are connected through LangGraph StateGraph, supporting Checkpointer state persistence and breakpoint recovery.

4. Celery Asynchronous Task System

The Python version uses the Celery + RabbitMQ combination for asynchronous decoupling of all time-consuming operations:

5. Model Gateway

┌─────────────────────────────────────────────────┐
│            FastAPI Model Gateway               │
├─────────────────────────────────────────────────┤
│  Unified Interface: POST /api/v1/chat/completions        │
├──────────┬──────────┬──────────┬───────────────┤
│  Qwen    │ DeepSeek │ GLM-4    │ Local Model      │
│ (Tongyi) │ (DeepSeek) │ (Zhipu)    │ (Ollama/vLLM) │
├──────────┴──────────┴──────────┴───────────────┤
│  Auto fallback: Model A timeout → Model B takeover         │
│  Intelligent routing: Simple Q&A→DeepSeek / Complex reasoning→Qwen     │
│  Token billing: Accurately calculate consumed Tokens and cost per call   │
│  Rate control: Token Bucket rate limiting by model + user dimension │
└─────────────────────────────────────────────────┘

4. System Showcase

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

5. Project Highlights

5.1 Architecture Highlights

1. True Microservice Implementation, not "just renaming modules"

Gateway's AuthGlobalFilter completes JWT validation when the request enters, extracts user information, and passes it downstream via the X-User-Id Header. Downstream services do not need to repeat authentication logic, just read the user identity from the Header—separation of concerns, cleaner code.

Inter-service communication uses Spring Cloud OpenFeign, defining remote calls with interfaces and annotations, writing no HTTP connection code at all.

All 10 services automatically register with Nacos after startup, supporting health checks, load balancing, and dynamic scaling.

2. RAG + KAG Dual-Engine AI Architecture

This is not a simple "connect to ChatGPT API".

The project implements a complete pluggable AI engine architecture:

Dimension RAG Engine KAG Engine
Data Source Document content (vectorized chunks) Knowledge Graph (Neo4j entity relationships)
Retrieval Method Embedding vector similarity + BM25 hybrid retrieval LLM entity recognition → Neo4j multi-hop traversal
Core Advantage Semantic matching, understanding user intent Structured reasoning, discovering implicit associations
Fusion Strategy RRF (Reciprocal Rank Fusion) weighted fusion, adjustable weights

The entire pipeline can be broken down into independent steps: Document Chunking → Text Embedding → Vector Indexing (KNN) → Hybrid Retrieval → Context Construction → LLM Generation.

Each step has an independent Service implementation, making it easy to replace or upgrade.

3. Hybrid Search (BM25 + Vector)

Not a simple ES LIKE fuzzy query, but implements multi-path recall + fusion ranking for search results:

User searches "how to improve system performance"
  ├── Path 1: BM25 inverted index keyword match → Hits "performance optimization" documents (precise but may miss synonyms)
  ├── Path 2: text-embedding-v3 vector semantic match → Hits "system tuning" documents (semantically similar but different wording)
  └── RRF Fusion: Weighted fusion of both paths' results by reciprocal rank, outputting Top-K=20 final results

Vector embedding uses the Alibaba Cloud text-embedding-v3 model, 1024-dimensional vectors stored in Elasticsearch's dense_vector field, supporting KNN approximate nearest neighbor search.

Each user search is asynchronously written to MySQL, and scheduled tasks aggregate and calculate hot search rankings.

Search history supports personal dimension management (view/clear/export), while hot search rankings are displayed system-wide—protecting personal privacy while providing global trend insights.

4. RabbitMQ-Driven Event Asynchronous Processing

A large number of time-consuming operations are asynchronously decoupled through RabbitMQ, keeping core processes responsive:

Event Producer Consumer Description
Operation Log AOP Aspect kb-foundation Does not block business requests
Document Index Update kb-document kb-search/Consumer Asynchronously updates ES after document publishing
RAG Vectorization kb-document kb-ai/ReindexConsumer Asynchronously embeds vectors after document publishing
KAG Graph Construction kb-document kb-ai/KAGReindexConsumer Asynchronously builds graph after document publishing
Video Transcoding kb-file kb-file/TranscodeConsumer Large file transcoding does not block upload
Notification Push Various Services kb-foundation Asynchronous message distribution

6. Two Backend Implementations, Free Choice

This is the core highlight that distinguishes this project from the vast majority of open-source projects—not just one backend, but complete implementations in both Java and Python:

Dimension Java Edition Python Edition
Framework Spring Boot 3.2 + Spring Cloud FastAPI 0.115 + LangChain
Microservice Modules 10 8
ORM MyBatis Plus SQLAlchemy 2.0+
Authentication Spring Security + JJWT FastAPI Users + PyJWT
Async Tasks RabbitMQ Celery + Redis + RabbitMQ (Celery for task scheduling, RabbitMQ for cross-service decoupling)
Database MySQL ×9 + MongoDB + ES + Neo4j Same set of databases, interface compatible
Inter-service Calls OpenFeign httpx async client
Deployment JAR + Docker Compose Uvicorn + Docker Compose
API Interface Uses the same Swagger specification, consistent interface paths and parameters
Frontend Shares the same React frontend, zero changes to switch

Design Philosophy: Most microservice open-source projects only provide an implementation in one language. If your preferred language isn't available, you have to make do.

This project has done both, with completely equivalent functionality.

If you want to learn the Spring Cloud ecosystem with Java, use the Java edition; if you want to learn FastAPI + LangChain + AI-native development with Python, use the Python edition.

Both sets of source code are in the Planet, one payment gets you everything.

5. Full-Format File Preview System

Covering PDF, DOCX, XLSX, PPT, Markdown, TXT, images, video (HLS), audio, users can view content without downloading files.

The project covers almost all file formats encountered in daily enterprise use, without requiring users to install any software:

Category Supported Formats Preview Technology Key Libraries
PDF .pdf Paginated rendering, supports zoom react-pdf 10.x
Word .doc/.docx Real-time HTML conversion mammoth.js
Excel .xls/.xlsx Interactive data table SheetJS (xlsx)
PPT .ppt/.pptx Slide-by-slide preview Backend image extraction
Markdown .md GFM rendering + code highlighting react-markdown + PrismJS
Plain Text .txt Monospace font rendering Native
Image png/jpg/gif/bmp/svg/webp Thumbnails + original image preview Native
Video mp4/avi/mov/mkv/webm HLS adaptive bitrate streaming FFmpeg + HTML5 Video
Audio mp3/wav/flac/aac/ogg HTML5 audio playback Native Audio
Archive zip/rar/7z File list display -

After video upload, it automatically completes: SHA-256 integrity check → FFprobe metadata extraction (duration/resolution/bitrate) → User clicks "Transcode" → RabbitMQ asynchronously sends transcode message → FFmpeg generates 360p + 720p multi-bitrate segments → HLS .m3u8 playlist → Frontend automatically switches quality based on network conditions.

The entire process is fully asynchronous, does not block user operations, and transcoding progress can be queried via API.

Import support: Word (.docx) → Markdown, Markdown (.md) → System document, Plain text (.txt) → System document, Drag-and-drop batch import

Export support: Markdown → PDF, Markdown → Word, Markdown → Original format download

A complete document format conversion pipeline has been built, knowledge can come in and go out.

5.2 Engineering Highlights

Category Highlight Count Core Keywords
Microservice Architecture 6 Database-per-service, Gateway auth pass-through, Feign declarative calls, Nacos registration and configuration, Java/Python dual backend implementation, completely equivalent functionality
AI/LLM 7 RAG+KAG dual-engine, LangChain+LangGraph Agent orchestration, Hybrid search RRF fusion, LLM auto-builds knowledge graph, SSE streaming output, dual model switching, feedback loop
Python Backend 5 FastAPI async microservices, Celery async task queue, SQLAlchemy 2.0 async ORM, Sentence-Transformers local Embedding, Model Gateway
Search Technology 2 BM25+Vector hybrid retrieval+RRF fusion, asynchronous hot search analysis
Permission Security 4 Three-tier RBAC, Token refresh request queue, anti-full-table-update interceptor, AOP annotation auditing
Storage Files 3 Full-format preview matrix, HLS adaptive streaming, SHA-256 instant upload deduplication
Data Engineering 4 Snowflake distributed ID, logical delete auditing, message queue event-driven, scheduled statistics
Frontend Engineering 4 Axios interceptor system, Zustand persistence, route lazy loading guards, TS zero errors
Ops Engineering 4 Global exception handling, Knife4j online documentation, virtual threads

More project practices are on my technical website: susan.net.cn/project

5.3 What Can This Source Code Bring You?

If you are a Java backend developer:

If you are a Python backend developer:

If you are a frontend developer:

If you focus on AI / LLM:

If you are an architect or tech leader: