chapter sixteen

16 Advancing to RAG, Web UI, and Fine-Tuning

 

This chapter covers

  • Retrieval-Augmented Generation (RAG) for answering questions from your own documents
  • Open WebUI: a free, ChatGPT-like interface running locally with Docker
  • Custom Modelfiles for baking personality and parameters into named models
  • LangChain integration for building complex LLM pipelines
  • Agentic AI patterns, including OpenClaw and PicoClaw
  • Fine-tuning with Unsloth: from training data to a custom model in Ollama

Your chatbot is running. It handles conversations, streams responses, and supports customizable system prompts. That is a solid foundation -- but it is also a starting point. The techniques in this chapter will show you what becomes possible when you build on that foundation.

16.1 RAG: Retrieval-Augmented Generation

Your chatbot is smart, but it only knows what was in its training data. It cannot answer questions about your personal documents, your company's internal knowledge base, or anything that happened after the model was trained. RAG changes that.

16.1.1 What Is RAG?

The idea is simple. Before asking the AI to generate an answer, you first retrieve relevant information from your own documents. Then you give that information to the AI as context, along with the user's question (figure 16.1). The AI generates an answer based on both its general knowledge and the specific documents you provided.

16.1.2 How Vectors and Embeddings Work

16.1.3 A Simple RAG Implementation

16.1.4 Loading Real Documents

16.2 Open WebUI for a ChatGPT-Like Experience

16.2.1 Option A: Use Open WebUI with Docker

16.2.2 Option B: Skip Open WebUI

16.2.3 Key Features of Open WebUI

16.3 Custom Model Creation with Modelfiles

16.3.1 Creating a Modelfile

16.3.2 Advanced Modelfile Options

16.4 LangChain Integration

16.4.1 Installing LangChain

16.4.2 Basic LangChain with Ollama

16.4.3 Creating a Chain

16.4.4 Why LangChain Matters

16.5 Agentic AI Patterns

16.5.1 A Simple Agent Concept

16.5.2 The Agent Pattern

16.5.3 Real-World Agent Use Cases

16.5.4 OpenClaw: The Autonomous Agent That Drew major GitHub attention

16.5.5 PicoClaw: An Agent That Fits in Your Pocket

16.5.6 The API Cost Revolution: Why Open Models Matter for Agents

16.6 Fine-Tuning Overview

16.6.1 When to Fine-Tune (and When Not To)

16.6.2 The GGUF Format

16.6.3 Fine-Tuning Workflow (High Level)