A Six-Step RAG Pipeline That Turns a Chinese Martial-Arts Epic into a Queryable AI Encyclopedia
This walkthrough demystifies the full RAG stack for developers who have only seen toy examples. It shows the exact parameters, schema design, and prompt engineering needed to turn a long-form text into a reliable, citation-backed Q&A system—a pattern that transfers directly to internal documentation, legal contracts, or any proprietary knowledge base.
A full RAG pipeline built in JavaScript processes the classic wuxia novel "Demi-Gods and Semi-Devils" from EPUB to answer. LangChain's EPubLoader splits the book by chapter, a RecursiveCharacterTextSplitter breaks chapters into 500-character overlapping chunks, and each chunk gets a 1024-dimension embedding before insertion into a Milvus vector database with IVF_FLAT indexing and cosine similarity search. When a user asks "What martial arts does Duan Yu know?", the system retrieves the top three semantically relevant snippets and feeds them into an LLM prompt that constrains the model to answer only from the provided text.
The pipeline is generic: swap the EPUB file or the Loader type to ingest PDFs, CSVs, or other document formats. The Milvus collection schema tracks book ID, chapter number, and chunk index alongside the vector and raw content, making it straightforward to support multiple books in a single knowledge base. The streaming approach processes one chapter at a time to avoid loading the entire book into memory.
The prompt design is the unsung hero here: it explicitly tells the model to admit ignorance when excerpts lack relevant information, which is the difference between a trustworthy knowledge base and a hallucination-prone chatbot.
Storing chapter and chunk metadata alongside vectors turns the database into an audit trail—every answer can be traced back to a specific passage, a capability that enterprise compliance use cases demand.
The 500-character chunk size is a pragmatic sweet spot: large enough to carry context for a martial-arts move description, small enough that retrieval precision doesn't degrade into noise.