frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Inverted Indexes: A Step-by-Step Implementation Guide (2023)

https://www.chashnikov.dev/post/inverted-indexes-a-step-by-step-implementation-guide
69•klaussilveira•3d ago

Comments

the_precipitate•11h ago
To really appreciate inverted indexes, it’s worthwhile to study ISR (Inverted Stream Readers), a concept introduced by the great Mike Burrows. It’s also worth exploring encoding techniques like PForDelta. These elegant ideas demonstrate how true systems design masters can distill complex concepts into simple, powerful abstractions.

Edit: I stand corrected: it's called index stream readers (thanks atombender for pointing this out). For those who knows Mike Burrows only for the Burrows-Wheeler transformation (BZip), you might also want to know that he was also one of the main developers of AltaVista, the first real search engine for the internet. He also designed the early versions of Bing search engine. Eventually he worked for Google and designed their lock service called Chubby.

atombender•10h ago
I think you're thinking of index stream readers?
mrkeen•10h ago
I have heard of neither. But the mention of Burrows leads me to Burrows-Wheeler, which is a compression algorithm (bzip).

I'm not 100% but I don't think you can directly query a BWT in the same way you'd query an inverted index (without the later discovery of wavelet trees and FM-indexes / succinct data structures, and all that jazz.) And that's mostly for genomics? Not sure if it applies to plain old document searches. Would love to be corrected though.

lazamar•6h ago
At Meta they are using FM indexes to power text search through the entire commit history of their monorepo.
marginalia_nu•9h ago
Another very nice algorithm in the space is this one[1] for intersecting postings lists in sublinear time generally with very good cache characteristics to boot. Works with tree-based indexes as well as skip lists (though a more modern design might also use simple bloom filters to go with the skip pointers).

[1] https://nlp.stanford.edu/IR-book/html/htmledition/faster-pos...

SeanSullivan86•10h ago
I've sometimes been confused by the term "inverted index". The example in this post feels like what I would just call an "index"... i.e documents indexed by the words they contain. Feels about the same as the index in the back of a physical book.

Is the distinction that an index on a multi-valued attribute is called an inverted index?

mrkeen•10h ago
No it's the same thing. With any book you have built-in mechanism to go to a page number see what words are there. An inverted index lets you do the inverse (words -> page numbers).
SeanSullivan86•10h ago
People (non-tech) don't tend to refer to "go to page 106" as using an index. The pages at the back of the book providing the word->page numbers lookup are commonly known as the book's "index"
grg0•10h ago
"commonly" is an understatement; that's literally what a book index is by definition.

The only thing "inverted" here is the context. The author even admits themselves that the word->doc mapping is an index:

"If user wants to search by words - then words should be keys in our "database" (index)"

It's a pointless debate of semantics. An inverted map is still a map.

teiferer•6h ago
It's pointless in the sense that the word "inverse" in the term is pointless, a mild way of saying that it's confusing or even unnecessary to the point of being incorrect.

The discussion about it is not pointless since it clears up confusion. It might not have been for you, but it's clearly for many others, so if you think that's pointless then allowing yourself to appreciate other perspectives could go a long way.

An inverted map is still a map, but if you are typically thinking of the map A->B and then suddenly somebody talks about an inverted map, then it's understandable that people start to assume that this is now about B->A and get confused if it somehow actually isn't really.

atombender•10h ago
Inverted indexes are what databases call indexes. It's used in the IR field to differentiate from forward indexes, which are less common, so you're right that we could just say "index's.

But when we talk about inverted indexes, they are almost always term -> posting list, and most index data structures lay these out so that posting lists are sorted and compressed together. Traditional database indexes like B-trees are optimized for rapid insertion and deletion, while inverted indexes tend to be optimized for batch processing, because you typically deconstruct text into words for a large batch and then lazily integrate this batch into the main index.

Part of this is about scale; a row in a database typically has a single column or maybe 2-3 columns in a composite index; but a document text may tokenize into thousands, hundreds of thousands, or millions of words. At this scale, the fine-grained nature of words mean B-trees aren't as a good a fit.

Another part of it is that inverted indexes aren't for point queries, which is what B-trees are optimized for; you typically search for many words at a time in order to rank your search results by some function like cosine similarity. You rarely want a single posting; you want the union or intersection of many posting sorted by score.

modulovalue•10h ago
NIT: That's not quite correct if your first statement is meant to imply an equality rather than a subset relation.

The idea of an index is more general, as an index can be built for many different domains. For example, B-trees can index monoidal data and inverted indexes are just an instance of such a monoid that a B-tree can efficiently index.

Furthermore, metric spaces (e.g., levenshtein distance) can also be efficiently indexed using other trees: metric trees. So calling inverted indexes just indexes would be really confusing since string data is not the only kind of data that a database might want to support having efficient indexes for.

atombender•9h ago
My point is that all indexes are "inverted" in the sense that they map some searchable value to occurrences of said value. That is true even if method of comparison is not strict equality.
giovannibonetti•7h ago
Most indexes people hear about are like that. However, there are indexes that work the other way around, like Postgres' Block Range Indexes (BRIN). They are mostly useful as skip indexes - for a given block, they have a summary that tells whether some given data may be there.

The trade-off this kind of index makes is that it is more optimized for (batch) writes than the more popular B-Tree indexes, but it is less optimized for reads on the other hand. If the write throughout of a given table is very high, you might want to remove all B-Tree indexes that are not strongly correlated to the insert order and have BRIN indexes instead. Combine it with table partitioning, and you can add B-Tree indexes in the cold partitions, or even migrate them to columnar storage if available (with the Citus extension).

By the way, a few years ago a Bloom BRIN variant was added, not to be confused with Postgres' Bloom indexes which are something else.

atombender•7h ago
I wouldn't say BRIN indexes are "the other way around"; index structure is still one where data values are looked up to find the area where occurrences exist.

"Coarse" indexes like BRIN and ClickHouse's data-skipping indexes are still indexes in a broad sense of serving to narrow down a search.

___tom___•8h ago
This drove me up the wall, until I researched it.

A document can be viewed as an object with a set of pointers to the words it contains.

The inverse of that, was a word object, with a list of pointers to the documents it is found it. This was referred to an an inverted DOCUMENT index. This is what people would normally just call an index.

At some point, people dropped the "DOCUMENT" part, and started just calling it an "inverted index". This makes no sense, grammatically, as it's the document that is inverted, not the index, but it is what it is.

So, an inverted index is just an index.

nzeid•7h ago
Love this take.
teiferer•6h ago
Wow, thanks for the explanation! That was driving me nuts too, as I was waiting for the point where they would invert the thing they built and what that would look like, though that point never came. But now I don't need to put in the time that you did!

In summary, they are not "inverted index" in the sense of "the inversion of what you'd normally think of as an index" but instead in the sense of "a map which provides the inversion of the map from documents to words in them, in other words, an index".

dvh•9h ago
I recently used inverted index (with ranked document retrieval) and it all took only 66 lines of JavaScript: https://github.com/dvhx/ngspicejs/blob/master/js/search.js and I'm kinda proud of that code, it's compact, without dirty tricks or without being overtly smart. Well except for using 1/term_frequency instead of logarithms, it's easier to debug (sums of fractions instead of random numbers produced by logarithms) and I just left it there, it works fine.
AdieuToLogic•6h ago
A related concept is "Key Word in Context (KWIC)"[0] indicies. These were very common, and useful, in Unix documentation. Another name for them is "permuted index."

0 - https://en.wikipedia.org/wiki/Key_Word_in_Context

Fast and cheap bulk storage: using LVM to cache HDDs on SSDs

https://quantum5.ca/2025/05/11/fast-cheap-bulk-storage-using-lvm-to-cache-hdds-on-ssds/
14•todsacerdoti•1h ago•0 comments

Resizable structs in Zig

https://tristanpemble.com/resizable-structs-in-zig/
97•rvrb•7h ago•42 comments

Show HN: QuickTunes: Apple Music player for Mac with iPod vibes

https://furnacecreek.org/quicktunes/
55•albertru90•5h ago•13 comments

How we rooted Copilot

https://research.eye.security/how-we-rooted-copilot/
273•uponasmile•12h ago•106 comments

Consciousness and being: How humans and AI influence each other

https://habr.com/en/articles/930946/
11•kamil_gr•15h ago•6 comments

Purple Earth hypothesis

https://en.wikipedia.org/wiki/Purple_Earth_hypothesis
190•colinprince•3d ago•55 comments

Paul Dirac and the religion of mathematical beauty (2011) [video]

https://www.youtube.com/watch?v=jPwo1XsKKXg
41•magnifique•6h ago•3 comments

Personal aviation is about to get interesting (2023)

https://www.elidourado.com/p/personal-aviation
65•JumpCrisscross•5h ago•67 comments

Rust running on every GPU

https://rust-gpu.github.io/blog/2025/07/25/rust-on-every-gpu/
499•littlestymaar•18h ago•171 comments

What went wrong for Yahoo

https://dfarq.homeip.net/what-went-wrong-for-yahoo/
132•giuliomagnifico•10h ago•137 comments

Low cost mmWave 60GHz radar sensor for advanced sensing

https://www.infineon.com/part/BGT60TR13C
31•teleforce•3d ago•8 comments

Coronary artery calcium testing can reveal plaque in arteries, but is underused

https://www.nytimes.com/2025/07/26/health/coronary-artery-calcium-heart.html
50•brandonb•7h ago•43 comments

The Electron E1 Processor

https://www.efficient.computer/announcing-electron-e1-processor
4•bane•1h ago•1 comments

Getting decent error reports in Bash when you're using 'set -e'

https://utcc.utoronto.ca/~cks/space/blog/programming/BashGoodSetEReports
86•zdw•3d ago•29 comments

Teach Yourself Programming in Ten Years (1998)

https://norvig.com/21-days.html
59•smartmic•7h ago•14 comments

Torqued Accelerator Using Radiation from the Sun (Tars) for Interstellar Payload

https://arxiv.org/abs/2507.17615
36•virgildotcodes•6h ago•4 comments

Tinyio: A tiny (~200 line) event loop for Python

https://github.com/patrick-kidger/tinyio
49•tehnub•4d ago•12 comments

The natural diamond industry is getting rocked. Thank the lab-grown variety

https://www.cbc.ca/news/business/lab-grown-diamonds-1.7592336
159•geox•16h ago•204 comments

Arvo Pärt at 90

https://www.theguardian.com/music/2025/jul/24/the-god-of-small-things-celebrating-arvo-part-at-90
56•merrier•7h ago•17 comments

Millet mystery: A staple crop failed to take root in ancient Japanese kitchens

https://phys.org/news/2025-07-millet-mystery-staple-crop-root.html
25•PaulHoule•3d ago•7 comments

Where are vacation homes located in the US?

https://www.construction-physics.com/p/where-are-vacation-homes-located
74•rufus_foreman•10h ago•68 comments

Test Results for AMD Zen 5

https://www.agner.org/forum/viewtopic.php?t=287&start=10
213•matt_d•10h ago•39 comments

Shallow water is dangerous too

https://www.jefftk.com/p/shallow-water-is-dangerous-too
96•surprisetalk•3d ago•54 comments

Asyncio: A library with too many sharp corners

https://sailor.li/asyncio
67•chubot•5h ago•62 comments

CCTV footage captures video of an earthquake fault in motion

https://www.smithsonianmag.com/smart-news/cctv-footage-captures-the-first-ever-video-of-an-earthquake-fault-in-motion-shining-a-rare-light-on-seismic-dynamics-180987034/
430•chrononaut•1d ago•77 comments

Large ancient Hawaiian petroglyphs uncovered by waves on Oahu

https://www.sfgate.com/hawaii/article/hawaii-petroglyphs-uncovered-20780579.php
76•c420•4d ago•23 comments

OCaml Programming: Correct and Efficient and Beautiful

https://cs3110.github.io/textbook/cover.html
100•smartmic•7h ago•30 comments

Open Sauce is a confoundingly brilliant Bay Area event

https://www.jeffgeerling.com/blog/2025/open-sauce-confoundingly-brilliant-bay-area-event
320•rbanffy•3d ago•185 comments

Algos and Code Performance: Your Code Works but Can It Handle Real Traffic?

https://beon.tech/blog/optimizing-algorithms-code-performance
19•Telstrom90•3d ago•2 comments

Font-size-adjust Is Useful

https://matklad.github.io/2025/07/16/font-size-adjust.html
162•Bogdanp•3d ago•50 comments