RAG Implementation Guide: Six Steps to a Working Retrieval-Augmented Generation Pipeline

    This guide explains why building a RAG (Retrieval-Augmented Generation) system does not require creating a platform first. It covers what RAG is, why it is a good early candidate for deployment, and a six-step path to a minimum viable pipeline: curating source documents, parsing and chunking, vectorization with a keyword index, retrieval and reranking, grounded generation with citations, and recall testing on a small set of real user questions. It also outlines deployment choices based on whether data can leave the internal network, common pitfalls, and a pre-launch checklist.

    Start With the Conclusion: You Do Not Need a Platform to Ship RAG

    When many teams discuss RAG (Retrieval-Augmented Generation), the first instinct is to launch a project to build an “enterprise knowledge platform.” From an engineering ROI perspective, the faster path is different: pick one specific Q&A scenario, clean up the documents the model will reference, build a minimum viable pipeline in six steps, and validate retrieval with about 20 real user questions. If the data is allowed to go to the cloud, start with ready-made general-purpose cloud capabilities (object storage, managed vector retrieval, container platforms, logging and monitoring/alerting, and similar common categories) to test the results. If the data cannot leave the internal network, take the self-hosted route instead.

    The value of this order is straightforward: the success of RAG depends mainly on data quality and retrieval quality, not on whether the framework is built in-house. Validating “is retrieval accurate?” with a minimal pipeline first, and only then deciding whether to invest in platform building, significantly lowers the cost of trial and error.

    What RAG Is and Why It Is Worth Shipping First

    The term RAG comes from a 2020 paper on retrieval-augmented generation. The core idea: before generating an answer, the model first retrieves relevant content from external data, then the retrieved passages and the user question are sent to the model together to produce the answer. The common industry explanation is that relevant information is pulled from a knowledge base and appended to the prompt, which noticeably improves answer quality.

    One frequently cited experiment illustrates the point well. Indexes were built from encyclopedia snapshots taken in an earlier year and a later year, and the question asked about changes in national leadership. When the index year matched the year in the question, accuracy was around 70%; when it did not match, accuracy dropped sharply to roughly 10% or even lower. The key implication of this comparison: the model weights did not change, yet simply swapping the retrieval index updated the facts the model “knew.”

    This leads to two reasons RAG is a good candidate to ship first:

    • Low cost of knowledge updates. Factual changes are handled by updating data and indexes, with no need to retrain or fine-tune.
    • Stronger explainability. Answers can include source passages, which makes human review and accountability easier.

    The boundary should also be clear: RAG reduces unfounded fabrication, but when retrieval returns nothing or returns the wrong passages, the model may still “guess” from its parametric memory. For high-precision fields such as prices, amounts, IDs, and dates, a human verification step must be kept.

    Six Steps to a Minimum Viable Pipeline

    Step 1: Curate the Data and Keep Dirty Data Out

    Define the scope of documents the model will reference, remove outdated versions and duplicate content, and tag each document with its version and effective date. Industry practice consistently warns that outdated data and duplicate content entering the knowledge base directly degrade answer quality and cause retrieval results to conflict with each other.

    It is worth maintaining a data register with at least these fields:

    1. doc_id | title | version | effective_date | scope | classification | owner

    The classification and scope fields directly determine “can this go to the cloud?” when you choose a deployment option later.

    Step 2: Parsing and Chunking Set the Retrieval Ceiling

    Extract the body text and tables from PDFs, Word documents, and web pages into structured text, then split it into small segments. Chunk granularity is a classic trade-off: chunks that are too large mix in irrelevant information and dilute the semantics; chunks that are too small lose context and produce incomplete answers.

    Practical recommendations:

    • Split along semantic structure (headings, subsections, list items, table rows) rather than mechanically cutting at a fixed character count.
    • Keep a small overlap between adjacent chunks so key sentences are not cut apart.
    • Preserve metadata for every chunk: source document, section path, version, page number. This is the foundation for citing sources later.

    Step 3: Vectorize and Index — Do Not Skip the Keyword Index

    Encode text chunks as vectors and write them to a vector database, while also building a keyword (inverted) index to form hybrid retrieval. The reason is direct: user queries contain many exact strings, such as error codes, model numbers, and clause numbers. Pure vector retrieval tends to surface passages that are “semantically close but do not match literally,” whereas keyword retrieval can hit exactly.

    Illustrative flow:

    1. chunks = parse_and_split(docs) # parse and chunk
    2. for c in chunks:
    3. c.vector = embed(c.text) # vectorize
    4. c.meta = {doc: c.doc_id, ver: c.version, page: c.page}
    5. vector_index.upsert(chunks) # write vector index
    6. keyword_index.upsert(chunks) # write keyword index

    Step 4: Retrieval and Reranking — Two Stages Are More Reliable

    After the user asks a question, encode it as a vector, take candidate sets from the vector index and the keyword index separately, merge and deduplicate them, then run a reranking model for a second-pass ordering and take the top few passages into the generation stage. The benefit of the two-stage structure: the first stage pursues recall and the second pursues precision, without interfering with each other.

    1. q_vec = embed(question)
    2. cands = merge(vector_index.search(q_vec, k=20),
    3. keyword_index.search(question, k=20))
    4. top = rerank(question, cands)[:5]

    Step 5: Generate and Cite Sources

    Pass the retrieved passages and the question to the model together, and state the constraint explicitly in the prompt: “Answer only from the given material; if the material does not contain it, say you do not know,” and require the output to include the cited passage numbers or source titles. This step makes the “ability to refuse” explicit and is one of the most economical ways to control hallucination.

    1. Answer the question using only the material below; if the material is insufficient, state clearly that "it is not mentioned in the material."
    2. At the end of the answer, list the cited document numbers and version dates.
    3. Material:
    4. [1] ... [2] ...
    5. Question: ...

    Step 6: Recall Testing — Do Not Roll Out to Everyone Yet

    Once the pipeline is built, run a small-sample evaluation first. Most application orchestration platforms provide “recall test” or “hit test” capabilities that let you input a question directly and see which passages were matched. Prepare about 20 historical questions that real users have actually asked, and check two things for each one:

    1. Whether the retrieved passages are correct and are the latest version;
    2. Whether the generated answer stays within the scope of those passages.

    If the error occurs at the retrieval stage, adjust the chunking strategy and indexing approach first (granularity, overlap, hybrid retrieval weights, metadata filtering); changing only the prompt usually will not fix it. If the error occurs at the generation stage, then tighten the prompt constraints, lower the temperature parameter, or add refusal rules.

    Deployment Choices: Whether Data Can Leave the Internal Network Is the Dividing Line

    • Data can go to the cloud: use general-purpose cloud capabilities to validate quickly, including object storage for raw documents, a managed retrieval service to host the index, a container platform to host the orchestration service, and logging plus monitoring/alerting services to observe pipeline quality. The advantages are fast startup and good elasticity.
    • Data cannot leave the internal network: use a self-hosted approach where model inference, vector indexing, and log storage all happen inside the internal network, with a unified gateway handling permissions and auditing. The cost is higher operational overhead, so capacity and backups need to be planned in advance.

    Baidu AI Cloud offers general-category capabilities for both scenarios, and teams can choose a combination based on classification and compliance requirements rather than locking into a heavy architecture at the validation stage.

    Common Pitfalls and a Checklist

    • Pitfall 1: Choosing a framework before finding a use case. The correct order is scenario-driven, with a minimal pipeline.
    • Pitfall 2: Building only a vector index. Missing a keyword index causes clear accuracy loss on ID-style queries.
    • Pitfall 3: Treating chunking as a one-time decision. Chunking should iterate based on evaluation results.
    • Pitfall 4: Leaving hallucination entirely to the prompt. Retrieval errors must be fixed on the retrieval side.
    • Pitfall 5: Ignoring version governance. A data register and effective dates are prerequisites for long-term maintainability.

    Pre-launch checklist: data deduplicated and versions labeled; parsing covers tables; hybrid retrieval works; reranking is integrated; the prompt includes refusal and citation requirements; recall testing on 20 real questions passes; key numeric fields keep human review; logging and alerting are observable.

    Following this path, you can typically validate a working version from zero in a relatively short time, and concentrate later investment on the two areas that truly determine results: data governance and retrieval quality.