[Hands-On] Build RAG from Scratch

.. PLUS: Build, Train, and Run a ChatGPT-Like Model

In today’s newsletter:

  • Everything You Need to Build a RAG Application End-to-End

  • Hands-On Guide to Agentic AI from Andrew NG

  • Build, Train, and Run a ChatGPT-Like Model from Scratch

Reading time: 3 minutes.

This open-source repository gives you everything you need to learn and build a Retrieval-Augmented Generation (RAG) application from scratch.

It’s a complete, hands-on resource that walks through the entire RAG pipeline covering both the fundamentals and advanced techniques like multi-querying, routing, and custom retrieval workflows.

Each notebook is designed as a practical guide, helping you move step-by-step from understanding the basics to experimenting with real-world implementations.

Here’s what it covers:

  • Query Construction - Learn how to translate natural language into structured queries across SQL, Cypher, or vector search. (Text-to-SQL, Text-to-Cypher, Self-Query Retriever)

  • Query Translation - Improve retrieval quality through decomposition and rephrasing. (Multi-query, RAG-Fusion, Hypothetical Docs)

  • Routing - Dynamically select the most relevant database or embedding context for each query.

  • Retrieval - Use advanced techniques like Re-Rank, RankGPT, RAG-Fusion, or CRAG to refine results - even pull live data from external sources.

  • Indexing - Explore multi-representation embeddings, hierarchical summarization, and optimization methods. (RAPTOR, CoLBERT, fine-tuning)

  • Generation - Enhance response quality with iterative reasoning and retrieval loops using Self-RAG and RRR.

If you want to understand RAG inside out and build your own system from the ground up this repo is the perfect starting point.

Andrew NG released a new free course on Agentic AI.

This course focuses on building agentic systems that take action through iterative, multi-step workflows.

You’ll get hands-on experience with four core agentic design patterns:

  • Reflection: The agent evaluates its own output and identifies improvements.

  • Tool use: LLM-driven systems decide which functions to call, web search, calendars, email, code execution, and more.

  • Planning: Break tasks into sub-tasks for systematic execution.

  • Multi-agent collaboration: Coordinate multiple specialized agents to tackle complex tasks.

It also covers how to evaluate and debug these systems systematically so you can improve performance based on real data instead of guesswork.

Everything is implemented in raw Python, so you can see each step in detail and apply the concepts to any agentic framework or even build one from scratch.

Andrej Karpathy released nanochat, a minimal end-to-end implementation of a GPT-style chatbot covering training, fine-tuning, evaluation, and inference all in under 8,000 lines of PyTorch code.

Key Highlights:

  • Rust-based tokenizer for quick text handling.

  • Pretrains a GPT-style transformer on open web text

  • Midtrains on chat data, multiple-choice questions, and tool use to improve reasoning

  • Supports supervised fine-tuning (SFT) and evaluation on ARC, MMLU, GSM8K, and HumanEval

  • Optional reinforcement learning (GRPO) on GSM8K for reasoning tasks

  • Efficient inference with KV cache, prefill/decode, and a lightweight Python sandbox for tool use

  • Accessible via CLI or a ChatGPT-style web UI

  • Entire pipeline runs in a single script, from raw text to an interactive model

Even on modest GPU hardware, you can train a compact ChatGPT-style model capable of chatting, reasoning, and generating text.

It’s 100% open source.

That’s a Wrap

That’s all for today. Thank you for reading today’s edition. See you in the next issue with more AI Engineering insights.

PS: We curate this AI Engineering content for free, and your support means everything. If you find value in what you read, consider sharing it with a friend or two.

Your feedback is valuable: If there’s a topic you’re stuck on or curious about, reply to this email. We’re building this for you, and your feedback helps shape what we send.

WORK WITH US

Looking to promote your company, product, or service to 150K+ AI developers? Get in touch today by replying to this email.