AlgoViz

Why did this document rank first?

medium 6 min

An internal engineering search returns a long glossary above a precise two-paragraph runbook.

Video lesson · Chapter 1 of 5

One battery reference or six

0:00 / 4:16

Why did the short runbook outrank the glossary?

1:21Reel

Theory

Read or listen first. About 1 min.

What it is

An inverted index records which documents contain a term. The posting for a rare product code may be tiny, while a word like “service” appears almost everywhere. Analysis choices such as case folding and tokenization decide whether a query and a document even share a term. Rankings only operate on the resulting candidates.

Repeated words have diminishing returns

BM25 term-frequency factor012Term occurrences081 occurrence → factor 1.00
With document length and IDF fixed, the first matching term makes a large contribution. The curve shows the BM25 frequency factor with k₁ = 1.2 at average document length.

Why it exists

Term frequency rewards a document for using a matching word. Inverse document frequency gives a rare word more weight. BM25 also limits the benefit of repetition and takes field length into account. A short runbook mentioning a precise failure code might therefore outrank a long incident archive.

View diagram · Query execution
Query → Shard search (analyzed terms); Index writer → Visible segments (refresh); Visible segments → Shard search (postings); Shard search → Top hits (merge scores)
TF, IDF and field length affect the order of eligible matches.
Full size

Words to know

Posting
An index entry that identifies a matching document and may carry term frequency and positions.
Refresh
The operation that makes newly indexed data visible to searches in Elasticsearch.

How it works

Step through the idea, or press Play.

Step 1 of 3

Trace retrieval. An inverted index maps analyzed terms to postings. Intersect required terms and apply permission filters before returning a result. Phrase queries need position information or a verification step.

Understand it

Start here

The missing reset guide

An engineer publishes a reset guide and immediately searches for it. Follow the guide from the writer’s view to the results page to see where a missing document and a low-ranked one diverge.

The missing reset guide
Finding the reset guideRunbookjust writtenIndexold viewResultsno guideSearch has an older index view

Check refresh, terms and access filters.

Structure

Query execution

Query execution

Query → Shard search (analyzed terms); Index writer → Visible segments (refresh); Visible segments → Shard search (postings); Shard search → Top hits (merge scores)
TF, IDF and field length affect the order of eligible matches.

A relevance experiment

Compare a two-sentence reset guide containing “reset token” once with a long troubleshooting catalog that repeats it eight times. Record their ranks for five judged queries before tuning length normalization. Test visibility separately by indexing a new guide and searching before and after refresh.

How a search result reaches the page

Trace a missing runbook

ObservationLikely stageUseful check
Direct ID lookup works, search missesIndex refresh or analysisCheck search visibility and analyzed tokens
Exact query finds it on page threeScoring or competing candidatesInspect scores for judged matches
Only one team cannot find itAccess controlRun with that team’s permissions
New scoring improves head queries onlyEvaluation sampleSplit results by query frequency

Field design changes relevance

An error identifier and a body paragraph often need separate fields. Users searching an exact identifier expect a precise match; people describing symptoms need tokenized text. Store and query each field according to its use. Phrase search also needs information about term positions so a phrase match can distinguish the same words scattered across a long article.

Evaluate a change against people’s queries

Build a small set containing a rare code, a frequent symptom, a paraphrase and a recent document. Record which results engineers consider useful. Compare their positions before and after tuning, with access rules kept fixed. Track publication-to-search delay separately so a slow refresh cannot masquerade as a relevance regression.

Inspect candidates first

  • Check refresh, terms and access filters.

Tune scoring for a missing candidate

  • A ranker can only score documents it receives.

Summary

The whole topic in one minute.

Trace analysis, visibility, candidate retrieval and scoring in order. Change a scoring parameter only after the desired item is visible and eligible.

Sources