AI in Python: A Guide to Local LLMs, Embeddings, RAG and MCP

A map of the AI tutorials: run a local model with Ollama, embed and plot text, build a RAG pipeline, let an LLM choose a chart, and expose your own tools to Claude with an MCP server. Most need no API key.

To use a language model from Python, you can run one locally with Ollama (ollama.chat(), no API key) or call a hosted API such as Claude's. Everything else in these tutorials builds on that call: embeddings turn text into vectors, RAG feeds the closest passages to the model, tool calls let it choose a chart, and an MCP server hands your own functions to an AI app. Most tutorials here run on your own machine, and each one says what it needs.

Grid of six images from the AI tutorials: a bar chart of local model speed, a UMAP map of text embeddings, a line chart of RAG retrieval hit rate, a bar chart drawn from an LLM chart spec, an MCP chart of revenue by month and a Streamlit chat app

Which Order Should I Learn These In?

Step Question Tutorial
1. Run a model How do I call an LLM from Python without an account? Run Local LLMs with Ollama
2. Embed text How do I turn text into vectors and see how they cluster? Visualize Text Embeddings with UMAP and Plotly
3. Retrieve How do I make the model answer from my own documents? Build a Simple RAG Pipeline
4. Use tools How do I let a model make charts without running its code? Let an LLM Generate Charts from a DataFrame
5. Share tools How do I give Claude access to my data and charts? Build an MCP Server
6. Add an interface How do I put a chat window on top? Streamlit Chatbot

Steps 2 and 3 are the ones to read together: the RAG post uses the same embedding model as the embeddings post, and plotting your chunks with UMAP shows how they relate to each other.

What Does Each Tutorial Need?

Tutorial Ollama API key Notes
Ollama Yes No One model download of a few GB
Embeddings and UMAP Yes No A small embedding model, about 380 MB
RAG Yes No An embedding model and a chat model, about 3.7 GB together
Text to chart No For the live call Validating and drawing the spec runs offline. The Claude call follows the SDK's documentation but isn't run live in the post
MCP server No No The server never calls a model. Connecting it to Claude needs a Claude account
Streamlit chatbot No For the live call The first version uses a stand-in bot

Local Model, Hosted API, or No Model?

Local with Ollama Hosted API No model at all
Cost Free after the download Billed per token Free
Privacy Prompts stay on your machine Prompts go to the provider Nothing is sent
Quality Limited by the model your memory can hold Much larger models Not applicable
Use it for Experiments, private data, bulk simple tasks Hard reasoning, long documents Search, clustering and similarity with embeddings

Embeddings often replace a model call. Finding the document nearest to a question, grouping similar texts and checking for near-duplicates are all vector math once the texts are embedded.

How Do the Pieces Fit Together?

  • Embeddings map text to vectors, so similar meaning means a small angle between vectors.
  • RAG embeds your documents once, embeds each question, takes the closest chunks and puts them in the prompt. It is retrieval plus a model call, and the RAG post shows how to tell which half failed.
  • Tool calls let the model return structured data instead of prose. The chart post forces the model to fill in a JSON schema (chart type, columns, aggregation) and draws the chart with code you wrote, so nothing the model writes is executed.
  • MCP is the same idea turned around: you write the tools once, and any MCP client such as Claude can discover and call them.

Common Problems

Problem Fix Details
ConnectionError: Failed to connect to Ollama Start the Ollama app or run ollama serve Ollama
content is empty and done_reason is "length" Raise num_predict or set think=False Ollama
The model answers from memory, not from your documents Retrieve passages and answer from them, then check what was retrieved RAG
Retrieval misses the right passage Chunk by heading instead of fixed lengths RAG
The 2D embedding map looks tidier than the data is Compare how many nearest neighbors share a group in 2D and in the original vectors Embeddings
The model asks for a chart your code can't draw Validate the spec and give the model an "unsupported" answer Text to chart
The model only sees Error executing tool Raise ToolError, since other exceptions are hidden from it MCP server
ModuleNotFoundError for mcp.server.fastmcp In mcp 2.x the class is MCPServer in mcp.server.mcpserver MCP server

Which Tutorial Should I Start With?

Similar Topics