- Published
- Updated
What Is an Inverted Index?
An inverted index maps terms to the documents that contain them, helping search engines find text matches without scanning every page.
A user searches a help site for:
reset passwordThe site has four pages. In this example, the search system indexes both the page title and the text below it.
| ID | Page title | Text |
|---|---|---|
| P1 | Manage your account | Manage your account and password. |
| P2 | Reset a forgotten password | Reset a forgotten password. |
| P3 | Billing help | Download invoices and update payment details. |
| P4 | Protect your account | Protect your account with two-factor authentication. |
The system could open all four pages and check every word. That works here, but repeating the scan for every query becomes wasteful as the collection grows.
Instead, it prepares a lookup before the user searches. That lookup is an inverted index.
What is an inverted index?
An inverted index maps each searchable term to the documents that contain it.
For our four pages, part of the index looks like this:
account -> P1, P4password -> P1, P2reset -> P2payment -> P3authentication -> P4This is similar to the index at the back of a book. You start with a topic and get the pages where it appears.
The mapping is called inverted because it reverses the direction we begin with. The original content starts as pages containing words. Search needs words pointing to pages .
The set of searchable terms is often called the vocabulary or lexicon. A term dictionary organizes those terms and points to their postings lists.
The list beside each term is a postings list. The postings list for password is P1, P2. Each document entry inside that list is one posting.
How is an inverted index built?
The system first extracts the text it wants to make searchable. It then breaks that text into smaller units called tokens.
For example:
"Reset a Forgotten Password"may become:
reset, a, forgotten, passwordThe system may also make text lowercase or handle punctuation. These choices make document terms and later query terms compatible. The exact processing varies by implementation.
Each final term is added to the postings for the field being indexed. Some systems keep separate term dictionaries and postings for fields such as titles and bodies.
How does search use the index?
Now the user searches for:
reset passwordThe search system analyzes the query into terms compatible with those stored in the index:
[reset, password]Then it reads the two postings lists:
reset -> P2password -> P1, P2P2 appears in both lists, so it contains both query terms. P1 appears only in the password list, so it is a partial match. Whether P1 is retained depends on whether the search requires every term or allows partial matches.
The shared part of the lists is their intersection. For this query, the intersection is just P2.
The engine can start with these short term-led lists instead of reopening every page to discover possible matches. Those possible matches are the candidates that a ranking method can order.
Does an inverted index rank the results?
The index retrieves candidates and can store clues about them. A posting may include how often the term appeared and where it appeared among the other tokens. The system may also keep separate postings for the title and body.
In our example, P2 contains both query terms, and both appear in its title. P1 contains only password. A ranking formula can use those differences to give P2 a stronger score.
Methods such as BM25 rank word-based matches using term evidence. The inverted index makes that evidence available; the ranking method decides how much each clue matters.
Stored token positions can also support phrase or nearby-word search. P2 is not an exact-phrase match for reset password because another word sits between the two terms. A hypothetical page containing the exact phrase could be treated differently from one where the words appear paragraphs apart. Not every index stores positions, so this behavior depends on the system.
What happens when a page changes?
Suppose P1’s title and text both change:
Title: Manage your accountText: Manage your account and password.becomes:
Title: Profile and login settingsText: Update your profile and login settings.Conceptually, selected affected postings change like this:
account -> remove P1password -> remove P1profile -> add P1login -> add P1settings -> add P1This does not mean every engine edits one list in place. An implementation may write new index segments, mark old entries as deleted, merge segments later, or rebuild on a schedule. The useful reader model is simpler: P1 must stop appearing under its old terms and start appearing under its new ones.
A single edit does not always require rebuilding the complete index. Search can still lag behind the source content when updates are delayed or batched.
The targeted lookup has a cost. The index takes storage and work to build and maintain, and new content must reach it before search can use it.
The index is a maintained lookup over the source content, not the source content itself. The source page can change before its searchable representation is refreshed.What does an inverted index not solve?
A basic inverted index is strong at finding exact or normalized word-based terms. It does not automatically understand every way a person can describe the same need.
A user may search for:
forgot my loginwhile the useful page says:
Reset your passwordThose phrases share little vocabulary. Synonym handling, spelling correction, query expansion, or vector search can help with differently worded meaning. An inverted index does not add those choices automatically.
Word-based matching still matters for product names, API routes, error codes, and exact technical terms. A search system can combine more than one retrieval method when its query mix needs both literal and semantic evidence.
Inverted index summary
An inverted index keeps a postings list for each searchable term.
The basic flow is:
indexed fields -> searchable terms -> postings listsquery -> compatible terms -> matching postingsIt makes candidate lookup targeted. Optional stored clues can support ranking and phrase behavior, while update work keeps the lookup fresh.
Start with the term, then follow it to the documents.
Next reads
What is BM25? A Plain English Guide
BM25 is a keyword search ranking function that scores documents using term frequency, term rarity, and document length. Learn how it works, where it helps, and how it differs from TF-IDF.
What Is Vector Search?
Vector search finds related content by comparing embeddings. Learn how vectors, similarity, approximate nearest-neighbor search, and hybrid retrieval work together.