Basi della Retrieval-Augmented Generation (RAG)
Impari come la RAG fondi le risposte degli LLM sui Suoi documenti recuperando il contesto pertinente al momento della query e inserendolo nel prompt.
Basi della Retrieval-Augmented Generation (RAG) è una lezione Prompt Engineering & LLM Optimization for Developers gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Prompt Engineering & LLM Optimization for Developers, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Prompt Engineering & LLM Optimization for Developers include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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.
Domande Frequenti
La lezione «Basi della Retrieval-Augmented Generation (RAG)» è gratuita?
Sì — il testo completo di «Basi della Retrieval-Augmented Generation (RAG)» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Prompt Engineering & LLM Optimization for Developers, passa a CoddyKit PRO. Il corso Prompt Engineering & LLM Optimization for Developers include 4 lezioni in totale.
Cosa imparerò in «Basi della Retrieval-Augmented Generation (RAG)»?
Impari come la RAG fondi le risposte degli LLM sui Suoi documenti recuperando il contesto pertinente al momento della query e inserendolo nel prompt. Eserciti Prompt Engineering & LLM Optimization for Developers con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Prompt Engineering & LLM Optimization for Developers?
Non è richiesta alcuna esperienza precedente. Prompt Engineering & LLM Optimization for Developers su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Basi della Retrieval-Augmented Generation (RAG)»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Prompt Engineering & LLM Optimization for Developers?
Sì. Ogni lezione Prompt Engineering & LLM Optimization for Developers include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Interazione con le API degli LLM (OpenAI, Anthropic)
- Nozioni di base su LangChain e LlamaIndex
- Gestione e versionamento dei prompt
- Basi della Retrieval-Augmented Generation (RAG)