RAG Implementation: Six Steps to a Working LLM Pipeline

    Build a practical retrieval-augmented generation pipeline by starting with a focused use case and trusted documents. This guide covers document preparation, chunking, hybrid retrieval, indexing, reranking, cited answers, and testing with real questions, along with the permissions, versioning, and validation needed for a controlled rollout.

    Getting retrieval-augmented generation (RAG) into production quickly does not require building a comprehensive platform first. The priority is to make one real question-answering workflow work: retrieve relevant passages from controlled sources before the model answers, provide those passages alongside the question, and require answers that can be traced back to their sources.

    Knowledge updates primarily come from replacing or incrementally updating documents and indexes, rather than retraining the model each time. Published research offers an illustrative comparison: indexes built from encyclopedia content from different years were used to answer questions about changes in leadership positions. When the index year matched the year of the facts being queried, accuracy was around 70%; when they did not match, it fell to single digits.

    The lesson is that what a model knows can be separated from what the current source material contains. For implementation, prioritize sources that are up to date, searchable, and citable.

    Define the Use Case Before the Architecture

    Good initial RAG use cases have answers mainly contained in internal documents, a relatively narrow question scope, and errors that business users can recognize. Examples include policy questions, product documentation, error-code explanations, contract clause lookup, and operations manual Q&A.

    Open-ended chat, tasks requiring substantial reasoning or computation, and questions whose answers are not in the documents are poor choices for a first release.

    Define four things when selecting a use case:

    • Who will ask questions?
    • Which sources may the system consult?
    • What is the cost of an incorrect answer?
    • Must the answer identify the original source location?

    A narrower scope makes chunking, evaluation, and access control easier. Serving one department and one document category first is more likely to produce useful results within one or two weeks than connecting every knowledge base at once.

    If the documents are permitted to leave the internal network, a mature cloud platform’s object storage, vector retrieval, and model inference services are sufficient for validation. The source workflow cites Baidu AI Cloud as one example of this general service combination; platform selection should depend on availability and the organization’s data requirements. Focus on stable retrieval and citations rather than comparing console interfaces.

    If documents must remain within the organization’s environment, deploy the same pipeline internally: parsing, chunking, vector indexing, retrieval, and generation. Use the same acceptance criteria for both deployment approaches so that cloud and internal results remain comparable.

    Six Steps to Build a Minimum Viable Pipeline

    1. Prepare the Documents

    Include only documents authorized for the selected use case. Remove outdated versions and duplicates, and record each document’s title, version date, owner, and intended audience.

    If obsolete and current provisions are indexed together, retrieval may place both in the context, making it easy for the model to mix them in its answer.

    Scanned documents and image-based PDFs need optical character recognition or conversion to selectable text if text cannot otherwise be extracted. Without usable text, downstream chunking accomplishes little.

    2. Parse and Chunk the Content

    Extract body text, heading hierarchies, and tables from PDFs, office documents, and web pages. Preserve section paths so answers can identify the relevant section.

    Chunking requires a balance between completeness and focus:

    • Chunks that are too large consume context with irrelevant sentences and dilute semantic similarity.
    • Chunks that are too small separate definitions from exceptions, leaving the model without the necessary conditions.

    A practical starting point is to split by headings or natural paragraphs, with one or two sentences of overlap between adjacent chunks to reduce abrupt breaks.

    Preserve tables as complete tables where possible, or retain the headers when splitting them by row. Do not turn individual cells into disconnected, meaningless fragments.

    Exact identifiers—such as error codes, model numbers, and clause numbers—often do not work well with vector similarity alone. A vector search may retrieve a passage about error codes in general rather than the specific code requested. Retain keyword or original-text search alongside vector retrieval, merge the results at query time, and then rerank them.

    3. Generate Embeddings and Build the Index

    Generate an embedding for each chunk and store filterable metadata, including:

    • Document ID
    • Version date
    • Department
    • Confidentiality classification
    • Language

    Use the same embedding model for document ingestion and user queries. If the embedding model changes, recompute embeddings across the indexed collection; otherwise, distances are no longer comparable.

    Separate indexes by use case rather than placing every department’s documents in one large collection. This makes permission isolation and evaluation easier.

    4. Retrieve and Rerank

    Embed the user’s question and retrieve a set of candidate chunks. If keyword search is available, merge and deduplicate its results with the vector results.

    Use a reranking model to rank candidates by how directly they answer the question, then pass only the top few passages to the generation model. Too many passages increase cost and can encourage the model to piece together an answer from irrelevant text.

    Apply filters such as department, validity period, and confidentiality classification during retrieval. A prompt saying “do not use outdated documents” is not a substitute for retrieval filtering.

    5. Generate Answers with Source Citations

    Make the prompt requirements explicit:

    • Answer only from the supplied passages.
    • If the passages are insufficient, say that the answer is unknown and identify the missing type of information.
    • Tie citations to passage identifiers or sections.
    • Do not invent clause numbers that were not provided.

    Use a low temperature to limit free-form invention.

    After generation, perform a lightweight validation check: can the numbers, monetary amounts, dates, and model identifiers in the answer be found verbatim in the cited passages? If they do not match, return a “manual confirmation required” response or decline to answer.

    6. Test Retrieval with Real Questions

    Before launch, collect about 20 questions that users have actually asked. Include common phrasing, abbreviations, typos, and boundary questions whose answers are absent from the source material.

    For each question, first check whether the retrieved passages contain the evidence needed to answer it. Then check whether the final answer goes beyond those passages.

    When retrieval fails, prioritize changes to chunking, metadata, hybrid search, and reranking. Prompt changes alone rarely fix information that was never retrieved.

    Once the system passes these checks, release it to a small share of users. Turn unanswered questions, negative feedback, and human-rewritten answers into additional test cases.

    The workflow can be summarized with vendor-independent pseudocode:

    1. chunks = parse_and_split(docs) # Preserve sections and versions
    2. index.upsert(embed(chunks), metadata)
    3. hits = hybrid_search(query, filters) # Vector + keyword search
    4. hits = rerank(query, hits)[:k]
    5. answer = llm(query, hits, cite=True, abstain_if_missing=True)
    6. assert numbers_in_answer_appear_in(hits)

    Where RAG Can Still Fail

    RAG reduces fabrication based on a model’s parametric memory; it does not eliminate every error.

    When retrieval returns nothing or retrieves the wrong material, the model may still fill gaps using general knowledge. This is especially likely when the prompt does not clearly require abstention or when the context contains only a partially relevant statement.

    For prices, inventory, legal figures, and medical dosages, business reviewers should verify the original source even when an answer and its citations look plausible.

    Permissions must be enforced through user-specific retrieval filters. Do not retrieve confidential material first and rely on the model to avoid disclosing it.

    At a minimum, record:

    • The user’s question
    • Retrieved documents and their scores
    • Passages sent to the model
    • The model’s answer
    • Whether citations resolve to their sources
    • Whether the user follows up or gives negative feedback

    Once version dates are stored in the index, rollback means restoring the previous document version and rebuilding the affected chunks—not rolling back the entire model.

    Following this sequence, a focused implementation can often be completed in roughly a week: choose one Q&A use case, clean a small set of authoritative documents, combine hybrid retrieval with cited generation, and validate against 20 questions.

    Once results are stable, expand document types, access controls, and multi-turn conversations. Treat evaluation questions and document versions as deliverables alongside code. That discipline helps prevent RAG systems from repeatedly shifting between convincing demos and unreliable production answers.