liveBook · Manning

Inverted index

As explained in AI-Powered Search

An inverted index is a data structure that maps terms or tokens to the documents and locations where they occur.

When someone searches a document collection, the engine needs to find matching documents without reading every document in full. An inverted index provides that lookup: for each field and term, it stores a postings list of documents containing the term. Postings can also record positions within documents. section 2.1.3 section 5.4.3

Indexing and searching work in opposite directions:

  • At index time, process and normalize document tokens, then record each term under its field with references to document identifiers and positions. section 13.2.1 section 5.4.3
  • At search time, process the query terms the same way, retrieve their postings lists, and combine matches. Boolean operations can select documents containing particular combinations of terms; positional matching can distinguish term sequences. section 13.2.1 section 2.1.3
  • Rank the retrieved documents with a scoring method such as BM25. A fast match is not, by itself, proof that the result answers the user's intent. section 13.2.1

A small postings lookup

Suppose three job documents have skills fields: document 1 contains “Python” and “SQL”; document 2 contains “Python”; document 3 contains “SQL.” The skills postings lists are python → [1, 2] and sql → [1, 3]. Intersecting them finds document 1 for a query requiring both skills. Real postings can also retain positions, allowing more precise matching within a field. section 5.4.3 section 2.1.3

The reverse mapping—a forward index—lists the terms in each document field. Together, the two directions support traversal from a term to shared documents and onward to other terms. This can expose relationships in a semantic knowledge graph without explicitly modeling its nodes and edges. In Lucene-based search engines, doc values commonly provide the forward mapping for faceting. section 5.4.3 section 2.1.3

Figure 5.5 Three representations of an SKG. The data structure view shows terms mapped to sets of documents, the set-theory view shows how the intersection of sets of documents forms the relationship between them, and the graph view shows the nodes and edges.
figure

Compare term-to-document postings, intersections of document sets, and the resulting graph relationships. section 5.4.3

An inverted index also serves as a sparse representation of documents: terms act as dimensions, and query expansion can supply additional weighted terms. Its limitation remains query-term dependence—matching strings and their normalized forms does not establish that a document is an objectively good semantic match. section 7.4.3 section 13.2.1

How AI-Powered Search covers it

How deep it goes
Explains field-specific postings, positions, query lookup, and the forward-index counterpart, but not low-level index storage algorithms.
Examples
Uses job documents with job-title, description, and skills fields to show field-level indexing and its forward-index counterpart.
What it assumes
Introduces postings through a textbook-index analogy while assuming basic familiarity with documents and search queries.
What you can do after
Operate/configure it for lexical lookup, and enable doc values when a Lucene-based field needs a forward index for faceting.
How it connects
Connects postings lists and Boolean matching to BM25, sparse vectors, forward indexes, faceting, and semantic knowledge graphs.

Also explained in

Compare how 5 books explain inverted index →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Search. The section links point to the parts of the book it draws on.