Inverted index

An inverted index is a data structure that maps each term to the list of documents containing it, allowing an engine to resolve a keyword query without scanning the corpus.

It is called inverted because it reverses the natural direction of a document. Instead of document → words, it stores word → documents, usually with positions and frequencies attached so that phrase matching and scoring are possible.

Nearly every keyword search engine in production — Lucene, Elasticsearch, OpenSearch, Solr, Typesense, Meilisearch, Postgres full-text — is built on some variant of this structure, paired with a scoring function such as BM25.

Inverted indexes are exceptionally good at precision on exact terms: SKUs, model numbers, names, error codes. They are poor at meaning, because "couch" and "sofa" are simply different keys. That weakness is what semantic retrieval was introduced to cover.