← back to projects

2026–present — Case study

Local RAG chatbot

A chatbot answering from my own documents, running 100% locally on an 8 GB GPU.

Role
Solo developer
Year
2026–present
Stack
PythonOllamaLlama 3.1 8BEmbeddingsChromaLangChainClaude Code

Overview

I wanted to understand RAG, not just use it. I knew "you embed documents, you search them, you give the result to the model", and that was about it. So I started this project to build a chatbot that answers from my own documents, with everything (model, embeddings, vector store) running on my own machine: a single RTX 3070 with 8 GB of VRAM. It is still in progress, so this page is more of a logbook than a finished case study.

TL;DR

  • Llama 3.1 8B (4-bit) served locally by Ollama, queried through its HTTP API.
  • Documents embedded with snowflake-arctic-embed:33m, stored in Chroma.
  • The 8 GB of VRAM is the constraint behind almost every choice I made.
  • Claude Code works as my tutor and is not allowed to write the solution for me.

The journey

Phase 1 — Setting the rules

I didn't want a project where an agent writes everything and I end up with a working app I can't explain. I had already lived that with Gemini at work (see Agentic assisted dev project), so this time I did the opposite. I wrote a CLAUDE.md that turns Claude into a tutor: it asks me questions, tells me if my answer is right, partially right or wrong, and it never writes the code that solves the current task. I write it, it reviews. A Tasks.md holds the roadmap and a Progress.md the log of each session, so the next session picks up where the last one stopped.

It is slower, obviously. But I came out of each session knowing why, not only how.

Phase 2 — Fitting an LLM in 8 GB

First question: which runtime? I picked Ollama. It handles the VRAM / layer offloading by itself, it has a registry of already quantized models and it runs as a local HTTP server that I can call from my own code.

Then the model. An 8B model in fp16 is 16 GB, so it doesn't fit. I worked out quantization on my own before it was even named: if each parameter takes fewer bits, and several small values can be packed in one byte, 4 bits per parameter gives around 0.5 byte each, hence ~4 GB for 8B parameters. I mixed up the unit prefixes at some point (I skipped "kilo" between bytes and GB), got corrected, and moved on.

I looked at three candidates:

ModelQuantized sizeVerdict
qwen3.5:9b6.6 GBOnly 1.4 GB left for context, too tight
ornith:9b–Fine-tuned for agentic coding, wrong job for a general chatbot
llama3.1:8b (Q4_K_M)4.9 GB~3.1 GB of headroom, very well documented

The qwen one taught me that real K-quant sizes are bigger than the naive "bytes per parameter" maths. I went with Llama 3.1 8B.

Then I checked the theory on the real machine, with nvidia-smi and the Windows Task Manager. Ollama was using ~5.7 GB: the 4.9 GB of weights plus ~0.8 GB for the KV cache and the compute buffers. And my "3.1 GB of headroom" was a lie: Discord, Opera GX and Windows itself already took ~1.4 GB, so I really had less than 1 GB left. That number changed how I looked at everything that came after.

Phase 3 — Talking to the model

I wanted to call the API myself and not just chat in a terminal. Three errors in a row, one after the other:

  1. WRONG_VERSION_NUMBER: I was using https:// on a plain HTTP server.
  2. 405 Method Not Allowed: I forgot the /api/chat path.
  3. A typo in the model name: ollama3.1:8b instead of llama3.1:8b.

Not glorious, but reading the real stack traces taught me more than any tutorial. I also learned that the API streams by default ("stream": false gives a single response), and what happens when the context window is full: Ollama silently drops the oldest tokens, system prompt included. No crash, no warning, the model just forgets. This is the reason why I will only send the relevant chunks to the model and never whole documents.

Phase 4 — Embeddings, chunking and the vector store

For the retrieval part I wrote the idea down myself: embed the query, compute the cosine similarity against the stored chunks, take the top-k and give only those to the LLM. Cosine is just dot(a, b) / (norm(a) * norm(b)), it ignores the magnitude and only compares directions, which is what I want for meaning.

  • Embedding model: snowflake-arctic-embed:33m, ~67 MB. Small, but the real reason is that the embedding model and the chat model have to sit in VRAM at the same time. I thought about loading and unloading them, then dropped it: reloading at every message would make the chat unusable. And with less than 1 GB of headroom, the smallest one wins.
  • Chunking: cutting every N characters breaks sentences and loses what is at the boundary. Overlap fixes part of it, and a recursive splitter (paragraph → line → sentence → word) avoids most of the bad cuts. Too small and a chunk loses its context, too big and its embedding is diluted over several topics, so it doesn't score high enough to be retrieved.
  • Vector store: I first wanted to do it by hand with numpy, to control everything. Then I changed my mind. The embeddings and the cosine similarity were the part I wanted to understand, and I had done that. Persistence and metadata filtering are plumbing, so I picked Chroma.

Here is the whole thing:

RAG chatbot architecture: PDFs are loaded, chunked, embedded and stored in Chroma; each question is embedded, matched against stored chunks with cosine similarity, combined into a prompt and answered by Llama 3.1 8B via Ollama

Where I am now

The app is split in small modules (a singleton config, a logger, an Ollama client for chat and embeddings) and it already finds the PDFs in the ingestion folder. I am using three public JWST documents as a test set. I also run Codegraph on the code, like in my other project.

What's left to build is the actual ingestion into Chroma, the first retrieval tests (do the chunks I get back make sense?), the prompt template and the behavior when nothing relevant is found. After that: a small API, a chat UI, and an honest evaluation of the answers.

What I took away so far

  • Measure it. My VRAM estimate was off by a lot because of everything else running on the GPU.
  • Resources shared by two models change the choices. I would not have picked such a small embedding model otherwise.
  • Write the parts that teach you, delegate the plumbing.
  • An agent can be a tutor. Asking Claude not to give me the answer was probably the best instruction I wrote in this project.