How to Build a Private Local RAG Chatbot for Your PDFs Using Ollama

Every time you upload a PDF to a cloud chatbot, you hand your documents to someone else’s server. For contracts, research papers, medical records, or company reports, that is a risk most people should not take. A local RAG chatbot solves it: the AI runs on your own computer, your PDFs never leave your machine, and there are no API bills at all.

  • Zybitai Editorial Team
  • November 2026
  • 9 Minutes
Private Local RAG Chatbot for PDFs

RAG stands for Retrieval Augmented Generation. Instead of asking a language model to answer from memory, your chatbot first searches your own documents for the relevant passages, then lets the model answer using only what it found. The result is a chatbot that answers questions about your PDFs with citations, and that cannot leak your files because nothing ever leaves your laptop. This guide builds one with Ollama, LangChain, and ChromaDB, all free and open source, in about an afternoon.

What RAG Actually Is, in Plain English

RAG is a simple two step trick. First, your documents are split into small chunks and converted into numbers called embeddings, which capture meaning in a way a computer can compare. Second, when you ask a question, the system finds the chunks most similar to your question and hands them to the language model as context. The model then answers from your documents, not from its training data.

This matters because language models hallucinate when they do not know something. A plain chatbot asked about your company handbook will invent a confident sounding answer. A RAG chatbot asked the same question will search the handbook first, quote the real passage, and say it does not know if the answer is not there. Research teams at Meta, who introduced RAG in a 2020 paper, showed that grounding answers in retrieved documents sharply improves factual accuracy, and every serious document chatbot since, from NotebookLM to enterprise search tools, uses the same pattern.

A concrete example: a lawyer loads 200 pages of contracts into a local RAG chatbot and asks which agreements renew in March. The chatbot retrieves the renewal clauses, cites the page numbers, and answers in seconds, work that used to take an afternoon of manual searching. The takeaway: RAG turns a general chatbot into a specialist that knows your documents.

The Stack: Ollama, LangChain, ChromaDB, and Python

Ollama logo on a grey background

The stack has four pieces, and each one is free. Ollama runs large language models locally on your machine with almost no setup. LangChain wires the pieces together, handling document loading, chunking, and the retrieval chain. ChromaDB is a lightweight local vector database that stores your document embeddings on disk. Python is the glue holding it all together.

For hardware, you need less than you think. A machine with 16 GB of RAM runs a capable 8 billion parameter model comfortably, and an 8 GB machine can run smaller quantized models such as Llama 3.2 1B. A dedicated GPU speeds up answers but is not required. The whole setup costs nothing: Ollama is free, the models are free to download, and ChromaDB and LangChain are open source. Compare that with cloud document AI, where a single heavy month of API calls can cost more than a new laptop accessory, and the local route pays for itself immediately.

If you are new to running models locally, start with our guide to running DeepSeek and Llama models on a low end PC before you begin. The takeaway: four free tools and a normal laptop are all you need.

Step 1: Install Ollama and Pull Two Models

Download Ollama from ollama.com and install it for Windows, macOS, or Linux. Then pull two models from your terminal: a chat model to generate answers, and an embedding model to turn text into vectors.

ollama pull llama3.1:8b
ollama pull nomic-embed-text

Llama 3.1 8B is Meta’s open model and a solid default for chat. If your machine has only 8 GB of RAM, pull the smaller llama3.2:1b instead and upgrade later. The embedding model nomic-embed-text is made by Nomic AI and is the standard free choice for local RAG. Both downloads together are under 10 GB, and Ollama serves them on your own machine at localhost:11434 by default, which means nothing leaves your computer.

Verify the install by running ollama list. You should see both models. The takeaway: two downloads, and your private AI engine is running.

Step 2: Set Up Your Python Environment

Create a virtual environment and install the libraries. Python 3.10 or later works, and the install takes a few minutes.

python -m venv rag-env
source rag-env/bin/activate
pip install langchain langchain-community langchain-ollama
pip install chromadb pypdf

On Windows, activate with rag-env\Scripts\activate. LangChain v1 changed how retrieval chains work: the old RetrievalQA chain is deprecated in favour of an agent plus middleware architecture, but the classic chain still works fine for a first project, and the freeCodeCamp tutorial from 2026 walks through the newer agent style if you want it. Either way, these five packages are the whole dependency list.

The takeaway: one virtual environment and five packages, with no API keys anywhere in the process.

Step 3: Load Your PDFs and Split Them Into Chunks

ChromaDB logo on a grey background

A language model cannot read a 200 page PDF in one go, so RAG splits documents into overlapping chunks first. Chunk size is the setting beginners get wrong most often: too large and retrieval gets vague, too small and context gets lost. A chunk of 800 to 1000 characters with 100 to 200 characters of overlap is a proven starting point for most PDFs.

from langchain_community.document_loaders import PyPDFLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter

loader = PyPDFLoader("my_notes.pdf")
documents = loader.load()

splitter = RecursiveCharacterTextSplitter(
    chunk_size=1000,
    chunk_overlap=200
)
chunks = splitter.split_documents(documents)

PyPDFLoader reads each page and keeps the page number as metadata, which is how your chatbot can cite sources later. RecursiveCharacterTextSplitter tries to split on paragraph breaks first, then sentences, so chunks stay coherent instead of cutting mid sentence. For scanned PDFs, run OCR first with a tool like ocrmypdf, because PyPDFLoader can only read text that already exists in the file.

The takeaway: good chunking is half of good retrieval, and 1000 characters with 200 overlap is a safe default.

Step 4: Create Embeddings and Store Them in ChromaDB

Embeddings turn each chunk into a list of numbers that captures its meaning. Two chunks about the same topic get similar numbers, even if they share no exact words, which is why RAG can answer a question phrased differently from the document. ChromaDB stores these vectors on your disk in a folder you control.

from langchain_ollama import OllamaEmbeddings
from langchain_community.vectorstores import Chroma

embeddings = OllamaEmbeddings(model="nomic-embed-text")
vectorstore = Chroma.from_documents(
    chunks,
    embeddings,
    persist_directory="./chroma_db"
)

Indexing happens once. A hundred page PDF takes a few minutes on a normal laptop, and after that the vector store loads instantly on every run. ChromaDB persists to the chroma_db folder, so you can delete it to start fresh or copy it to another machine. If you outgrow ChromaDB later, Qdrant and pgvector are the usual next steps, and LangChain supports both with almost no code change.

The takeaway: embeddings are computed once, stored locally, and reused forever.

Step 5: Build the Retrieval Chain and Ask Questions

LangChain logo on a grey background

The final piece connects the retriever to the chat model. When you ask a question, the retriever fetches the most relevant chunks, usually the top 4, and the model answers using only that context.

from langchain_ollama import ChatOllama
from langchain.chains import RetrievalQA

llm = ChatOllama(model="llama3.1:8b")
retriever = vectorstore.as_retriever(search_kwargs={"k": 4})

qa_chain = RetrievalQA.from_chain_type(
    llm=llm,
    retriever=retriever,
    return_source_documents=True
)

result = qa_chain.invoke({"query": "What does this document say about refunds?"})
print(result["result"])

Setting return_source_documents=True is the feature that makes this trustworthy: every answer comes with the passages it used, so you can verify instead of blindly trusting the model. Ask a question your documents cannot answer, and a well prompted chain will say so rather than inventing one. If you want a chat interface instead of a terminal, wrap the same chain in Streamlit or Gradio with about 30 lines of code and run it on localhost.

Students use this exact pattern to quiz themselves on lecture notes, and small businesses use it to answer staff questions from policy handbooks. The takeaway: a retriever plus a local model plus source citations is a complete private chatbot.

How to Make Your RAG Chatbot More Accurate

Three tuning steps fix most weak answers. First, raise the number of retrieved chunks from 4 to 6 when answers miss details, and lower it when answers get noisy. Second, add a short instruction to your prompt telling the model to answer only from the provided context and to say it does not know when the context is silent. Third, clean your PDFs: remove headers, footers, and scanned junk pages before indexing, because dirty chunks produce dirty retrieval.

For a real case study, teams building internal support bots report that chunk size tuning and a strict answer only from context prompt together fix most hallucination complaints without any model upgrade. If accuracy still lags, swap the embedding model or the chat model: Ollama makes that a one line change. You can also add conversation memory so follow up questions work, and metadata filters so the chatbot searches only the documents you choose.

For more on working with long documents, read our guide to summarising 100 page PDFs without hallucinations, and if you want Claude connected to your files instead, see how to connect Claude AI to local files using MCP. The takeaway: tune retrieval before you blame the model.

Frequently Asked Questions

Does a local RAG chatbot need the internet?

No, after the one time model download. Ollama, ChromaDB, and LangChain all run on your machine, so you can chat with your PDFs fully offline. See our list of the best offline AI tools for more ideas.

How much RAM do I need?

16 GB is comfortable for an 8 billion parameter model. With 8 GB of RAM, use a small model such as Llama 3.2 1B and keep your PDF collection modest.

Is my data really private?

Yes, as long as Ollama binds only to localhost, which is its default behaviour. No document text leaves your machine, there are no API keys, and nothing is sent to any cloud service.

Don’t Miss These, Explore More Topics

Doctors and medical students using AI for study and diagnostics

How Doctors & Medical Students Us e AI for Study & Diagnostics

30 AI Prompts for SEO Blog Outlines

30 Copy-Paste AI Prompts for SEO Blog Outlines & Keyword Clustering

30 mega prompts for high converting cold emails

30 Mega-Prompts for Writing High-Converting Cold Emails

Bypass AI detector false positives ethically

How to Bypass AI Detector False Positives Ethically (Humanizing Guide)

Free alternatives to ElevenLabs for realistic voiceovers

5 Best Free Alternatives to ElevenLabs for Realistic Voiceovers

AI regulations and copyright updates for creators

Major AI Regulations & Copyright Updates: What Creators Must Know

7 Best Free Notion AI Alternatives

7 Best Free Alternatives to Notion AI for Second-Brain Note Taking

Free AI courses with certificates

Best Free AI Courses with Certifica tes from Google, Mi crosoft & Nvidia

Robotics Meets Generative AI: Biggest Humanoid Breakthroughs This Year

Robotics Meets Generative AI: Biggest Humanoid Breakthroughs This Year