Skip to main content

Predict, Don't Search : Are Learned Indexes the future ?

Updated 4 min readMarkdown

If you have worked on any production system, you would have heard about the terms "indexes" in software, but in this blog we are shedding light on a concept known as "learned indexes".

Some of the traditional index structures that are the backbone of all databases are B-Tree, Hash-maps, Bloom filters.

Enter AI: Predicting Instead of Searching

“Learned indexes” are a concept that represents a paradigm shift in how we think about storing and accessing data. Instead of relying on standard indexing techniques, they propose the use of machine learning models to predict data positions, potentially reducing resource usage and speeding up data access.

Traditional Indexes

When we discuss efficient data reading, the first term that comes up is indexing. Traditional indexes are fundamental data structures that databases use to find information quickly.

  1. B-Tree
    B-Trees, given a key, they “predict” the location of a value within a key-sorted set. It keeps data sorted in a self-balancing, tree-like structure. This allows databases to find data in O(logn) time without scanning every row in a table.
    Given a key, it provides a position that guarantee that the key of the record at that position is the first key equal or higher than the look-up key.

    For efficiency purpose, B-Tree does not indexes every key, they index the first key of every nth record. They are extremely cache- and operation-efficient as they keep the top nodes always in cache and access other pages if needed.

    But B-Trees also have their limitations.
    1. They need rebalancing whenever new data is added.
    2. A B-Tree requires log n operations for lookup.
    3. They are designed for scenarios where records are fixed-length and memory is continuously mapped, which might not always be the case in modern distributed databases.

Learned Indexes

Learned Indexes are a new thought process different from the traditional indexes. The basis of the whole theory is that traditional indexes like B-Trees work on a fixed pattern, and lag behind when there can be optimisations learned from the data itself.

It proposes that with the use of neural networks, we can predict the location of data in a database. The ability to predict the location holds the potential to transform how we access data today. By the use of machine learning, the database can be taught to adapt to the specific needs of the dataset that its managing.

The potential ROI of Learned Indexes :

  1. Reduced Latency : Prediction of data position can be faster than traditional indexes, for example : for a linearly increasing id based dataset, the B-Tree would take O(log n) lookup, but it could be O(1) for a learned index.

  2. Decreased Index Size: Machine learning also opens possibilities for various different compactions, cache efficiency improvements.

  3. For Modern Hardware : Learned Indexes would work with the direction of hardware the world is heading to, GPU / TPU based instead of purely CPU.

  4. Cost-Effective Performance: Reduces the need for extensive hardware, lowering operational costs by minimising storage and computational overhead.

The Secret Sauce: The Recursive Model Index (RMI)

Using a neural network to predict data locations seems promising, but researchers faced a practical problem. A single large machine learning model is costly and struggles with precise accuracy when identifying a specific record among millions.

They solved this by creating the Recursive Model Index (RMI). Instead of one big model, RMI uses a smart setup of smaller, quicker models.

  • The process begins with a basic model that uses the search key to make a rough guess. This guess helps choose a more specialized model in the next stage. This pattern repeats until the final model at the bottom gives the exact location with a small error margin.

Challenges

While the concept does sound promising, and worth experimenting with, it is still a big unknown. Accuracy of the model, predictability, reliability, computational cost, hardware cost, and the experimental nature, if all to be compared with the traditional indexes, there's a lot of work to be figured out, before we see this approach coming to fruition.

The question still stands though, do learned indexes beat efficient implementation of traditional indexes based on data structures, if somebody answers it tomorrow after trying it out, i'll be there to read it.

Conclusion

As technology advances, particularly in machine learning and computational hardware, learned indexes might become a regular in our lives. Adopting these innovative structures could radically improve data retrieval processes and redefine performance standards in database management.

Sources :
1. https://arxiv.org/pdf/1712.01208
2. https://databasearchitects.blogspot.com/2017/12/the-case-for-b-tree-index-structures.html

No comments yet. Be the first to comment.