Build your own "chat with my files" app in Python, step by step
"What's the notice period in my tenancy agreement?" Build the app that answers questions like that from your own files, quotes its sources and says when it doesn't know. Every model runs on your own computer, so nothing gets uploaded.
- A terminal version (ingest.py, ask.py) and a browser version (app.py) built on the same small engine
- A test set and a script that scores retrieval and answers, so every change you make is measured
- Run a ChatGPT-style AI on your own laptop done: Ollama installed and
gemma4:e2bdownloaded (4.6GB). Use Ollama 0.20.7 or newer: Gemma 4 needs it, and it covers the 0.11.10 minimum for this mission's embedding model. Check withollama --version. - uv, the Python installer used in Turn a Python script into a web app you can share and Turn any Word, Excel, PowerPoint or PDF into text your AI can actually read. uv fetches Python 3.12 for you.
- 8GB of RAM minimum, 16GB recommended. About 1.1GB of extra disk: 622MB for the embedding model and about 440MB for the project's Python packages.
- You can read a bit of Python. You don't need to write any from scratch: every file is complete and in the starter kit.
- No accounts, no API keys, nothing to pay for.
Fast path: your first cited answer in 10 minutes
See the finished thing working first. The rest of the lesson takes it apart so you can tune it.
Download the starter kit: chat-with-my-files.zip (178KB) and unzip it into your Documents folder. It comes with four sample documents from a fictional bike shop, so you can check every answer against something you know. Then get the embedding model (622MB), install the project and ask your first question:
Windowsollama pull embeddinggemma cd $HOME\Documents\chat-with-my-files uv sync uv run ingest.py uv run ask.py "How long is the warranty on an aluminium frame?"Mac / Linuxollama pull embeddinggemma cd ~/Documents/chat-with-my-files uv sync uv run ingest.py uv run ask.py "How long is the warranty on an aluminium frame?"ingest.pyreads the four files and builds a searchable index.ask.pyprints the passages it found under Sources found, then an Answer from the local model with[1]-style numbers pointing at those sources. The first answer is the slowest, because Ollama has to load the model into memory.Want the browser version straight away? Run
uv run streamlit run app.py, ask a question at the bottom of the page and open Sources under the answer. Step 6 covers it properly.TipSwapping in your own files is one change: put them in thedocsfolder (PDF, Word, PowerPoint, Excel, Markdown or text) and runuv run ingest.pyagain.
ask.py answers "5 years" with a [1] citation, and returns-and-warranty.pdf is in the sources list.If it breaks'uv' is not recognised + 2 more
'uv' is not recognised
winget install --id astral-sh.uv -e (Windows) or curl -LsSf https://astral.sh/uv/install.sh | sh (Mac or Linux), then open a new terminal. Full walkthrough in Install anything from GitHub.