Zero Labs
Industry News / AI

I Built a Private AI That Answers Questions From My Own PDFs — Entirely on My Laptop

Source · Towards AI By Pariv Shah

From the publisher’s feed, collected in the ZeroLabs newsroom.

No cloud API. No subscription. No data leaving my machine.That was the goal.Like many people, I wanted to ask questions about my own documents — reports, notes, personal PDFs — and get useful answers back. ChatGPT-style tools are powerful, but sending private files to the cloud is not always comfortable.So I built a simple RAG (Retrieval-Augmented Generation) application in Python that runs 100% locally using Ollama, a vector database, and a small language model.This article walks through what I built, why it matters, and how the pieces fit together.What is RAG, in plain English?RAG stands for Retrieval-Augmented Generation.Instead of asking an AI to answer from memory alone, RAG works in two steps:Retrieve — Find the most relevant parts of your documentsGenerate — Use an LLM to write an answer based on that contextThink of it like an open-book exam. The model does not need to memorize your PDF. It looks up the right pages first, then answers using what it found.That makes answers more accurate, more grounded, and less prone to hallucination.Why go local?Cloud AI is convenient, but local RAG has real advantages:Privacy — Your documents never leave your machineCost — No per-token API billsControl — You choose the models, chunk size, and retrieval logicLearning — You see how RAG actually works under the hoodFor personal documents, prototypes, or experimentation, local RAG is a great starting point.The architecture I choseI kept the stack intentionally small:Total model size: under ~1 GB. That is small enough to run on a normal laptop.Two models, two jobsA common point of confusion in RAG: you usually need two different models.1. Embedding model — nomic-embed-textThis model does not write answers. It converts text into numbers (vectors) that capture meaning.When you ask “How do I get a refund?” and your document says “Return policy and reimbursement process”, the embedding model helps the system understand those are related — even though the words differ.2. Chat model — TinyLlamaThis is the model that reads your question + retrieved context and writes the final answer.TinyLlama is only ~1.1B parameters — small, fast, and good enough for learning and simple Q&A. For better quality later, you can swap in models like phi3:mini or gemma:2b.How the pipeline worksStep 1: Ingest a PDFPDF → extract text → split into chunks → embed → store in ChromaDBI split documents into ~500-character chunks with a small overlap so context is not lost at chunk boundaries.Step 2: Ask a questionQuestion → embed → find top similar chunks → send to LLM → answerThe system retrieves the top 4 most relevant chunks, passes them as context to TinyLlama, and generates a grounded response.What the CLI looks likeThe app is command-line driven and easy to use:# Index your PDF python main.py ingest "my-document.pdf" # Ask a question python main.py ask "What is the main topic of this document?" # Check status python main.py status# Clear the vector store python main.py resetThat is it. No web server, no Docker, no complex setup.Project structureI organized the code into small, focused modules:rag-local/├── main.py # CLI entry point├── rag/│ ├── pdf_loader.py # PDF → text → chunks│ ├── embedder.py # Ollama embeddings│ ├── vector_store.py # ChromaDB wrapper│ └── query.py # Retrieve + generate answer├── .chroma/ # Local vector database└── data/ # Stored PDF copiesEach file has one responsibility. That made debugging and extending the project much easier.What I learned building this1. RAG is simpler than it sounds Once you understand retrieve → augment → generate, the pattern clicks quickly.2. Embeddings are the secret sauce Good retrieval depends on turning text into meaningful vectors. The LLM only works well if you feed it the right context.3. Small models are underrated for learning TinyLlama will not beat GPT-4, but it is perfect for understanding the RAG flow without heavy hardware.4. Start minimal, then iterate A CLI with one PDF, one vector store, and one local model is enough to learn the full stack. You can add a web UI, multi-PDF support, or better chunking later.Who is this for?This kind of project is great if you are:Learning AI engineering hands-onExploring local LLMs with OllamaBuilding private document Q&A for personal usePreparing for interviews where RAG and vector search come upYou do not need a GPU farm. You need Python, Ollama, and curiosity.What is next?From here, the natural extensions are:Support for multiple PDFs in one indexA simple web UI for non-technical usersSmarter chunking (by paragraph or section)Swapping in a stronger local model for better answersBut even in its current form, the project already demonstrates the core idea: your documents, your machine, your AI assistant.Final thoughtWe often think AI means sending data to the cloud. It does not have to.With open-source tools like Ollama and ChromaDB, you can build meaningful AI applications on your own hardware — privately, affordably, and transparently.If you are getting started with RAG, my advice is simple: build the smallest version first. Ingest one PDF. Ask one question. See the full loop work end to end.That one working pipeline teaches more than reading ten architecture diagrams.You can download the complete source code from GitHub. The repository includes detailed instructions to run everything locally. Please let me know if you liked this article or have any questions, feedback, or suggestions. You can connect with me on LinkedIn.I Built a Private AI That Answers Questions From My Own PDFs — Entirely on My Laptop was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.