

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Inverted Index
incomplete
2: Use the Index
incomplete
3: Boolean Search
incomplete
4: Term Frequency
incomplete
5: Inverse Document Frequency (IDF)
incomplete
6: TF-IDF
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
An inverted index is what makes keyword search fast. It's like a SQL database index, but for text. Instead of scanning every document on every search, we build a lookup table ahead of time.
A "forward index" maps location → value. An "inverted index" maps value → location.
Here's an example mapping words to the document IDs where they appear:
matrix → [1, 5, 10]hacker → [1, 8]reality → [1, 3, 7]Using an inverted index is fast: each token lookup is O(1) on average. Building the index is slower because we still have to read and tokenize every document once.
Implement an InvertedIndex class and use it for keyword search.
f"{m['title']} {m['description']}"
print(f"First document for token 'merida' = {docs[0]}")
We'll hardcode this as a very simple test to ensure that the index is built correctly.
Run and submit the CLI tests.