"Chat with your docs" is one of the most useful patterns for personal LLM use โ research notes, journal entries, manuals, code documentation. Cloud RAG offerings exist but you have to upload everything to someone else's servers. With local Ollama + a local vector database, you get the same capability with nothing leaving your home network.
RAG (Retrieval-Augmented Generation): when the user asks a question, retrieve relevant snippets from a vector database via semantic search, then prompt the LLM with the question plus those snippets as context. The LLM answers using your snippets as ground truth.
Each step lives on your tailnet. Question โ embedding (Ollama) โ vector search (Chroma) โ top-k snippets โ augmented prompt โ final answer (Ollama). All inference local; nothing sent to the cloud.
docker run -d \
-p 8000:8000 \
-v chroma-data:/chroma/chroma \
--name chroma \
--restart always \
chromadb/chroma
Verify: curl http://localhost:8000/api/v1/heartbeat should return JSON.
Embeddings turn text into vectors. We need a model for that:
ollama pull nomic-embed-text
Small (~270MB) model dedicated to producing semantic embeddings.
mkdir ~/rag && cd ~/rag
python3 -m venv .venv
source .venv/bin/activate
pip install chromadb requests
Save as ingest.py:
import os, sys, requests
from pathlib import Path
import chromadb
OLLAMA = "http://localhost:11434"
CHROMA = chromadb.HttpClient(host="localhost", port=8000)
COLL = CHROMA.get_or_create_collection("docs")
def embed(text):
r = requests.post(f"{OLLAMA}/api/embeddings",
json={"model": "nomic-embed-text", "prompt": text})
return r.json()["embedding"]
def chunk(text, size=500, overlap=50):
chunks = []
for i in range(0, len(text), size - overlap):
chunks.append(text[i:i + size])
return chunks
def ingest(path):
text = Path(path).read_text()
for i, c in enumerate(chunk(text)):
COLL.add(
ids=[f"{path}-{i}"],
documents=[c],
embeddings=[embed(c)],
metadatas=[{"source": str(path), "chunk": i}],
)
print(f"Ingested {path}")
if __name__ == "__main__":
for p in sys.argv[1:]:
ingest(p)
Test:
python ingest.py ./notes/*.md ./book.txt
Save as query.py:
import sys, requests
import chromadb
OLLAMA = "http://localhost:11434"
CHROMA = chromadb.HttpClient(host="localhost", port=8000)
COLL = CHROMA.get_collection("docs")
def embed(text):
r = requests.post(f"{OLLAMA}/api/embeddings",
json={"model": "nomic-embed-text", "prompt": text})
return r.json()["embedding"]
def ask(question, k=5):
results = COLL.query(query_embeddings=[embed(question)], n_results=k)
snippets = "\n\n---\n\n".join(results["documents"][0])
prompt = f"""Answer using ONLY the snippets below. If they don't contain the answer, say so.
Snippets:
{snippets}
Question: {question}
Answer:"""
r = requests.post(f"{OLLAMA}/api/generate",
json={"model": "llama3.1:8b", "prompt": prompt, "stream": False})
return r.json()["response"]
if __name__ == "__main__":
print(ask(" ".join(sys.argv[1:])))
python query.py "what does my book say about networks"
Wrap query.py in a small Flask app, then:
sudo tailscale serve --bg --set-path=/rag http://localhost:5000
From any tailnet device, you can now POST queries:
curl https://ai-rig.tail-abc.ts.net/rag \
-d '{"q": "summarize the meeting notes"}'
Open WebUI (from the Local AI project) supports RAG natively. Upload docs in its UI; it handles chunking, embedding, and retrieval automatically. No script needed.
Recommendation: use Open WebUI for chat-with-docs unless you need custom logic. The scripts above are educational; the production answer is "use Open WebUI's built-in RAG."
ollama pull nomic-embed-text first.nomic-embed-text is good; mxbai-embed-large is even better but slower