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

> A guide to using LLMs from Python covering Ollama local models, text embeddings with UMAP, a RAG pipeline without a framework, LLM-generated charts from a DataFrame and an MCP server, with what each one needs and the order to read them in.

Source: https://www.pythoncharts.com/ai/ai-python-guide/ | Published: 2026-12-06 | Author: Alex Scott | Category: AI | Tags: llm, ollama, embeddings, rag, mcp, text-to-chart, guide

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](https://www.pythoncharts.com/ai/ai-python-guide/images/ai-hub-montage.png)

## 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](https://www.pythoncharts.com/ai/run-local-llms-ollama-python/) |
| 2. Embed text | How do I turn text into vectors and see how they cluster? | [Visualize Text Embeddings with UMAP and Plotly](https://www.pythoncharts.com/ai/visualize-text-embeddings-umap-plotly/) |
| 3. Retrieve | How do I make the model answer from my own documents? | [Build a Simple RAG Pipeline](https://www.pythoncharts.com/ai/simple-rag-pipeline-python/) |
| 4. Use tools | How do I let a model make charts without running its code? | [Let an LLM Generate Charts from a DataFrame](https://www.pythoncharts.com/ai/llm-generate-charts-from-dataframe/) |
| 5. Share tools | How do I give Claude access to my data and charts? | [Build an MCP Server](https://www.pythoncharts.com/ai/mcp-server-python/) |
| 6. Add an interface | How do I put a chat window on top? | [Streamlit Chatbot](https://www.pythoncharts.com/streamlit/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](https://www.pythoncharts.com/ai/visualize-text-embeddings-umap-plotly/) shows how they relate to each other.

## What Does Each Tutorial Need?

| Tutorial | Ollama | API key | Notes |
|---|---|---|---|
| [Ollama](https://www.pythoncharts.com/ai/run-local-llms-ollama-python/) | Yes | No | One model download of a few GB |
| [Embeddings and UMAP](https://www.pythoncharts.com/ai/visualize-text-embeddings-umap-plotly/) | Yes | No | A small embedding model, about 380 MB |
| [RAG](https://www.pythoncharts.com/ai/simple-rag-pipeline-python/) | Yes | No | An embedding model and a chat model, about 3.7 GB together |
| [Text to chart](https://www.pythoncharts.com/ai/llm-generate-charts-from-dataframe/) | 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](https://www.pythoncharts.com/ai/mcp-server-python/) | No | No | The server never calls a model. Connecting it to Claude needs a Claude account |
| [Streamlit chatbot](https://www.pythoncharts.com/streamlit/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](https://www.pythoncharts.com/ai/simple-rag-pipeline-python/) 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](https://www.pythoncharts.com/ai/run-local-llms-ollama-python/) |
| `content` is empty and `done_reason` is `"length"` | Raise `num_predict` or set `think=False` | [Ollama](https://www.pythoncharts.com/ai/run-local-llms-ollama-python/) |
| The model answers from memory, not from your documents | Retrieve passages and answer from them, then check what was retrieved | [RAG](https://www.pythoncharts.com/ai/simple-rag-pipeline-python/) |
| Retrieval misses the right passage | Chunk by heading instead of fixed lengths | [RAG](https://www.pythoncharts.com/ai/simple-rag-pipeline-python/) |
| 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](https://www.pythoncharts.com/ai/visualize-text-embeddings-umap-plotly/) |
| The model asks for a chart your code can't draw | Validate the spec and give the model an "unsupported" answer | [Text to chart](https://www.pythoncharts.com/ai/llm-generate-charts-from-dataframe/) |
| The model only sees `Error executing tool` | Raise `ToolError`, since other exceptions are hidden from it | [MCP server](https://www.pythoncharts.com/ai/mcp-server-python/) |
| `ModuleNotFoundError` for `mcp.server.fastmcp` | In `mcp` 2.x the class is `MCPServer` in `mcp.server.mcpserver` | [MCP server](https://www.pythoncharts.com/ai/mcp-server-python/) |

## Which Tutorial Should I Start With?

- **You want a model on your laptop today:** [Ollama](https://www.pythoncharts.com/ai/run-local-llms-ollama-python/).
- **You have documents and want answers from them:** [RAG](https://www.pythoncharts.com/ai/simple-rag-pipeline-python/).
- **You want to see what your texts have in common:** [embeddings with UMAP](https://www.pythoncharts.com/ai/visualize-text-embeddings-umap-plotly/).
- **You want people to ask questions of a DataFrame:** [text to chart](https://www.pythoncharts.com/ai/llm-generate-charts-from-dataframe/), then the [Streamlit chatbot](https://www.pythoncharts.com/streamlit/streamlit-chatbot/).
- **You want Claude to use your own data or charts:** [MCP server](https://www.pythoncharts.com/ai/mcp-server-python/).

## Similar Topics

- [Streamlit Tutorials: A Guide from First App to Deployment](https://www.pythoncharts.com/streamlit/streamlit-python-guide/)
- [Machine Learning Charts in Python: A Guide to Evaluating and Exploring Models](https://www.pythoncharts.com/machine-learning/machine-learning-python-guide/)
- [t-SNE vs UMAP in Python: How to Visualize High-Dimensional Data](https://www.pythoncharts.com/machine-learning/tsne-vs-umap-python/)
