Prompt Engineering & LLM Optimization for Developers · Lección

Fundamentos de Retrieval-Augmented Generation (RAG)

Aprenda cómo RAG fundamenta las respuestas de los LLM en sus propios documentos recuperando contexto relevante en el momento de la consulta e incorporándolo al prompt.

Lección 4 de 413 pasos

Fundamentos de Retrieval-Augmented Generation (RAG) es una lección gratuita de Prompt Engineering & LLM Optimization for Developers en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Prompt Engineering & LLM Optimization for Developers, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Prompt Engineering & LLM Optimization for Developers incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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.

Gratis para empezar

Aprende Prompt Engineering & LLM Optimization for Developers con un tutor de IA — gratis

Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.

Cursos
12
Lecciones
48

Preguntas frecuentes

¿La lección «Fundamentos de Retrieval-Augmented Generation (RAG)» es gratis?

Sí — el texto completo de «Fundamentos de Retrieval-Augmented Generation (RAG)» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Prompt Engineering & LLM Optimization for Developers, actualiza a CoddyKit PRO. El curso de Prompt Engineering & LLM Optimization for Developers incluye 4 lecciones en total.

¿Qué aprenderé en «Fundamentos de Retrieval-Augmented Generation (RAG)»?

Aprenda cómo RAG fundamenta las respuestas de los LLM en sus propios documentos recuperando contexto relevante en el momento de la consulta e incorporándolo al prompt. Practicas Prompt Engineering & LLM Optimization for Developers con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Prompt Engineering & LLM Optimization for Developers?

No se requiere experiencia previa. Prompt Engineering & LLM Optimization for Developers en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Fundamentos de Retrieval-Augmented Generation (RAG)»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Prompt Engineering & LLM Optimization for Developers?

Sí. Cada lección de Prompt Engineering & LLM Optimization for Developers incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Interacción con APIs de LLM (OpenAI, Anthropic)
  2. Conceptos básicos de LangChain y LlamaIndex
  3. Gestión y control de versiones de prompts
  4. Fundamentos de Retrieval-Augmented Generation (RAG)
← Volver a Prompt Engineering & LLM Optimization for Developers