Build a RAG of You
- Level
- intermediate
- Time to complete
- 25 min
- Prerequisites
- 3
What you will buildIndex your own notes, chats, and documents on your own machine and ask them questions. About 25 minutes, Python only, no paid service.
What You Will Build
You will build a small program that reads your own notes, exported chats, and documents from a folder on your machine, turns them into a searchable index, and answers questions from them in plain language. Ask it "what did we decide about pricing" and it hands back the note where you decided, not a web result and not a guess.
The whole thing is one Python file of about 90 lines, using only the standard library. It runs entirely on your computer. Nothing is uploaded, no account is created, and no paid service is required. It ships with a zero-install retrieval mode so you can run it today, and a one-line switch to free, local, semantic embeddings when you are ready for better matches.
Prerequisites
- Python 3.9 or newer, and a terminal. That alone is enough to finish every step.
- A folder of your own text: export a few AI chats, drop in some
.txtand.mdnotes, save a document or two as plain text. Even three files is enough to see it work. - Optional, for semantic search: Ollama installed (it is free and local) with an embedding model pulled. You can add this after you have the basic version running.
Tip
Start with whatever text you already have. You do not need to tidy or tag anything first - the entire point of a RAG of you is that it works on the mess as it is.
Mental Model
A RAG of you is three plain moves (the idea comes from the 2020 paper by Lewis and colleagues that named Retrieval-Augmented Generation). First, cut your text into small pieces. Second, turn each piece into a list of numbers that captures its meaning, called an embedding, and keep those in a file you can search. Third, when you ask a question, turn the question into numbers the same way, find the pieces whose numbers are closest, and answer from them.
The only moving part worth understanding is that last comparison. Two pieces about the same idea get similar numbers even when they share no words, so "how do we handle late payers" can find a note that only ever said "overdue invoices." You measure "closeness" with cosine similarity, which is just a number between 0 and 1 for how aligned two lists of numbers are. That is the whole engine. Everything below is plumbing around it.
Steps
Create the file and gather your corpus
Make one folder, say my-corpus, and put your text in it: exported chats, notes, documents saved as .txt or .md. Then create an empty rag_of_you.py next to it. That is the entire project: one folder of your text, one script.
You know this worked when ls my-corpus (or dir my-corpus) lists at least a couple of .txt or .md files.
Load and chunk the text
Open rag_of_you.py and add the imports and the two functions that read your files and cut them into overlapping pieces. The overlap keeps a sentence that straddles a boundary from being split in half and lost.
import os, re, json, math, hashlib, glob, sys
import urllib.request
def load_docs(folder):
docs = []
for path in glob.glob(os.path.join(folder, "**", "*"), recursive=True):
if path.lower().endswith((".txt", ".md")):
with open(path, encoding="utf-8", errors="ignore") as fh:
docs.append((path, fh.read()))
return docs
def chunk(text, size=180, overlap=40):
words = text.split()
out, i = [], 0
while i < len(words):
out.append(" ".join(words[i:i + size]))
i += size - overlap
return out or [""]
You know this worked if python -c "import rag_of_you" runs with no error.