Prompt Engineering & LLM Optimization for Developers · Lekcja

Podstawy Retrieval-Augmented Generation (RAG)

Naucz się, jak RAG ugruntowuje odpowiedzi LLM we własnych dokumentach, pobierając odpowiedni kontekst w chwili zapytania i przekazując go do promptu.

Lekcja 4 z 413 kroki

Podstawy Retrieval-Augmented Generation (RAG) to bezpłatna lekcja Prompt Engineering & LLM Optimization for Developers na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Prompt Engineering & LLM Optimization for Developers, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Prompt Engineering & LLM Optimization for Developers zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

The Knowledge Gap

An LLM only knows what it was trained on. It cannot answer questions about your private docs or recent events. RAG (Retrieval-Augmented Generation) closes this gap by fetching relevant text and putting it in the prompt.

The Core Idea

Instead of fine-tuning the model on your data, you retrieve the most relevant snippets at query time and let the model answer using them as context. Cheaper, faster to update, and easy to cite.

Step 1: Chunking

Documents are split into small chunks (a few hundred tokens each). Chunks small enough to be precise, large enough to keep meaning.

chunks = split(document, size=500, overlap=50)

Step 2: Embeddings

Each chunk is converted to a vector with an embedding model. Similar meanings produce nearby vectors, enabling semantic search.

vector = embed("Refunds are processed in 5 days.")
// -> [0.012, -0.43, 0.88, ...]

Step 3: The Vector Store

Vectors are saved in a vector database like Pinecone, Weaviate, or pgvector. It supports fast nearest-neighbor search over millions of chunks.

Step 4: Retrieve at Query Time

When a user asks a question, you embed the question and find the top-k most similar chunks.

q = embed(userQuestion);
results = store.search(q, topK=4);

Step 5: Augment the Prompt

The retrieved chunks are inserted into the prompt as context, and the model is told to answer using only that context.

Use only the context below to answer.
Context:
{retrieved_chunks}
Question: {user_question}

Grounding and Citations

Because the answer is built from real chunks, you can show citations back to the source documents, and you can instruct the model to say I do not know when the context lacks the answer.

Why Not Just Fine-Tune?

  • RAG updates instantly: change a doc, re-index, done.
  • Fine-tuning is slow and bakes knowledge in.
  • RAG gives traceable sources; fine-tuning does not.

Common RAG Problems

Poor chunking, weak embeddings, or retrieving too few chunks all hurt quality. If answers are wrong, inspect what was retrieved first; the issue is usually retrieval, not the model.

Improving Retrieval

  • Add overlap between chunks.
  • Use hybrid keyword + vector search.
  • Re-rank results with a cross-encoder.
  • Tune top-k for your context window.

Quick Check

Test your understanding of RAG.

Recap

RAG chunks documents, embeds them into a vector store, retrieves the most relevant chunks for each query, and augments the prompt. It grounds answers, enables citations, and stays current without retraining.

Bezpłatny start

Ucz się Prompt Engineering & LLM Optimization for Developers dzięki korepetycjom AI — za darmo

Pisz i uruchamiaj kod w przeglądarce, otrzymuj natychmiastową pomoc od korepetytora AI dostępnego 24/7 i kontynuuj naukę w sieci lub w aplikacji.

Kursy
12
Lekcje
48

Często zadawane pytania

Czy lekcja „Podstawy Retrieval-Augmented Generation (RAG)” jest bezpłatna?

Tak — pełny tekst „Podstawy Retrieval-Augmented Generation (RAG)” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Prompt Engineering & LLM Optimization for Developers, przejdź na CoddyKit PRO. Kurs Prompt Engineering & LLM Optimization for Developers zawiera 4 lekcji w sumie.

Co nauczysz się w „Podstawy Retrieval-Augmented Generation (RAG)”?

Naucz się, jak RAG ugruntowuje odpowiedzi LLM we własnych dokumentach, pobierając odpowiedni kontekst w chwili zapytania i przekazując go do promptu. Ćwiczysz Prompt Engineering & LLM Optimization for Developers z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Prompt Engineering & LLM Optimization for Developers?

Nie wymagamy żadnego doświadczenia. Prompt Engineering & LLM Optimization for Developers w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Podstawy Retrieval-Augmented Generation (RAG)”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Prompt Engineering & LLM Optimization for Developers?

Tak. Każda lekcja Prompt Engineering & LLM Optimization for Developers zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Interakcja z API LLM (OpenAI, Anthropic)
  2. Podstawy LangChain i LlamaIndex
  3. Zarządzanie promptami i wersjonowanie
  4. Podstawy Retrieval-Augmented Generation (RAG)
← Powrót do Prompt Engineering & LLM Optimization for Developers