Study Vault Search notes, aliases and full text
Graph
ConceptDBISAI-written · proofread

Inverted Index

An inverted index maps each word to its inverted list, the sorted list of IDs of the documents containing it, optionally with a score per posting such as tf or BM25.

Definition#

An inverted index is a data structure that maps each distinct term tt to a sorted list of documents containing tt, called an inverted list (or postings list). Each entry in the list pairs the document identifier with a score (commonly tf or tf.idf).

Inverted Index={t↦[(Di1,s1), (Di2,s2), …]∣t∈vocabulary}\text{Inverted Index} = \{ t \mapsto [(D_{i_1}, s_1),\ (D_{i_2}, s_2),\ \ldots] \mid t \in \text{vocabulary} \}

where scores sjs_j are sorted in descending order (or documents by ID).

Construction#

For each document DD in the corpus:

  1. Tokenize DD into terms.
  2. For each term tt
    1. compute its score ss (e.g., tf(t,D)\text{tf}(t, D)).
    2. Append (D,s)(D, s) to the inverted list of tt.

Query Processing#

SemanticsOperationAlgorithm
AND (all terms required)Intersection of inverted listsList Intersection and Search
OR (any term sufficient)Union of inverted listsMerge

For multi-keyword queries, retrieve the inverted list for each query term, then intersect or merge the lists and aggregate scores.

Example#

Documents:

  • D1D_1: “b c a c d c”
  • D2D_2: “b c a c d c b c”

Inverted index with tf scores:

TermPostings
a(D1,1), (D2,1)(D_1, 1),\ (D_2, 1)
b(D1,1), (D2,2)(D_1, 1),\ (D_2, 2)
c(D1,3), (D2,4)(D_1, 3),\ (D_2, 4)
d(D1,1), (D2,1)(D_1, 1),\ (D_2, 1)

Properties#

  • Space: O(∑tdf(t))O(\sum_{t} \text{df}(t)) where df(t)\text{df}(t) is the number of documents containing tt.
  • In practice, most entries are zero (sparse), so the inverted index is far more compact than a full term-document matrix.
  • Inverted lists are typically stored sorted by document ID to enable efficient intersection.

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only