RAG Architecture

Retrieval-augmented generation: grounding AI answers in your own trusted data.

Language models don't know your internal documents, policies or data, and they can make things up when they don't know. Retrieval-augmented generation (RAG) solves this by finding the most relevant pieces of your trusted content and giving them to the model along with the question, so the answer is grounded in real sources.

RAG is often the first serious enterprise AI pattern teams build, because it delivers value quickly without training a model.

The pipeline

A RAG system has two halves: preparing the knowledge, and answering questions with it.

Ingestion
Collect documents from sources such as wikis, PDFs, tickets and databases, and keep them in sync.
Chunking
Split documents into passages small enough to retrieve precisely, while keeping enough context.
Embedding and indexing
Convert chunks into vectors that capture meaning, and store them in a vector index.
Retrieval
Find the most relevant chunks for a question, often combining semantic and keyword search.
Generation
Give the retrieved chunks and the question to the model, and ask it to answer with citations.

Quality comes from retrieval

Most RAG problems are retrieval problems: the right passage wasn't found, or too much irrelevant text was included. Improvements usually come from better chunking, hybrid search, reranking the results, adding metadata filters, and cleaning up the source content itself.

Security and access control

A RAG system must never show someone content they aren't allowed to see. Carry permissions from the source systems into the index, and filter retrieval by the user's access. Classify sensitive data and decide whether it belongs in the index at all.

Retrieved documents can contain text that tries to give the model instructions. Treat them as untrusted content, not as commands.

Evaluating RAG

Build an evaluation set of real questions with expected answers and the sources that should support them. Measure retrieval (were the right passages found?) and generation (was the answer correct, complete and grounded in those passages?). Tools such as RAGAS help, and so does regular review by subject-matter experts.

RAG, fine-tuning or long context?

RAG is best when knowledge changes often or must be cited. Fine-tuning helps when you need a specific style, format or domain behaviour. Very long context windows let you include whole documents for some tasks, at higher cost per request. Many systems combine these approaches.

Keeping the knowledge fresh

A RAG system is only as current as its index. Schedule re-ingestion, remove documents when they are retired at the source, and show the last-updated date with each citation so users can judge freshness.

Give each knowledge domain an owner who reviews poor answers and fixes the underlying content. Often the best improvement to a RAG system is a better source document.

How to put it into practice

  1. Choose one well-defined knowledge domain with an owner, such as IT policies or runbooks.
  2. Clean up and de-duplicate the source content before indexing it.
  3. Build the pipeline with permissions carried through from the source.
  4. Require citations in every answer so users can check the source.
  5. Create an evaluation set of 30–50 real questions and measure retrieval and answer quality.
  6. Add feedback buttons and review poor answers weekly.

Common mistakes

  • Indexing everything, including outdated and contradictory documents.
  • Ignoring access control, so the assistant leaks restricted content.
  • Blaming the model for answers that are really retrieval failures.
  • Launching without an evaluation set, so quality can't be tracked.

How to measure progress

  • Retrieval hit rate: share of questions where the right source was found.
  • Answer accuracy and groundedness on the evaluation set.
  • User feedback and repeat usage.
  • Cost and latency per answer.

Go further