Inferensys

Glossary

Inverted Index

A database index data structure that maps each unique term to a list of documents containing it, enabling fast full-text search by avoiding a sequential scan of all documents.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
DATA STRUCTURE

What is an Inverted Index?

An inverted index is a database index mapping each unique term to a list of documents containing it, enabling fast full-text search by avoiding sequential scans.

An inverted index is a hash map-like data structure that stores a mapping from content terms to their locations in a document collection. Unlike a forward index that maps documents to words, the inverted structure maps each unique term to a postings list—a sorted list of document IDs where that term appears, often accompanied by frequency and positional metadata. This inversion allows a search engine to immediately retrieve all documents matching a query term without scanning the entire corpus.

During query execution, the engine retrieves the postings lists for each query term and performs list intersection or union operations to compute result sets. The structure supports advanced operations like phrase matching by storing term positions within each document. While highly efficient for sparse, lexical retrieval, the index size can grow substantially for large corpora, requiring compression techniques like delta encoding and variable-byte encoding to manage storage and memory overhead.

CORE DATA STRUCTURE

Key Characteristics of an Inverted Index

An inverted index is the foundational data structure enabling sub-second full-text search. It maps terms to their locations, turning a linear scan of millions of documents into a rapid dictionary lookup.

01

The Dictionary and Postings

The index is logically split into two main parts: a dictionary of unique terms and a postings list for each term. The dictionary is a sorted list of all unique tokens found in the document collection. For each term, a postings list stores the identifiers of every document containing that term, along with metadata like term frequency and positional offsets for phrase matching.

02

Index Construction via Sorting

Building an inverted index at scale typically uses Blocked Sort-Based Indexing (BSBI). The process involves:

  • Collecting term-documentID pairs from each document.
  • Sorting these pairs by term as the primary key.
  • Grouping by term to create the final postings lists. This external sorting algorithm is critical for indexing corpora that vastly exceed available RAM.
03

Skip Pointers for Query Speed

To accelerate multi-term Boolean AND queries, postings lists often include skip pointers. These are intra-list shortcuts that allow the query engine to jump ahead to a specific document ID without scanning every entry. For example, when intersecting the postings list for 'machine' and 'learning', a skip pointer on the longer list can bypass thousands of irrelevant document IDs.

04

Delta Encoding for Compression

Postings lists are highly compressible. Since document IDs are stored in ascending order, they are converted to d-gaps (the difference between consecutive IDs). Small gaps are then encoded using variable-byte or Elias gamma coding to minimize storage. This drastically reduces the memory footprint and I/O cost, keeping the index in RAM for maximum performance.

05

Positional vs. Non-Positional

A non-positional index stores only document IDs and term frequencies, sufficient for basic ranking functions like BM25. A positional index expands the postings to include the exact byte or word offset of each term occurrence. This added granularity is essential for phrase queries (e.g., 'artificial intelligence') and proximity operators, at the cost of roughly 2-4x larger index size.

06

Dynamic Indexing with Log-Structured Merge Trees

While a static index is built offline, dynamic systems like Elasticsearch use a Log-Structured Merge (LSM) tree approach. New documents are written to a small, mutable in-memory buffer. When the buffer is full, it is flushed to disk as a new immutable segment. A background process continuously merges these smaller segments into larger ones, optimizing the index without blocking writes.

INVERTED INDEX

Frequently Asked Questions

Clear, technical answers to the most common questions about the inverted index data structure, its mechanics, and its role in modern search infrastructure.

An inverted index is a database index data structure that maps each unique term to a list of documents containing it, enabling fast full-text search by avoiding a sequential scan of all documents. The structure consists of two core components: a dictionary (or vocabulary) of all unique terms, and a set of postings lists—one for each term—that record the document IDs and often the term positions within those documents. During query processing, the search engine looks up each query term in the dictionary, retrieves the corresponding postings lists, and performs set operations (intersection for AND, union for OR) to identify matching documents. This is the inverse of a forward index, which maps documents to the terms they contain. By inverting the relationship, the system can instantly locate all documents containing a specific word without scanning the entire corpus.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.