Lesson 1 — Fondamentaux

Introduction to RAG

30min

A large language model (LLM) such as Gemini knows a lot… but nothing about your internal documents. Retrieval-Augmented Generation (RAG) fixes this by retrieving relevant passages from a document base at question time and injecting them into the prompt1.

Architecture at a glance

flowchart LR
    U["User"] -->|question| A["ADK agent (Cloud Run)"]
    A -->|search query| R["RAG Engine"]
    subgraph Ingestion
        GCS[("Cloud Storage")] --> P["Parsing and chunking"]
        P --> E["Embeddings text-embedding-005"]
        E --> V[("Vector index")]
    end
    R --> V
    V -->|top-k passages| A
    A -->|prompt + context| G["Gemini 2.5 Flash"]
    G -->|cited answer| U

The same diagram, illustrated:

Architecture

Two flows coexist:

  1. Ingestion (offline): documents are split into chunks, turned into vectors and indexed.
  2. Query (online): the question is embedded, the closest chunks are retrieved and handed to the model.

RAG, fine-tuning or long context?

ApproachFresh dataCostCitationsWhen to use
RAG✅€€✅Evolving document base
Fine-tuning❌€€€❌Style, format, domain vocabulary
Long context✅€€€€⚠️Few documents, one-off analysis
Prompt only❌€❌General knowledge

Your progress

  • Understand the RAG principle
  • Identify the ingestion and query flows
  • Compute a cosine similarity
  • Create your first corpus
  • Deploy the agent on Cloud Run

Footnotes

  1. Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, NeurIPS 2020 — https://arxiv.org/abs/2005.11401. ↩

Next