The PGM-index

The Piecewise Geometric Model index (PGM-index) is a data structure that enables fast lookup, predecessor, range searches and updates in arrays of billions of items using orders of magnitude less space than traditional indexes while providing the same worst-case query time guarantees.

Source PyGM Docs Papers

Unlike traditional tree-based indexes that are blind to the possible regularity present in the input data, the PGM-index exploits a learned mapping between the indexed keys and their location in memory. The succinctness of this mapping, coupled with a peculiar recursive construction algorithm, makes the PGM-index a data structure that dominates traditional indexes by orders of magnitude in space while still offering the best query and update time performance.

In addition to that, the PGM-index offers compression, distribution-awareness, and multi-criteria adaptability, thus resulting suitable for addressing the increasing demand for big data systems that adapt to the rapidly changing constraints imposed by the wide range of modern devices and applications.




It is one of the first results on learned indexes which achieves astonishing performance by capturing the distribution of the input data.


Unlike some early results, the PGM‑index is a learned index with provably optimal time and space complexity guarantees.
Memory efficient

Memory efficient

It always consumes less space than traditional tree-based indexes, often orders of magnitude less. If this is not enough, there is even a compressed version.
Fast construction

Fast construction

Even on gigabytes of data, its construction speed matches the one of traditional indexes.
Tunable page size


You can tune the index to adapt to the memory hierarchy, space occupancy and time efficiency by properly setting one of its parameters.

Automatic tuner

The automatic tuner lets you specify a maximum lookup time (or space footprint) and get the corresponding most space-efficient (or fastest) PGM‑index configuration.

Running example

#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include "pgm/pgm_index.hpp"

int main() {
    // Generate some random data
    std::vector<int> data(1000000);
    std::generate(data.begin(), data.end(), std::rand);
    std::sort(data.begin(), data.end());

    // Construct the PGM-index
    const int epsilon = 128; // space-time trade-off parameter
    pgm::PGMIndex<int, epsilon> index(data);

    // Query the PGM-index
    auto q = 42;
    auto range =;
    auto lo = data.begin() + range.lo;
    auto hi = data.begin() + range.hi;
    std::cout << *std::lower_bound(lo, hi, q);

    return 0;

Read more about the C++ API here.


  1. Paolo Ferragina and Giorgio Vinciguerra. The PGM-index: a fully-dynamic compressed learned index with provable worst-case bounds. PVLDB, 13(8): 1162-1175, 2020.

    PDF Video DOI

  2. Paolo Ferragina, Fabrizio Lillo, and Giorgio Vinciguerra. Why are learned indexes so effective?. In: Proceedings of the 37th International Conference on Machine Learning (ICML 2020).

    PDF Video

Cite us

If you use the library please put a link to this website and cite the following paper:

Paolo Ferragina and Giorgio Vinciguerra. The PGM-index: a fully-dynamic compressed learned index with provable worst-case bounds. PVLDB, 13(8): 1162-1175, 2020.

  Author = {Paolo Ferragina and Giorgio Vinciguerra},
  Title = {The {PGM-index}: a fully-dynamic compressed learned index with provable worst-case bounds},
  Year = {2020},
  Volume = {13},
  Number = {8},
  Pages = {1162--1175},
  Doi = {10.14778/3389133.3389135},
  Url = {},
  Issn = {2150-8097},
  Journal = {{PVLDB}}}

Some interesting uses of the PGM-index

  • PyGM. A Python package of sorted containers that uses the PGM-index for efficient query performance and memory usage.

We would love to be informed whether you used our code in your projects. We will list the most interesting applications of the PGM-index here!


There are a lot of ways to contribute on this project, just to mention a few:

  1. Engineering the support for insertions and deletions. done!
  2. Making the index SIMD aware. For example, you could set the error to the SIMD register width and use vector instructions to traverse the levels of the index with no branches.
  3. Adding support for concurrent and batch queries.

Feel free to submit issues and pull requests in the GitHub repository.