Discovering Data Structures: Nearest Neighbor Search and Beyond
Omar Salemohamed, Laurent Charlin, Shivam Garg, Vatsal Sharan, Gregory Valiant
Abstract
We explore if it is possible to learn data structures end-to-end with neural networks, with a focus on the problem of nearest-neighbor (NN) search. To answer this question, we introduce a framework for data structure discovery which adapts to the underlying data distribution and provides fine-grained control over query and space complexity. Crucially, the data structure is learned from scratch, and does not require careful initialization or seeding with candidate data structures. In several settings, we are able to reverse-engineer the learned data structures and query algorithms. For 1D nearest neighbor search, the model discovers optimal distribution (in)dependent algorithms such as binary search and variants of interpolation search. In higher dimensions, the model learns solutions that resemble k-d trees in some regimes, while in others, elements of locality-sensitive hashing emerge. Additionally, the model learns useful representations of high-dimensional data such as images and exploits them to design effective data structures. Beyond NN search, we believe the framework could be a powerful tool for data structure discovery for other problems, and adapt it to the problem of estimating frequencies over a data stream. To encourage future work in this direction, we conclude with a discussion on some of the opportunities and remaining challenges of learning data structures end-to-end. 3
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 44884284-d9d4-48b1-bb64-bebd5004f574Builds on26
- An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn et al.ICLR 2021 · 21,477 citations
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-AwarenessTri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra et al.NeurIPS 2022 · 5,493 citations
- Do Transformers Really Perform Badly for Graph Representation?Chengxuan Ying, Tianle Cai, Shengjie Luo, Shuxin Zheng et al.NeurIPS 2021 · 1,632 citations
- Perceiver: General Perception with Iterative AttentionAndrew Jaegle, Felix Gimeno, Andy Brock, Oriol Vinyals et al.ICML 2021 · 1,399 citations
- What Can Transformers Learn In-Context? A Case Study of Simple Function ClassesShivam Garg, Dimitris Tsipras, Percy Liang, Gregory ValiantNeurIPS 2022 · 883 citations
Related papers
- I/O Efficient Approximate Nearest Neighbour Search based on Learned FunctionsMingjie Li, Ying Zhang, Yifang Sun, Wei Wang et al.ICDE 2020 · 23 citations
- Graph-based Approximate Nearest Neighbor Search by Deep Reinforcement RoutingMingjie Li, Junhao Lin, Dian Ouyang, Ying Zhang et al.ACM MM 2025
- Learning to Hash Robustly, GuaranteedAlexandr Andoni, Daniel BeagleholeICML 2022 · 12 citations
- Learning Space Partitions for Nearest Neighbor SearchYihe Dong, Piotr Indyk, Ilya P. Razenshteyn, Tal WagnerICLR 2020 · 104 citations
- A New Paradigm in Tuning Learned Indexes: A Reinforcement Learning Enhanced ApproachTaiyi Wang, Liang Liang, Guang Yang, Thomas Heinis et al.SIGMOD 2025 · 2 citations
