● ● ● ● ● ● ○ ○ ○ Lesson 6 of 9
Build a docs Skill · A brown-bag
Your search works. So why does a giant changelog keep beating the page you actually need?
We shipped TF-IDF in Lesson 5. It passes the body-only evals. Ship it, done — right?
Then someone searches machine id tbot. The right answer is the focused
tbot reference page. But look what ranks near the top: the
Teleport Changelog — a single, enormous page that lists every change in
every release. It is almost never the page you want. Yet it keeps muscling in above the
pages that are.
Why? Because our score is weight = TF × IDF, summed over the query's
words — and a huge page contains every word many times. The Changelog
has 2,891 terms. Of course it racks up a big total. It wins by size, not by
relevance.
"the multi-hundred-page Changelog (2,891 terms) outranks the focusedtbotreference formachine id tbot." — CORPUS.md, Act E (the review)
Here is the twist that makes this the most important lesson in the course. The agent that built TF-IDF knew about this risk. It even watched the Changelog rank high and talked itself into it:
"The changelog shows up a lot (it's a very long page with many terms), but the weights naturally push the targeted pages to the top." — CORPUS.md, Act D (the agent, eyeballing the output)
A capable agent made a reasonable call and eyeballed the result as fine. It wasn't. That's the lesson: a good guess is still a guess.
Your turn — propose the fix (before you read on).
A page wins because it's long: every word appears many times, so its total is bloated. What would you change about the score to stop big pages from dominating?
Two fixes, and you want both. (1) Stop rewarding repetition without limit — the 20th time a word appears shouldn't count as much as the 1st. (2) Divide by page length — judge a word's density, not its raw count, so a long page gets no free boost. Together, those two ideas are BM25.
The fix is a small upgrade to TF-IDF called BM25. Same family, still just arithmetic — but it adds length normalization. It has two knobs:
k1 — saturation. The more a word repeats, the less each
extra hit adds. A word appearing 20 times isn't 20× as relevant. (We use
k1 = 1.2.)b — length normalization. Divide a word's score by how
long the page is compared to the average page. A big page no longer wins just for being
big. (We use b = 0.75.)That second knob is the whole cure for the Changelog. Its size stops paying.
Here's the score, with each piece labeled. You don't need to compute it — just see
what k1 and b do:
IDF × TF × (k1 + 1)
score = ─────────────────────────────────────
TF + k1 × (1 − b + b × doc_len / avg_doc_len)
└──────────────────┘
this is the new part: page length ÷ average
long page → bigger denominator → lower score
And the payoff, same query, before and after:
"for machine id tbot the top 4 are now all Machine/Workload Identity pages;
the Changelog is gone from the top."
— CORPUS.md, Act G (BM25 lands)
One more thing, and it's the reason this costs nothing extra: we compute the BM25 weights at build time and bake them into the index (it just grows one number, the average page length). The shipped skill still does only lookups and addition — no new work at query time. Same shippable file, smarter ranking.
Red: raw TF × IDF let the 2,891-term
Changelog outrank the focused tbot page — measured live (for
tbot github actions deploy the Changelog hit #2 at 38.1, beating "Deploy
tbot" at 27.7).
Green: BM25 (k1=1.2, b=0.75) → top results
all become Machine/Workload Identity pages, Changelog gone. The body-only suite
(evals 9–13) stays in place to confirm the ranking holds after the change.
That's Agile iteration again: title → body → ranked by density, not size. Each short round — built, tested, improved — makes the data the agent grounds on more accurate.
But now try searching for mysqld, or
pg_hba.conf. The page you need exists… and the index can't find it at all.
Not ranked low — completely absent. What did we forget to index?
That's Lesson 7.
Quick self-check (recall before you peek):
It's huge — every word appears many times, so its summed score is bloated. It won by length, not relevance. Frequency ≠ relevance.
k1 saturates repetition (the 20th hit adds little); b normalizes by page length (a long page gets no free boost). b is what fixes the Changelog.
By a measurement (running the query, reading the ranks), not a smarter model. Eyeballs aren't evals — a capable agent's reasonable guess was still wrong.