RAG over agent-created harness files
in RAG pipelines
Every agent mistake I fix becomes a written lesson, and a month later I can't find the lesson when the same mistake comes back, because I don't remember the words I used.
- Why search my own notes?
- What is the RAG part?
- What does it search, and which questions get an answer?
- What did we build?
- How do you test a search engine?
- Did meaning search beat keyword search?
- What made the biggest difference?
- When does it refuse to answer?
- What stops it getting worse?
- What didn't work?
- How was it built?
- Summary
Why search my own notes?
Because the answers are in my notes, and keyword search only finds them if I type the note's words. I run Claude Code agents all day on my own harness: the rules, hooks and skills every chat loads. When an agent does something wrong, I write a lesson with an id, like L99: "When you show the operator a page, confirm they can see it." Sessions end with a report, and reports cite the lessons they hit.
The index measured here holds 4,909 heading-sized chunks: lessons, session reports, brainstorms, checkpoints, plans. When something breaks, I type what I see, like "i cant see the ui". The lesson that answers it says "confirm they can see it". The words barely overlap.
So the goal was a search that finds the lesson from the symptom, an answer tool that quotes it, and numbers that say how often it works. My CV also had no retrieval work, and the jobs I want ask for it.
| Tool | Used for |
|---|---|
| Python 3.14, uv | the docrag package and its lock file |
| SQLite FTS5 | keyword search (BM25) in the same file as the vectors |
| fastembed 0.9.0, ONNX Runtime 1.31.0 | local embeddings, no torch, no hosted API |
BAAI/bge-small-en-v1.5 |
the embedding model, 384 numbers per chunk |
| NumPy 2.5.4 | brute-force vector search |
| Anthropic SDK 2.1.0, Claude Sonnet 5.5 | docrag ask, the answer step (optional extra) |
| GitHub Actions | the recall gate on every push |
| mow | the multi-agent run that built it |
What is the RAG part?
RAG means retrieval-augmented generation: find the relevant text, then hand it to a model with the question, so the answer comes from your documents, not the model's memory. Here the retrieve step is docrag search and the generate step is docrag ask.
Most of the work is the retrieve step. If search misses the right lesson, the best model answers from the wrong page.
What does it search, and which questions get an answer?
My own harness files, cut at their headings. The index I rebuilt on 2026-11-16 holds 5,819 sections from 542 files:
| Kind of file | Sections | Files |
|---|---|---|
| session reports | 2,636 | 205 |
| brainstorms | 1,249 | 101 |
| plans | 1,071 | 126 |
| workflow, action reports, checkpoints, runbooks | 755 | 109 |
| lessons | 108 | 1 |
search looks through all of it. ask looks only at the 108 lesson sections by default, because a lesson is a rule written to be quoted. Three real runs:
| I ask | It returns | Why |
|---|---|---|
ask "What should an agent do before showing me a page in the browser pane?" |
check I can see it, citing L99 | a lesson says nearly that |
ask "What is the capital of France?" |
"Not in the docs" (cosine 0.468) | easy case under the 0.616 cut, no model call; 55% is typical |
search "why did we drop the reranker" |
three unrelated docs | the deciding plan says "reranker" and still missed |
It answers rules I wrote down, asked in roughly my words. A decision buried in a plan's "Decisions locked" list can lose to docs that use the same words in passing.
What did we build?
A small Python package, docrag, with four commands that share one SQLite file:
docrag indexsplits every markdown doc at its#,##and###headings and stores each chunk twice: as text for keyword search, and as an embedding, a list of 384 numbers that places similar meanings close together.docrag searchfinds chunks by keywords (BM25), by meaning (dense), or by both fused (hybrid).docrag evalscores search against an answer key.docrag askanswers from the top chunks with citations, or refuses.
There is no vector database. At about 5,000 chunks, comparing the question's vector to every chunk's is one NumPy matrix multiply. The vectors sit in the same SQLite file as the text, so one file is the whole index.
Hybrid search uses reciprocal rank fusion. Each search gives its top 50, and a chunk scores 1/(60 + rank) from each list it appears in.
With the lesson filter on, hybrid search ranks L99 first for "i cant see the ui" (snippets cut to the first hit's):
$ docrag search --mode hybrid --doc-type lesson -k 3 "i cant see the ui"
1. 0.03279 docs/lessons-cases.md#Lessons — the full cases > L99 [lesson]
## L99 - **When you show the operator a page, confirm they can see it** — the Browser pane may be hidden (`tabs_context` says so); say…
2. 0.03008 docs/lessons-cases.md#Lessons — the full cases > L39 [lesson]
3. 0.02964 docs/lessons-cases.md#Lessons — the full cases > L01 (L31, L63) [lesson]
The score 0.03279 is 2/61: keyword and meaning search both ranked L99 first.
How do you test a search engine?
With questions whose right answer you know before you search. The answer key has 34 questions, and each one names its gold lesson. The score is recall@5: how often the gold lesson lands in the top 5. A second score, MRR, rewards ranking it higher: 1 for first place, 1/2 for second, and so on.
21 of the 34 questions are built by a script from my notes. A session report that cites L58 becomes a question with gold L58. The script strips every lesson id and the lesson's own wording, and the search skips the source report, so it can't match the text the question was cut from.
The other 13 are mine, copied word for word from past chats. An agent searched my old messages for questions a lesson answers, like "i cant see the ui" and "why is lane A stuck at 23s ????". This is how I actually ask. An agent that has read the lessons writes questions in their words, and those score too well.
A hit counts only when the chunk is the gold lesson's own section. Some lessons have later notes that repeat their id, like a section headed L153 (L58). An earlier version of the scorer counted those as hits for L58. Fixing that dropped hybrid from 14 to 9 of 31 hits, on the same index.
At 34 questions, one question moves recall@5 by about 3 points. Treat any one-question gap as a tie.
Did meaning search beat keyword search?
Barely, and not by enough to count. Searching lesson sections only, on the same index:
| Search | Found in top 5 | recall@5 | MRR |
|---|---|---|---|
| keywords (BM25) | 10 of 34 | 0.2941 | 0.1819 |
| meaning (dense) | 8 of 34 | 0.2353 | 0.2020 |
| hybrid | 11 of 34 | 0.3235 | 0.2434 |
Hybrid beats keywords by one question, which is noise. Its lead is MRR: it ranks the lesson higher. On my own 13 questions, hybrid finds 6 (0.4615), keywords 4 and meaning 5.
What made the biggest difference?
Searching only the lesson sections. Every gold answer is a lesson, but across all 4,909 chunks the session reports about the same incident outrank it: they describe the symptom in the question's words.
| Search scope | hybrid found in top 5 | recall@5 |
|---|---|---|
| all 4,909 chunks | 3 of 34 | 0.0882 |
| 101 lesson chunks | 11 of 34 | 0.3235 |
Here is the same question on the same index without the filter. Headings are shortened with "…" and snippets cut:
$ docrag search --mode hybrid -k 3 "i cant see the ui"
1. 0.022 docs/brainstorms/admin-panel.md#admin-panel: one ai-wow admin site … > Decisions
2. 0.01639 docs/brainstorms/mow-outputs-summary.md#mow-outputs-summary: wrap-up … >
3. 0.01639 docs/session-reports/2026-10-17-2122-ui-ingest-and-ui-workflow.md# [session-report]
Three docs where I said "ui" in passing; L99 is not in the top 3.
When does it refuse to answer?
When the best chunk's meaning score is below 0.616. Then ask says so and never calls the model, so a refusal costs nothing.
- Hybrid search takes the top 8 lesson chunks.
- If the best cosine score is below 0.616,
askrefuses with no model call. - Otherwise it wraps the chunks as data, escaping every
<so a doc can't close the wrapper and pass as instructions. - Claude answers only from them and cites each claim as
[n]. askswaps each[n]for the chunk'spath#heading.
I ran the 34 answer-key questions and 20 questions the docs can't answer, and picked the highest cut that lets at least 95% of the real ones through. It passes 33 of 34 and refuses 11 of 20 off-topic questions (55%). An earlier cut refused every off-topic question but also 10 of 31 real ones. I chose answering: a wrong refusal sends me back to grep, and a weak answer still shows its citations.
The fusion score can't be the gate: it says how a chunk ranked, not how close it is.
The first live run, on 2026-11-17, index path shortened:
$ docrag ask --index docrag.sqlite --threshold-file evals/retrieval/threshold.json "What should an agent do before showing me a page in the browser pane?"
tokens: input=2791 output=68
Before showing a page, confirm the operator can actually see it. The Browser pane may be hidden, which `tabs_context` will tell you. Say where the page opened, or use the operator's default browser instead [docs/lessons-cases.md#Lessons — the full cases > L99].
Sources:
- docs/lessons-cases.md#Lessons — the full cases > L99
$ docrag ask --index docrag.sqlite --threshold-file evals/retrieval/threshold.json "What is the capital of France?"
Not in the docs: the best match (cosine 0.468) is below the refusal threshold 0.616.
No token line on the refusal: no model call. It was an easy case, 0.468 against a 0.616 cut; across 20 off-topic questions the cut refuses 55%.
What stops it getting worse?
A CI job that rebuilds the index on every push to main and fails if hybrid loses a single question against the committed baseline.
The slack is half a question: 0.5 divided by the number of questions, 0.0147 at 34. The index is deterministic, so a red run means something changed. I proved the gate fires by pointing it at a corpus config with the lessons file removed. It exited 1.
What didn't work?
- The repeat detector found nothing. The plan had a nightly job flag a new report that looks like an old lesson nobody cited. On 9 known repeats it found 0 at the shipped cut, and no cut reached precision 0.8. The embedding score tracks a doc's topic more than the failure it describes. It ships as code, not scheduled.
- The answer step ran live once: one answer, one refusal. No build lane had an API key; tests use a fake client. They show the path works, not answer quality.
- 21 of 34 questions are missed by all three searches. Most are short status questions like "is wave 2 lane B actually still running?", which share no words with the lesson.
- The scope filter made refusals worse. Across all docs the cut refused 65% of off-topic questions. Filtered to lessons it refuses 55%.
How was it built?
As one mow run: four waves, seven lanes, a review gate after each wave. mow, my multi-agent workflow, turns a plan into one brief per lane; builders work in their own git worktrees and fresh reviewers check each wave's diff. More in Supervisor agents catch what worker agents miss.
Summary
- Measure the retrieve step first. In RAG, a search that misses the page makes the model answer from the wrong one.
- Build the answer key from real questions, word for word. Mine your own chat history rather than asking an agent to invent them.
- Check what your scorer counts as a hit. Mine gave credit for notes that only repeated a lesson's id.
- Filter to where the answers live before tuning anything. That took hybrid from 3 to 11 of 34; hybrid against keywords was a one-question tie.
- Gate it in CI at half a question of slack, so one lost question turns the push red.
- Give my agents
searchas an MCP tool over an index rebuilt every night, so they look up a lesson mid-task instead of me grepping for it. - Grow the answer key past 34 questions, so one question stops being 3 points.