跪拜 Guibai
← All articles
Backend

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

By 苏三说技术 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

This is a paid, closed-source project promoted through a subscription community. It matters primarily to developers looking for a large, pre-built reference implementation that demonstrates how to wire together microservices, hybrid search, RAG pipelines, knowledge graphs, and multi-agent orchestration in both Java and Python stacks.

Summary

The system covers full document lifecycle management, a file center with online preview for 10+ formats including HLS video streaming, and an Elasticsearch-powered hybrid search that fuses BM25 keyword matching with vector semantic retrieval via RRF. Its AI assistant runs a RAG + KAG dual-engine architecture: RAG retrieves document chunks for grounded Q&A, while KAG traverses a Neo4j knowledge graph to answer relational questions like system dependencies. The Python backend adds a LangGraph-based multi-agent workflow where a supervisor agent dispatches search, RAG, KAG, and writing agents through a state graph with checkpoint persistence.

Both backends expose nearly 200 identical REST API endpoints and share one React frontend. The Java stack uses Spring Cloud Alibaba with Nacos, Gateway, Feign, and MyBatis Plus; the Python stack uses FastAPI, SQLAlchemy 2.0 async ORM, Celery with RabbitMQ for async tasks, and a Model Gateway that routes between Qwen and DeepSeek with automatic fallback. Infrastructure spans MySQL (9 databases), MongoDB, Elasticsearch, Neo4j, Redis, and RabbitMQ.

The project is a paid offering promoted as resume material and a full-stack learning vehicle, with source code available through the author's subscription community.

Takeaways
Two functionally equivalent backends exist: a Java edition with 10 Spring Cloud microservices and a Python edition with 8 FastAPI microservices, both sharing one React frontend.
The AI assistant uses three modes—standard chat, RAG over document chunks, and KAG over a Neo4j knowledge graph—with RRF fusion combining BM25 and vector search results.
The Python backend runs a LangGraph StateGraph with five agent types (Search, RAG, KAG, Writing, Supervisor) and supports checkpoint persistence for breakpoint recovery.
Celery handles six async task types including document parsing, BGE-M3 embedding generation, LLM entity extraction for the graph, and FFmpeg HLS transcoding.
A Model Gateway routes requests between Qwen and DeepSeek with intelligent routing, automatic fallback, per-call token billing, and token-bucket rate limiting per model and user.
File preview covers PDF, DOCX, XLSX, PPT, Markdown, images, HLS adaptive-bitrate video, audio, and archive listings without requiring downloads.
Infrastructure includes 9 MySQL databases, MongoDB, Elasticsearch, Neo4j, Redis, and RabbitMQ, with SHA-256 deduplication for uploads and Snowflake distributed IDs.
Total codebase exceeds 50,000 lines: 20,000+ Java, 15,000+ Python, and 16,000+ TypeScript/TSX across 34 frontend pages.
Conclusions

The dual-language implementation is a sales tactic, not an architectural decision—it lets the author sell to both Java and Python camps without maintaining two separate products, since the frontend and API contract are shared.

Calling this 'KAG' is a stretch. The knowledge graph mode queries Neo4j for entity relationships and injects them into a prompt; it does not perform structured reasoning or graph-native inference, which is what the KAG term typically implies in research.

The project's scale—50,000 lines, 9 databases, 7 middleware components—makes it a credible portfolio piece, but the sheer breadth also means individual modules likely trade depth for coverage.

Promoting a system as both a learning resource and resume filler while paywalling the source code is a common monetization pattern in Chinese developer communities; the value is in having a complete, runnable reference, not in novel techniques.

Concepts & terms
RRF (Reciprocal Rank Fusion)
A method for merging ranked results from multiple search algorithms. Each document's score is 1/(k + rank), where k is a constant (often 60). The scores from BM25 keyword search and vector semantic search are summed to produce a final ranking, avoiding the need to normalize disparate score distributions.
KAG (Knowledge-Augmented Generation)
An approach that enhances LLM responses by retrieving structured entity-relationship data from a knowledge graph, rather than only unstructured document chunks. In this system, it means querying Neo4j for related nodes and injecting those relationships into the prompt alongside RAG-retrieved text.
LangGraph StateGraph
A LangChain library for building stateful, multi-step agent workflows as directed graphs. Nodes represent computation steps (like calling an LLM or a tool), edges define transitions, and a shared state object persists across steps. Supports checkpointing for pause-and-resume execution.
BGE-M3
A multilingual embedding model from BAAI that produces 1024-dimensional dense vectors. It supports both Chinese and English, and can generate dense, sparse (lexical), and multi-vector (ColBERT-style) representations from a single model.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗