跪拜 Guibai
← All articles
Frontend

A Plain-English Walkthrough of RAG, From In-Memory Demos to Milvus

By snow来了 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Hallucination is the single biggest blocker for putting LLMs in front of real users. RAG is the cheapest, most controllable fix available today, and the tooling has settled enough that a working pipeline is a weekend project, not a research undertaking.

Summary

RAG splits into two distinct phases: an offline indexing step that chunks documents, embeds them, and stores the vectors, and an online query step that retrieves the closest chunks, stuffs them into a prompt, and hands the whole thing to the LLM. LangChain's document loaders, text splitters, and vector-store abstractions make the pipeline uniform whether the source is a PDF, a Word file, or a web page.

A basic example runs the entire flow against hard-coded story fragments using MemoryVectorStore, then an advanced example pulls a real .docx file through DocxLoader and RecursiveCharacterTextSplitter. The code is nearly identical; only the loader changes. The final section replaces the in-memory store with a local Milvus instance, showing how to search with cosine similarity and feed results back into a chat model.

Milvus coexists with a traditional database like MySQL rather than replacing it. The walkthrough covers Docker setup, the Attu GUI, and Node.js snippets for embedding, searching, and answering questions from persisted vectors.

Takeaways
RAG's offline indexing phase (load → chunk → embed → store) runs once; the online query phase (embed question → retrieve → assemble prompt → generate) runs per request.
RecursiveCharacterTextSplitter with ~400-character chunks and 100-character overlap is a sensible default for Chinese text, using sentence-ending punctuation as separators.
LangChain abstracts document loaders so the same retrieval-and-generation code works for PDFs, Word files, and web pages with only a loader swap.
Milvus is not a MySQL replacement; the two coexist in an agent project, with Milvus handling vector similarity search and MySQL handling structured metadata.
Advanced retrieval techniques like Rerank, HyDE, Query Rewriting, Hybrid Search, GraphRAG, and Agentic RAG sit on top of the basic pipeline and can dramatically improve answer quality.
Conclusions

The post treats RAG as a solved engineering pattern with a standard component menu, which signals that the Chinese developer community has moved past experimentation and into integration work.

Using a children's story as the demo corpus is a deliberate choice that makes retrieval failures immediately obvious to a human reader, sidestepping the need for formal evaluation metrics in a tutorial.

The jump from MemoryVectorStore to Milvus is presented as a straightforward configuration change, but in practice it introduces persistence, indexing strategy, and connection management that the tutorial's code snippets gloss over.

Concepts & terms
RAG (Retrieval-Augmented Generation)
A pattern that retrieves relevant documents from a knowledge base and inserts them into the LLM's prompt context, grounding the model's answer in provided facts rather than its training data alone.
Vector Embedding
A numerical representation of text (or other data) in a high-dimensional space, where semantically similar items sit close together. Models like OpenAI's text-embedding-v3 produce these vectors.
Milvus
An open-source vector database designed for similarity search at scale. It stores embeddings and supports operations like insert, search, and delete with configurable index types and distance metrics.
RecursiveCharacterTextSplitter
A LangChain utility that splits text by recursively trying a list of separators (e.g., paragraph breaks, then sentences, then spaces) to keep semantically related content together within a target chunk size.
HyDE (Hypothetical Document Embeddings)
A retrieval technique where the LLM first generates a hypothetical answer to the query, then uses that generated text as the search query against the vector store, often producing more relevant results than the raw question.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗