AI ENGINEERING | LIVING GLOSSARY | #004
RAG — RETRIEVAL-AUGMENTED GENERATION
How AI Grounds Its Answers in External Knowledge
AIYING — Accomplishing with AI
Imagine asking an AI assistant about your company's latest travel reimbursement policy.
The language model may not have encountered that policy during training. Even if it has, the policy might have changed.
How can the assistant answer using the organization's actual documents rather than relying only on information encoded in the model?
One important solution is Retrieval-Augmented Generation (RAG).
1. What Is RAG?
Retrieval-Augmented Generation is an approach that combines information retrieval with generative AI.
Instead of generating a response solely from model parameters and the user's question, a RAG application retrieves relevant external information and provides it as additional context.
The model then uses that context to generate a response.
Question: "What is our company's hotel reimbursement limit?"
Retrieved source: The current company travel policy.
Generated response: An answer based on the relevant policy passage, ideally with a source citation.
RAG does not necessarily require a vector database. Retrieval may use keyword search, vector search, structured queries, hybrid search, or other methods.
↑ Back to contents2. Why RAG Matters
Language models have several limitations when used without access to relevant external information.
- They may lack knowledge of private organizational documents.
- Their learned information may be outdated.
- They may generate unsupported or incorrect statements.
- They may not know which sources justify an answer.
RAG helps address these challenges by making relevant external content available during generation.
| Without retrieval | With RAG |
|---|---|
| Answer relies on existing model context and learned parameters. | Answer can incorporate retrieved external information. |
| Private documents may be unavailable. | Authorized documents can be retrieved. |
| Source attribution may be difficult. | Retrieved passages can support citations. |
| Updates may require changes to supplied context or model behavior. | Updated indexed documents can be retrieved without retraining the model. |
Important: RAG can improve factual grounding, but it does not guarantee accuracy. Retrieval errors, outdated sources, misleading documents, and model mistakes can still occur.
↑ Back to contents3. How RAG Works
The term describes three connected operations.
Retrieve
Find information relevant to the user's question from an external source.
Augment
Add the retrieved information to the context supplied to the generative model.
Generate
Use the model to produce a response informed by the supplied information.
User Question
|
v
Retrieve Relevant Information
|
v
Combine Question + Evidence
|
v
Language Model
|
v
Generated Answer
|
v
Source References / Verification
Real systems may add query rewriting, metadata filtering, reranking, tool use, validation, and human review.
↑ Back to contents4. Understanding RAG Architecture
A typical document-based RAG application has two major workflows.
A. Knowledge preparation
- Collect approved source documents.
- Extract and clean their content.
- Divide long documents into suitable passages.
- Generate embeddings when using vector retrieval.
- Index passages in a searchable system.
- Preserve source references and access-control metadata.
B. Question answering
- Receive the user's question.
- Identify relevant sources using a retrieval method.
- Apply access controls and relevance filters.
- Optionally rerank retrieved passages.
- Construct a prompt containing the question and selected evidence.
- Generate an answer using the model.
- Attach source references and evaluate the result.
| Component | Engineering responsibility |
|---|---|
| Document pipeline | Prepare accurate and current source content. |
| Retrieval system | Find relevant information. |
| Context builder | Select evidence that fits the model's context budget. |
| Language model | Generate a useful response. |
| Verification layer | Check citations, relevance, and answer support. |
| Security controls | Prevent unauthorized information disclosure. |
5. Retrieval Quality and Grounding
RAG performance depends heavily on the quality of retrieved information.
Consider two possible retrieval results for a travel policy question:
Result A: An outdated travel reimbursement policy.
Result B: The currently approved reimbursement policy.
Both documents may be semantically similar to the question, but only one may be appropriate for the answer.
Therefore, similarity alone is insufficient.
Engineers must consider:
- Document relevance
- Source authority
- Document freshness
- Version control
- Access permissions
- Completeness of retrieved evidence
- Faithfulness of the generated answer
Retrieval evaluation and answer evaluation should be treated as distinct activities.
↑ Back to contents6. Industry Applications
| Application | How RAG contributes |
|---|---|
| Enterprise knowledge assistants | Answers questions using authorized company information. |
| Customer support | Uses product manuals and support documentation. |
| Developer assistants | Retrieves relevant code documentation and technical references. |
| Research assistants | Finds relevant publications and supporting passages. |
| Financial operations | Retrieves applicable policies and procedural guidance. |
| Education | Supports answers grounded in selected learning materials. |
In regulated or high-stakes applications, retrieval must be accompanied by appropriate verification, controls, and human oversight.
↑ Back to contents7. What Must an AI Engineer Decide?
A. What information should be retrievable?
Define approved knowledge sources, data ownership, and document update procedures.
B. Which retrieval method should be used?
Choose keyword, vector, hybrid, structured, or other retrieval approaches according to the task.
C. How should documents be divided?
Chunking affects retrieval precision and the completeness of context.
D. How much evidence should be supplied?
Too little evidence may omit necessary facts. Too much can increase cost and introduce irrelevant information.
E. How should conflicting documents be handled?
Define source priority, effective dates, version rules, and escalation procedures.
F. How should access permissions work?
Retrieval must enforce authorization before protected information is exposed to the model or user.
G. How should prompt injection be addressed?
Retrieved documents are data, not trusted instructions. Applications must avoid treating malicious document text as authority over system behavior.
H. How should the system be evaluated?
Measure retrieval relevance, answer faithfulness, citation support, latency, cost, and successful task completion.
8. Practical Industry Case: Company Policy Assistant
A company maintains HR, travel, procurement, and IT policies.
Employees ask questions such as:
The AI assistant must use the current approved policy and avoid disclosing restricted information.
Engineering workflow
- Collect current approved policy documents.
- Preserve version numbers and effective dates.
- Extract and index relevant passages.
- Associate each passage with its source and access permissions.
- Receive the employee's question.
- Retrieve authorized and relevant policy passages.
- Prioritize the applicable policy version.
- Generate an answer using the retrieved evidence.
- Include citations to the policy passages.
- Check whether the answer is supported.
- Escalate ambiguous or conflicting cases to an authorized human reviewer.
Expected benefit: Employees can locate policy information more efficiently while retaining traceability to approved documents.
Important limitation: The assistant should not invent reimbursement limits or assume that retrieved documents are complete.
↑ Back to contents9. Try It Yourself
Mini Project: Build a Small RAG Demonstration
Objective: Understand how retrieval changes the evidence available to a language model.
- Prepare five short fictional company policy documents.
- Include a travel reimbursement policy with a specific limit.
- Ask an AI model a question about the limit without providing the documents.
- Record the response and whether it expresses uncertainty.
- Retrieve the relevant policy passage using manual selection or a search tool.
- Supply that passage as context and ask the same question.
- Request a citation to the supporting passage.
- Check whether the response is fully supported.
- Replace the policy with an updated version and repeat the test.
- Try a question that the documents cannot answer.
Reflection questions
- Did retrieval improve the factual support for the answer?
- Did the model cite the correct passage?
- What happened when evidence was missing?
- How did the system respond to an updated policy?
- What controls would be necessary for real company documents?
Success criterion: The assistant should answer supported questions from the provided evidence and acknowledge when the evidence is insufficient.
↑ Back to contents10. Connected Glossary Terms
- Token: Determines the information budget available to the model.
- Embedding: Represents information numerically for semantic retrieval.
- Vector Database: Stores and searches vectors in many RAG architectures.
- Context Window: Limits how much retrieved evidence can be supplied.
- Prompt Engineering: Helps specify how the model should use evidence.
- Evals: Measures retrieval and generation quality.
- Guardrails: Helps enforce application policies and boundaries.
Previous lessons:
Next lesson: #005 — Context Window.
↑ Back to contents11. Living Update
Editorial baseline: November 2026
RAG engineering continues to develop beyond basic vector retrieval followed by a single model response.
Important design directions include:
- Hybrid retrieval combining lexical and vector search
- Query rewriting and decomposition
- Reranking and relevance optimization
- Adaptive retrieval based on question complexity
- Structured and graph-based retrieval
- Multimodal retrieval
- Source freshness and version-aware retrieval
- Retrieval and answer evaluation
- Security against prompt injection and unauthorized access
These techniques should be selected according to measured application needs rather than adopted solely because they are new.
Living Glossary note: Revisit this entry as retrieval techniques, model capabilities, and evaluation practices evolve.
↑ Back to contents12. Key Takeaway
But evidence must be relevant, current, authorized, and correctly interpreted.
The engineer's responsibility is not simply to retrieve information. It is to design a system that uses evidence appropriately and produces answers that users can verify.
Think like an AI engineer: Can we show not only what the AI answered, but why the available evidence supports that answer?
↑ Back to contents13. References and Further Reading
- Lewis et al. — Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
- LangChain — Documentation
- LlamaIndex — Documentation
- OpenAI — Retrieval Guide
- OWASP — LLM Application Security Risks

