RAG in practice
For enterprise knowledge bases, private document assistants, and long-code analysis scenarios, master the complete RAG implementation workflow from corpus preparation and retrieval pipeline design to effectiveness evaluation and continuous optimization, truly turning RAG into an iterative engineering system.
Learning objectives
Methodology
RAG-DD workflow
Retrieval pipeline design
Knowledge chunking
- • Prioritize semantic integrity; do not split mechanically by a fixed number of characters
- • Add metadata such as source, time, business domain, and permissions to each chunk
- • Use different chunking strategies for architecture documents, interface documents, and code documentation
Retrieval and reranking
- • For general Q&A, prioritize hybrid retrieval, balancing semantic recall and exact keyword matching
- • For long-code analysis scenarios, reranking is usually more effective than simply increasing top-k
- • When assembling context, preserve the source and hierarchy to avoid fragments being detached from their original context
Practical principles: First build RAG that can explain why it produced that answer, then pursue answer quality that looks smarter.
Evaluation and governance
- • Recall Evaluation: Whether the correct document corresponding to the problem is retrieved
- • Answer evaluation: Whether the answer is accurate, complete, and cites the correct source
- • Failure review: Distinguish whether it is retrieval failure, context contamination, or generation-stage hallucination
- • Permission governance: Isolate documents by knowledge domain and user identity to avoid unauthorized retrieval
AI tool applications
Use Claude to design evaluation sets
Let AI generate an evaluation question set from historical FAQs, tickets, and document indexes, covering query reformulation, ambiguous wording, and long-tail scenarios.
The point is not to “have AI evaluate itself,” but to use AI to quickly build test samples that cover a broader range.
Optimize recall using vector databases and re-ranking models
- • The vector database is responsible for initial retrieval, ensuring as much as possible that it can be "found"
- • The reranking model places the most relevant documents at the top, ensuring they are “delivered accurately”
- • Performing Top-K comparisons on failed samples is more valuable than blindly tuning prompts
Practical case study
Case 1: Internal knowledge base Q&A
Goal: enable employees to query policies, procedures, FAQs, and architecture documents in natural language and return answers with sources.
- • Corpus sources: policy documents, Wiki, FAQ, SOP
- • Key design: document domain partitioning, permission control, version update time
- • Key metrics: hit rate, citation accuracy, problem resolution rate
Case 2: Retrieval-Augmented Assistant for a Large Code Repository
Goal: combine code comments, README, architecture design documents, and module boundary information to help developers quickly locate implementation logic.
- • Corpus sources: code explanations, architecture documents, interface contracts, change logs
- • Key design: organize context by modules and upstream/downstream relationships, rather than only inserting code snippets
- • Failure focus: retrieving stale documents, missing module boundaries, fragments detached from semantic context