Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Workflow recipe

Chat with private documents on a local model

Chat with PDFs locally: ask questions about contracts, notes and PDFs with Ollama and Open WebUI or LM Studio on your own computer, and check nothing leaves it.

By Checked Beginner1 h 30 min6 steps
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On this page

To chat with PDFs locally, run a chat model and an embedding model in Ollama, give the model enough context, install Open WebUI with the features that phone home switched off, load your documents into its built-in search, and ask questions that force citations. Then confirm that nothing leaves the machine before you trust it with anything private.

Some documents should not be pasted into a cloud chatbot: an employment contract, medical letters, a client’s financials, a draft you are not allowed to share. A model running on your own computer can still read them and answer questions, and with the right setup nothing is sent anywhere.

This recipe uses Ollama to run the models and Open WebUI as the chat interface, because Open WebUI has document search built in and shows which passage each answer came from. LM Studio, a single desktop app, is the simpler alternative and is covered in “Variations”. Expect answers that are slower and less polished than the large cloud models. For finding and summarising what your own documents say, a small local model is usually good enough.

TerminalAbout 15 min

1. Download a chat model and an embedding model

Install Ollama from its website if you have not already, then pull two models: one to answer questions and one to turn text into vectors for search.

ollama pull gemma4:e4b
ollama pull embeddinggemma
ollama list

gemma4:e4b suits a 16 GB machine. On 8 GB, try gemma4:e2b; with a strong GPU, a larger model gives better answers. The Ollama tutorial has a sizing table.

TerminalAbout 10 min

2. Give the model enough context

Ollama picks a default context length from your graphics memory, and on GPUs with less than 24 GB it is 4,096 tokens. That is roughly three pages of text, and document search pushes retrieved passages into that same window. With the default, the model often never sees the passage that holds the answer.

Raise it when you start the server (quit the Ollama desktop app first, or change the context slider in its settings instead):

OLLAMA_CONTEXT_LENGTH=16384 ollama serve

More context uses more memory. If the machine starts swapping, go back to 8192. Check what the model actually got with ollama ps, in the CONTEXT column.

TerminalAbout 15 min

3. Install Open WebUI and switch off what phones home

Install Open WebUI in its own Python environment. Its documentation says Python 3.11 or 3.12; 3.13 is not supported.

python3.12 -m venv ~/open-webui-env
source ~/open-webui-env/bin/activate
pip install open-webui

A default install makes a few outbound calls: a version check to GitHub, a model-list request to the default OpenAI connection, and an update check for its local embedding model on Hugging Face. Turn those off when you start it:

export ENABLE_VERSION_UPDATE_CHECK=false
export ENABLE_OPENAI_API=false
export RAG_EMBEDDING_MODEL_AUTO_UPDATE=false
open-webui serve

Open http://localhost:8080 and create the first account, which becomes the admin. This account is stored on your machine.

The pip route keeps everything on localhost. If you use Docker instead, Open WebUI’s documentation explains that Ollama must then listen on all network interfaces so the container can reach it, which also exposes it to your local network unless a firewall blocks it.

Open WebUIAbout 15 min

4. Use Ollama for embeddings and load your documents

In Open WebUI, open the admin Settings, then Documents. Set the embedding model engine to Ollama and the model to embeddinggemma, and save. Your documents are now embedded by Ollama on your machine.

Then go to Workspace, Knowledge, create a knowledge base (for example “Contracts 2026”) and upload your files. PDFs that contain real text work best. Scanned pages without a text layer come out empty or garbled; run them through OCR first.

In a chat, type # and pick the knowledge base or a single file from the list that appears, then ask your question. Pick gemma4:e4b as the model at the top of the chat.

Open WebUIAbout 20 min

5. Ask questions that force citations

Local models are more likely than large ones to fill gaps with plausible guesses. Ask in a way that makes guessing visible:

Question with citations · Open WebUI with a local model
Answer using only the attached documents. Question: [YOUR QUESTION, E.G. WHAT IS THE NOTICE PERIOD IN MY CONTRACT?] Quote the exact sentence that supports your answer and name the document it comes from. If the documents do not answer the question, say "Not found in the documents" and stop. Do not use general knowledge.

Open WebUI lists the sources under each answer. Click them and check that the quoted sentence is really there and says what the answer claims. Start with your three questions whose answers you already know. If the model gets one wrong, see “When it goes wrong” before trusting it with questions you cannot check.

Summaries of a whole long document are the weak spot of this setup, because search only feeds the model a few passages. For a full summary, either ask section by section or use a model and context length big enough to read the whole file.

TerminalAbout 15 min

6. Confirm nothing leaves the machine

Do not take privacy on trust. Two quick checks:

First, disconnect from the network (turn off Wi-Fi) and ask another question. If the answer still arrives, the model and search run locally.

Second, with the network back on, list the connections the processes hold open while you chat:

# macOS and Linux
lsof -i -P -n | grep -E "ollama|open-webui|python" | grep -v "127.0.0.1\|localhost\|\[::1\]"

You should see nothing, or only connections you can explain. Also check in Open WebUI’s admin settings that no external connection (OpenAI, web search, image generation) is switched on. Keep the virtual environment and the Ollama models updated yourself, since you turned off the automatic checks.

Check it worked

Verification checklist

0 of 6 done

When it goes wrong

If answers ignore the document or say “not found” when the text is there, the context is probably too small (step 2), or the PDF has no text layer. Open the PDF and try to select a sentence. If you cannot, it is a scanned image. The pdf skill and OCR tools can extract text from it before upload.

If the answer is wrong but cites a real passage, retrieval found the wrong chunk. Use the words the document itself uses in your question, upload fewer documents per knowledge base, or reduce the chunk size under the admin Documents settings and re-index.

If everything is very slow, the model is too big for your memory and is running partly on the CPU. ollama ps shows the split. Use a smaller model or a smaller context.

If you changed the embedding model after uploading files, re-index the knowledge base. Vectors from two different embedding models cannot be compared, and search quietly returns poor matches.

Variations

With LM Studio, download a model inside the app, start a chat and attach a .pdf, .docx or .txt file. If the document fits in the model’s context, LM Studio adds it in full; if not, it switches to retrieval and picks relevant passages. It is the quickest setup, with fewer controls over how documents are split and searched.

Jan is another open-source desktop app for local models, with a simpler interface. Check the current version’s documentation for how it handles attached files.

For a team, run Open WebUI on one internal server with Ollama, behind your company login, so documents never leave your network. That is an IT project rather than an afternoon: plan accounts, backups and updates first. To build your own pipeline in code instead, follow RAG pipeline in a day.

Running local models with Ollama covers model choice and memory in more depth, and the local model servers cheat sheet lists start commands and ports. To see what Open WebUI’s document search does underneath, read RAG fundamentals, or build your own retrieval in a RAG pipeline in a day. The local models and fine-tuning learning path goes further. Browse more AI workflow examples.

Outcome and tools

Outcome
A private chat app on your computer that answers questions about your own documents with citations, with outbound connections you have checked and switched off.
For
Non-technical, Developers, Team leads
Agent Skills
  • Run local models with Ollama

    Install Ollama, run an open-weight model on your own machine, call it from scripts over the local API and choose a model size your hardware can handle, offline.

    TutorialBeginner30 min

  • RAG fundamentals: retrieval before generation

    What RAG is and how retrieval-augmented generation works, when it beats long context or fine-tuning, and a minimal working pipeline in about 80 lines of Python.

    TutorialBeginner30 min

  • RAG pipeline in a day with Postgres and pgvector

    Ingest your documents, answer with citations and measure retrieval against 20 questions written first.

    WorkflowIntermediate1 day7 steps

  • RAG vs long context vs fine-tuning: how to choose

    What each approach changes, what it costs, where it fails, and a practical order to try them in before you commit to one.

    Article

  • Local models and fine-tuning

    Run open-weight models on your own hardware, use them on private documents, decide when fine-tuning beats RAG or long context, and try a small LoRA fine-tune.

    Learning pathIntermediate11 h8 steps

Back to top