RAG in Practice: Knowledge Bases, AI Agents, and Workflow Design
A reliable retrieval-augmented generation (RAG) system requires more than document uploads and a language model. This article explains how to define business boundaries, govern knowledge sources, design retrieval and evidence-grounded answers, choose between workflows and agents, manage models, and evaluate quality, security, and operational reliability.
1. From Model Responses to Evidence-Grounded Answers
Organizations building AI question-answering applications often face three problems: the model does not know their internal information, cannot keep up with recent business changes, and struggles to explain the basis for its answers. Strong language understanding does not make a model’s training knowledge equivalent to an organization’s current, authoritative knowledge base.
Retrieval-augmented generation, or RAG, is a common approach to these problems. It retrieves relevant information from external knowledge sources based on a user’s question, organizes that information into context, and passes it to a model to generate an answer.
This mechanism does not guarantee correctness. Retrieval results may be incomplete, documents may be outdated, and the model may misinterpret evidence. A complete solution must therefore address knowledge processing, retrieval, generation, evaluation, and governance—not stop at “upload documents and start asking questions.”
At the application architecture level, knowledge bases, agents, workflows, and model management serve different purposes:
- Knowledge bases provide retrievable, traceable business facts.
- AI agents select tools and perform multistep tasks within authorized boundaries.
- Workflows organize business logic into controlled, observable execution processes.
- Model management maintains model configurations, access credentials, intended uses, and runtime policies.
These capabilities can work together, but they should not be treated as interchangeable. A simple policy lookup usually needs only retrieval and generation. A task involving several business systems may also require a workflow or an agent.
2. Define Business Boundaries Before Designing the Technical Pipeline
Before choosing technologies, establish what the application is expected to do.
For example, “look up the expense reimbursement policy” and “submit an expense claim automatically” may appear to belong to the same use case, but their risks differ substantially. The first primarily involves retrieving knowledge. The second also requires identity verification, field validation, writes to a business system, and user confirmation. Good question-answering performance does not establish that a system can safely execute actions.
Start by answering these questions:
- What types of questions will users ask?
- Which sources qualify as valid evidence?
- Which operations are read-only, and which change business state?
- What consequences could an incorrect answer cause?
- When evidence is insufficient, should the system ask for clarification, decline to answer, or escalate to a human?
- How will a successful answer or task execution be defined?
The answers shape the architecture. Time-sensitive inventory queries, for example, should not rely solely on a periodically updated document index. Internal policy question answering should prioritize effective dates, applicability, and version relationships.
A typical baseline pipeline is:
User question → Identity and permission checks → Question interpretation → Knowledge retrieval → Evidence selection → Context assembly → Model generation → Citation verification → Response
For more complex tasks, this pipeline can be extended with conditional branches, business tool calls, and human confirmation steps.
3. Building the Knowledge Base: The Foundation of System Quality
3.1 Establish Knowledge Sources and Ownership
Knowledge sources may include policies, business manuals, operating procedures, technical documentation, and reviewed question-and-answer records. Collecting documents is not just about volume. Each source should have an owner, an update timestamp, an applicability scope, and a validity status.
Different documents may give different answers to the same question. If an older operating manual conflicts with a recent notice, the system must recognize their version relationship rather than arbitrarily select a passage.
Basic knowledge governance rules should include:
- Confirming the source and applicability of new material.
- Preserving version information for revisions and updating how older versions are indexed.
- Removing withdrawn material from the default retrieval scope.
- Assigning reviewers to high-risk content.
- Ensuring document changes can trigger the corresponding index updates or rebuilds.
Knowledge governance is an ongoing operational responsibility, not a one-time activity before launch.
3.2 Document Parsing Must Preserve More Than Text
Documents often contain heading hierarchies, tables, footnotes, numbered clauses, and structures spanning multiple pages. These features affect meaning. A table value separated from its column heading and applicable conditions, for example, may be cited incorrectly by the model.
Parsing should preserve as much of the following as possible:
- Heading and section relationships.
- Table headers and their associations with cells.
- Clause numbers and cross-references.
- Page numbers or other source location information.
- Dates, applicable groups, conditions, and exceptions.
Scanned documents also require optical character recognition, with spot checks of important fields. Recognition errors that enter the index can repeatedly affect later answers.
3.3 Chunking Should Respect Semantic Boundaries
Because model context capacity is limited, retrieval systems usually split documents into smaller chunks. Oversized chunks can introduce irrelevant content, while undersized chunks can separate a rule from the conditions that govern it.
A practical approach is to split first by sections, paragraphs, and complete clauses, then subdivide further where necessary to meet length constraints. Moderate overlap can help, but it should not be used as a substitute for preserving document structure.
Each chunk should carry relevant metadata, such as the document identifier, section path, update timestamp, access permissions, and source location. This metadata supports retrieval filtering, answer citations, and troubleshooting.
4. Retrieval Design: From Similar Text to Valid Evidence
4.1 Semantic and Keyword Search Serve Different Needs
Semantic search works well when a question and its answer use different wording with similar meanings. A user might ask, “How much can I claim for a hotel on a business trip?” while the document refers to an “accommodation reimbursement limit.”
Keyword search is useful for exact names, clause numbers, internal identifiers, and specialized terminology. Relying only on semantic similarity may miss important results for these queries.
Depending on business requirements, the two approaches can be combined, with result fusion and reranking used to select candidate content. Whether this combination helps must be tested against real questions; architectural complexity alone is not evidence of better retrieval.
4.2 Enforce Permissions Within the Retrieval Pipeline
Knowledge access controls cannot depend solely on prompt instructions, nor should they be deferred until after answer generation. Candidate retrieval or result filtering should restrict evidence according to the user’s identity and document permissions. Downstream stages should receive only authorized content.
Shared caches require particular care. If a cache does not distinguish permission scopes, the system may return a result retrieved for a privileged user to someone with lower access rights. Authorization must cover indexing, retrieval, caching, and citation display.
4.3 Reranking Improves Relevance, Not Factual Validity
Initial retrieval generally produces a broad candidate set. Reranking then assesses how well each candidate passage matches the question.
High relevance, however, does not mean a source is currently valid. The system must also consider versions, dates, and applicability. Conflicting documents should be handled using explicit version rules. If the conflict cannot be resolved, the system should disclose it rather than force a single conclusion.
4.4 Control Noise When Assembling Context
Concatenating every retrieval result into a prompt can introduce duplication, mix unrelated topics, and bury useful evidence.
Context assembly should follow these principles:
- Prioritize evidence directly relevant to the question.
- Merge or remove duplicate passages.
- Preserve the conditions and exceptions needed to interpret rules.
- Attach clear source identifiers to each evidence passage.
- Allocate the available context budget among the question, evidence, and answer.
Complex questions can be divided into subquestions, with separate retrieval followed by evidence consolidation. This decomposition must also be checked to ensure that constraints from the original question are not lost.
5. Generation Controls: Make Answers Verifiable, Not Just Fluent
At generation time, the model should be instructed to answer from the available evidence and distinguish among three situations:
- The source explicitly states the answer.
- The answer is inferred from the source.
- The source does not provide the information.
Citations should point to actual source passages. Listing several document names at the end of an answer does not establish that every conclusion is supported. A stronger approach links key claims to their corresponding evidence and checks whether that evidence supports the claims.
When a question lacks necessary conditions, the system should ask for clarification first. If different policies apply by region, role, or time period, it should not silently assume the user’s circumstances.
The system should also be allowed to state clearly when evidence is insufficient. Declining to answer appropriately is part of quality control, not a failure of capability.
6. Agents and Workflows: Choose Based on Task Uncertainty
6.1 Prefer Workflows for Predictable Processes
Workflows suit business processes with clear steps and stable rules, such as:
Classify the question → Retrieve knowledge → Assess evidence sufficiency → Generate an answer or escalate to a human
Their main advantage is an explicit execution path that is easier to test, audit, and troubleshoot. Developers can inspect each node’s inputs, outputs, execution time, and failure reasons rather than observing only the final answer.
6.2 Use Agents When Tasks Require Dynamic Decisions
An agent can be useful when a task requires tool selection, retrieval strategy adjustments, or multiple rounds of analysis based on intermediate results. Greater autonomy, however, makes execution less predictable.
Agents need explicit boundaries, including permitted tools, maximum execution steps, timeouts, and resource budgets. Actions with external effects—such as submitting, deleting, modifying, or sending information—require permission checks and, where necessary, human confirmation.
Retrieved documents must be treated as data, not control instructions. Text such as “ignore previous requirements” must not change system permissions or execution rules.
6.3 Combine Both Without Requiring Full Automation
A common design embeds a constrained agent within a fixed workflow. The outer workflow handles identity verification, risk assessment, and result review. The agent performs query planning or evidence organization only within a designated stage.
This retains some flexibility without handing the entire business process to uncontrolled autonomous decision-making.
7. Model Management and Engineering Reliability
Model management involves more than configuring an endpoint. It should also track model versions, intended uses, context limits, and invocation policies. Different models may suit different tasks, so question classification, embedding generation, reranking, and final answer generation can be evaluated separately.
When changing embedding models, existing indexed vectors and new query vectors generally cannot be mixed directly. Compatibility must be checked, and the index rebuilt if necessary. Changing the generation model also requires renewed testing of citation adherence, behavior when evidence is insufficient, and response style.
Engineering design must account for timeouts, retries, rate limits, and fallback behavior. Read-only queries can usually be retried. Operations that change business state need an idempotency mechanism first to prevent duplicate execution.
Logs should contain enough information to trace the pipeline while limiting exposure of sensitive data. Access credentials must not be placed in prompts, ordinary logs, or document indexes. User content and retrieved evidence should be retained and redacted according to data governance requirements.
8. Evaluation and Deployment: Validate With Real Questions
8.1 Layered Evaluation Is More Useful Than a Single Score
Evaluate the following dimensions separately:
- Retrieval quality: Is the correct evidence retrieved, and is it ranked appropriately?
- Answer quality: Is the answer correct, complete, and faithful to the evidence?
- Citation quality: Can the source be located, and does it support the associated claim?
- Security behavior: Does the system permit unauthorized retrieval, disclose sensitive information, or make inappropriate tool calls?
- Operational performance: Do response times, error rates, and resource consumption meet business requirements?
User satisfaction should not be the only metric. A fluent but incorrect answer may still receive a favorable subjective rating.
8.2 Test Both Routine and Exceptional Cases
The test set should include common questions, ambiguous wording, questions with multiple conditions, unanswerable questions, outdated information, and permission boundaries. It should also cover conflicting sources, prompt injection, and tool failures.
Where possible, label each test with reference evidence and expected behavior. For an unanswerable question, the correct outcome may be a clarification request or a refusal—not a response that merely appears complete.
8.3 Roll Out Gradually and Close the Feedback Loop
Start with read-only, low-risk use cases to validate knowledge updates and retrieval quality, then introduce more complex tasks incrementally.
When an answer fails, identify whether the cause is a parsing error, poor chunking, insufficient retrieval, conflicting evidence, misinterpretation during generation, or a workflow defect. Locating the failing stage prevents repeated prompt changes that leave the underlying problem unresolved.
9. Conclusion
The core value of RAG is that it enables models to use external knowledge and makes answers easier to trace and verify. It does not automatically guarantee reliability, nor does it replace business rules, authorization systems, or human review.
A sustainable AI application treats knowledge governance, retrieval strategy, generation controls, workflow orchestration, agent boundaries, and model management as parts of one system. Begin with clear business objectives and a minimal pipeline that can be evaluated, then improve it using real questions. Clear boundaries, valid evidence, and diagnosable failures matter more to trustworthiness than accumulating features.
