How does RAG work?

What is it?

This article walks through the full RAG lifecycle: how a document becomes searchable and how a question becomes a grounded answer. It connects the concepts you will learn in this learning path into one system.

The running example

A company uploads equipment manuals to its Knowledge Base.

A user asks:

"What maintenance is required after 500 operating hours?"

Here is what happens behind the scenes.

Phase 1 — Preparing knowledge (indexing)

When the manual PDF is uploaded:

PDF document ↓ Text extraction (read text from file; OCR if needed) ↓ Chunking (split into smaller pieces) ↓ Embedding (convert each chunk to a vector) ↓ Indexing (store vectors in vector database) ↓ Document status: Ready

Each stage maps to Noulek pipeline labels you see in Job detail: Extraction, Chunking, Embedding, Indexing.

Until indexing completes, the document is not available for retrieval.

Phase 2 — Answering a question (query time)

When the user submits the question:

Question: "What maintenance after 500 hours?" ↓ Query embedding (question converted to a vector) ↓ Vector search (find similar chunks in the index) ↓ Retrieval (top relevant chunks selected) ↓ Context assembly (chunks + question formatted for LLM) ↓ LLM generation ↓ Grounded answer with optional sources

The answer should reflect the manual's 500-hour maintenance section — not generic model knowledge.

Phase 3 — What the user sees

  • Search may show matching chunks or snippets directly.
  • Chat shows a conversational answer, often with source attribution listing which documents supported the response.

Why each step matters

Step If it fails
Extraction No text to index (corrupt file, unsupported format)
Chunking Pieces too large or too small for good retrieval
Embedding Cannot represent meaning numerically
Indexing Vectors not stored — nothing to search
Retrieval Wrong or empty chunks sent to LLM
Generation LLM error or answer ignores context

How this relates to Noulek

Noulek implements this pipeline in WordPress:

  1. Upload in Knowledge Base triggers the indexing pipeline.
  2. Settings → LLM and Vector DB must be connected for embedding and generation.
  3. Search & Chat widgets run retrieval + (for Chat) generation at query time.
  4. Activity log records failures at retrieval or LLM stages.

Track indexing in review document processing. Diagnose empty answers in Search or Chat no results.

Next concepts

Deepen each stage: