liveBook · Manning

Chapter 16: Advancing to RAG, Web UI, and fine-tuning

What you will learn in chapter 16 of Build Applications with Local AI Models on a Mac

The chapter introduces advanced directions that build on the existing chatbot, including RAG, Open WebUI, agents, and fine-tuning.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces advanced directions that build on the existing chatbot, including RAG, Open WebUI, agents, and fine-tuning.

16.1 RAG: Retrieval-augmented generation

This section introduces RAG as a way to address a chatbot’s inability to answer from information outside its training data.

Key terms: training data, RAG, personal documents, internal knowledge base

16.1.1 What is RAG?

This subsection explains how RAG gives an AI relevant information from your documents before it answers a question.

Key terms: RAG, retrieve, context

16.1.2 How vectors and embeddings work

Explains how a RAG application represents text as vectors and uses their similarity to find relevant documents without relying on exact word matches.

Key terms: vector, embedding, embedding model, vector embeddings, similarity search

16.1.3 A simple RAG implementation

The section introduces a local ChromaDB example and explains how retrieving a relevant document helps ground an AI-generated answer.

Key terms: retrieval-and-generation, hallucinations, source material, ChromaDB, vector database, vectors, closest matches

16.1.4 Loading real documents for RAG

This section explains how to use document files in RAG and why longer documents should be split into retrievable chunks.

Key terms: my_documents, current working directory, .txt, .md, chunking, chunks, retrieval, context window

16.2 Using Open WebUI for a ChatGPT-like experience

Introduces Open WebUI as a ready-made interface for Ollama and explains when to choose it instead of a self-built Streamlit chatbot.

Key terms: Open WebUI, Ollama, local embedding, document-processing settings, Streamlit, state management

16.2.1 Using Open WebUI with Docker

This section explains how to run Open WebUI in Docker, connect it to local Ollama, and open it in a browser while making clear that Docker is optional.

Key terms: Docker, containers, Open WebUI, Python/Streamlit path, docker run, --add-host, -v, persistent storage, local Ollama server, Docker Desktop

16.2.2 Key features of Open WebUI

This section identifies Open WebUI’s main features for local AI chat and compares it with the Streamlit chatbot built earlier.

Key terms: Ollama models, conversation history, document upload, RAG, custom system prompts, user management, keyboard shortcuts, export conversations, Streamlit app

16.3 Custom model creation with Modelfiles

The section connects earlier Modelfile work to a study-assistant model and introduces the purpose of the TEMPLATE instruction.

Key terms: TEMPLATE instruction, conversation messages, underlying model

16.3.1 Creating a Modelfile

This subsection shows how a Modelfile becomes a custom Ollama model that can be listed and used in Ollama-connected apps.

Key terms: Modelfile, custom model, Ollama

16.3.2 Advanced Modelfile options

This section introduces Modelfile conversation templates and emphasizes that Modelfiles make custom model configurations reproducible and shareable.

Key terms: Modelfile, reproducible, shareable model configurations, TEMPLATE, conversation format, .System, .Prompt, .Response, .Messages

16.4 LangChain integration

Introduces LangChain as a way to assemble reusable components for more complex LLM applications, including those using Ollama.

Key terms: LangChain, building blocks, chains, Ollama

16.4.1 Installing LangChain

16.4.2 Basic LangChain with Ollama

This subsection places a basic LangChain connection to local Ollama in context: by itself it resembles direct use of the Ollama Python library, while its value comes from combining components.

Key terms: LangChain, Ollama Python library, components

16.4.3 Creating a chain

Explains how a chain passes data through a prompt template, an LLM, and an output parser.

Key terms: chain, prompt template, LLM, output parser, | operator, pipeline

16.4.4 Why LangChain matters

This section explains why LangChain’s reusable components matter and briefly identifies what its main components do.

Key terms: LangChain, building blocks, Prompts, Chains, Memory, Tools, Agents, Retrievers, RAG

16.5 Agentic AI patterns

This section defines an AI agent as an LLM that can choose and use tools, inspect their results, and decide what to do next.

Key terms: AI agent, LLM, tool

16.5.1 A simple agent concept

This subsection distinguishes a simple tool-layer demonstration from a full agent setup in which an LLM chooses whether and how to use a tool before answering.

Key terms: tool layer, Ollama model, reasoning-and-action loop, LLM, tools, tool’s output, final answer

16.5.2 The agent pattern: Evaluate and act

Explains how an agent chooses whether to use a tool and notes that agent performance depends on model capability.

Key terms: LLM, tool descriptions, tool selection, agents, gemma3:4b, 7B or larger models

16.5.3 Real-world agent use cases

This section illustrates where agents are useful by listing tasks that involve choosing tools, acting on external information, and evaluating results.

Key terms: agents, select tools, external information, evaluate the results

16.5.4 OpenClaw: The autonomous agent that drew major GitHub attention

This section introduces OpenClaw’s capabilities, architecture, local-model support, and security risks.

Key terms: OpenClaw, autonomous AI agent, messaging platform, gateway-plus-protocol model, gateway, protocol layer, ClawHub, LLM backends, Ollama, local agent

16.5.5 PicoClaw: An agent that fits in your pocket

PicoClaw shows how a lightweight agent can run on inexpensive hardware while relying on a separate LLM for inference.

Key terms: PicoClaw, Go binary, agent runtime, embedded hardware, model inference, edge device, LLM API, Ollama server

16.5.6 The API cost revolution: Why open models matter for agents

This section explains why repeated agent calls make costs important and how to compare hosted API pricing with local inference.

Key terms: autonomous agent, API call, privacy, control, cost, input tokens, output tokens, local inference, tool charges

16.6 Fine-tuning overview

Defines fine-tuning as further training a general pretrained model on your own data to give it specific knowledge or behaviors.

Key terms: fine-tuning, pretrained model, base model

16.6.1 When to fine-tune (and when not to)

This section frames fine-tuning as a powerful but usually unnecessary option and contrasts it with system prompts and RAG through an analogy.

Key terms: system prompts, RAG, fine-tuning

16.6.2 The GGUF format for quantized models

This section explains why a fine-tuned model is commonly exported as a quantized GGUF file for Ollama and how quantization levels trade memory use for quality.

Key terms: GGUF, fine-tuned model, Ollama, quantization, weights, inference, context, runtime overhead, quantization levels, q2_K

16.6.3 Fine-tuning workflow (high level)

Outlines the high-level path from training examples to a fine-tuned model running in Ollama.

Key terms: fine-tuning framework, GGUF, ollama create, Modelfile, test and iterate, training examples, input/output pairs, base model

16.6.4 Unsloth: The fine-tuning accelerator

Explains how Unsloth fine-tunes and exports a model for local use in Ollama, along with practical limits and handoff steps.

Key terms: Unsloth, GPU memory, GGUF export, hosted GPU, base model, GGUF, Ollama, Jupyter, Google Colab, Modelfile

16.6.5 GGUF quantization deep dive

This subsection identifies Q4_K_M as a common quantization choice for Ollama models because it balances quality with resource usage.

Key terms: Q4_K_M, quantization level, Ollama

16.7 Project ideas and learning resources

16.7.1 Ten project ideas

This section offers ten local-AI project ideas, grouped by difficulty, that extend familiar tools with new concepts.

Key terms: beginner projects, intermediate projects, advanced projects, system prompts, conversation history, RAG, ChromaDB, chained prompts, temperature settings, LangChain agents

16.7.2 Learning resources

The section points readers to resources for continued local AI learning and advises them to build on fundamentals rather than chase every new release.

Key terms: AI landscape, fundamentals, documentation, communities, books and courses, GitHub releases

16.8 Exercises

16.9 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 15: Common errors and troubleshooting Chapter 17: The open model revolution of 2026 →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.