# Retrieval-Augmented Generation (RAG)

> VI: https://5ac.vn/wiki/rag/ · EN: https://5ac.vn/en/wiki/rag/ · lang: en · spec_as_of 2026-10-19 (spec no formal spec) · cluster C17

Retrieval-Augmented Generation wires a language model to a search step: pull the most relevant passages from your own document store into context before the model answers.

---
## Definition

Retrieval-Augmented Generation (RAG) wires a large language model to a search step: before answering, the system queries your document store — database, wiki, contracts — picks the most relevant passages and puts them into the model's context. The answer then rests on your actual documents, not only on knowledge compressed into the model's weights. The academic origin is Lewis et al. (2020, arXiv:2005.11401): the parametric memory of a pre-trained seq2seq model paired with non-parametric memory — a dense vector index over Wikipedia — reached through a neural retriever.

## Mechanism

The standard pipeline runs four steps: split documents into chunks, embed each chunk as a vector, retrieve the vectors closest to the question, then stuff the matched passages into the prompt for generation. 5ac's write-up of Andrew Ng's skills map states the reason RAG exists: most real applications cannot fit an entire body of knowledge into the context window, so something has to fetch exactly the relevant passages — RAG is the bridge between the model and the company's knowledge store.

Beyond basic RAG, the same framework flags two decisions. Vector retrieval is not the only grounding: Knowledge Graphs and Semantic Layers cover structured data instead. And you choose between injecting data into the prompt and pulling it on demand via tools, plus the document-processing pipeline behind that choice. When retrieval itself starts planning, checking itself and looping over several rounds, you have left base RAG behind — that is agentic RAG, covered in its own entry.

## Application context

The job RAG does in a business: answers grounded in the company's own material, with sources you can audit, instead of answers recalled from the internet. It is also a hiring signal: in Vietnam RAG ranks among the most sought-after skills — 5ac aggregates roughly 15,000 AI job postings against about 8,000 qualified candidates. One caveat straight from the skills map (Andrew Ng, August 2026, built on 10,000+ listings): RAG is not skill number one — evals is, because an unmeasured retrieval loop cannot be improved.

## Sources fetched

- [Andrew Ng's AI Engineering Skills Map: The 6 Skills That Actually Matter](/en/blog/andrew-ng-ai-engineering-skills-map/) — "Grounding Models with Data" beyond basic RAG, Vietnam hiring signals — accessed 2026-10-19
- [Andrew Ng's 4 AI Engineering Skills Map — What Every Developer Needs](/en/blog/ai-engineering-skills-map/) — RAG as the bridge between model and company knowledge — accessed 2026-10-19
- <https://arxiv.org/abs/2005.11401> — Lewis et al., the original RAG paper (v4) — verified via arXiv API 2026-10-19

## Related

- [Agentic RAG](/en/wiki/agentic-rag/)
- [Context engineering](/en/wiki/context-engineering/)
- [Agent memory](/en/wiki/agent-memory/)
