UUtah Fall 2026 | Data Mining | L5 NN Search
Overview
Nearest-neighbor search turns a distance function into a scalable retrieval system by preprocessing data and answering queries without scanning every point. The lecture progresses from exact one-dimensional trees and two-dimensional Voronoi diagrams to approximate KD-trees, locality-sensitive hashing, and Hierarchical Navigable Small World (HNSW) graphs, explaining why HNSW-style vector search works well in high-dimensional practice despite the curse of dimensionality.
Key takeaways
- A balanced binary tree over sorted one-dimensional data supports exact nearest-neighbor queries in O(log N) time with O(N) storage, after O(N log N) preprocessing.
- Exact Voronoi-based search scales poorly beyond two dimensions: its space can grow as N^ceil(D/2), reaching quadratic size at D = 3.
- Approximate search permits a returned point up to 1 + ε times the true nearest-neighbor distance; this relaxation enables pruning and randomized indexing methods.
- Locality-sensitive hashing offers dimension-insensitive approximate-search bounds aside from reading coordinates, but HNSW has proved more effective in many practical high-dimensional benchmarks.
- HNSW combines sparse, randomly promoted graph layers with beam search, using long-range navigation above and multiple candidate paths to reduce local-minimum failures.
- Vector databases make approximate nearest-neighbor retrieval practical for embedding workloads, including Euclidean and cosine similarity search.
Chapters
- The first homework is due at the end of the day; implementation choices can greatly change runtime even when scalability trials are completed.
- Nearest-neighbor search is introduced as a scalability problem: preprocess a dataset once, then retrieve close points efficiently.
- The lecture roadmap leads from basic data structures to modern Hierarchical Navigable Small World graphs.
- Rich Sutton’s 2019 essay, “The Bitter Lesson,” argues that general methods can outperform hand-crafted domain knowledge when given enough data and compute.
- Sutton identifies learning and search as methods that scale; nearest-neighbor retrieval is one way to search for similar examples.
- Search underlies systems such as Google, where finding relevant items across large collections is central.
- Given a dataset X in R^D, a query q, and a distance function, exact nearest-neighbor search returns the point x* minimizing distance(x, q).
- The lecture uses Euclidean distance, while noting that related methods can support cosine or Mahalanobis distance after suitable transformations.
- A K-nearest-neighbor query returns the K closest points, useful when a single match is insufficient.
- A data structure S(X) lets a system spend time preprocessing the dataset instead of scanning all points for every query.
- Search systems can find duplicate or near-duplicate documents, including overly similar homework submissions.
- For prediction, retrieving several labeled neighbors lets a model aggregate their known outcomes rather than rely on one match.
- In R¹, sort the points and build a balanced binary tree whose nodes store split values.
- A query follows the appropriate side of each split in O(log N) time, then checks adjacent sorted points to select the true nearest neighbor.
- The structure uses O(N) space and takes O(N log N) time to build, dominated by sorting.
- A skip list maintains sorted linked-list layers, promoting roughly half the points at random at each successive level.
- Queries traverse the sparse upper layers to narrow their interval, then inspect a constant number of candidates at the bottom.
- The randomized structure uses roughly linear space and supports logarithmic expected query time, providing an analogy for modern layered graph indexes.
- A Voronoi diagram partitions the plane so every location in a cell has the same nearest dataset point.
- In two dimensions, the diagram can be built in O(N log N) time and stored in O(N) space; point-location structures support O(log N) queries.
- For Euclidean distance, diagram edges are perpendicular bisectors and vertices are equidistant from three points.
- In dimension D, Voronoi structure can require N^ceil(D/2) space, which is quadratic already at D = 3.
- The rapidly growing representation prevents extending the efficient two-dimensional exact-search approach directly to high dimensions.
- Approximate nearest-neighbor search relaxes the requirement: the returned point may be up to a factor of 1 + ε farther away than the exact nearest point.
- A KD-tree recursively splits space with axis-aligned boundaries, typically dividing the points roughly in half at each split.
- After finding a candidate near the query, the search prunes cells that cannot intersect the candidate-distance ball, adjusted for the allowed approximation factor.
- Alternating-coordinate KD-trees often work in roughly 10 to 12 dimensions; strategic split directions can extend some implementations to around 100 to 200 dimensions.
- An axis-aligned box enclosing a unit-radius Euclidean ball has volume 2^D, while the ball’s volume relative to that box shrinks sharply as D grows.
- The box’s 2^D corners occupy an increasingly significant share of its volume, making box-based partitions poor approximations to spherical distance neighborhoods.
- This geometric mismatch helps explain why KD-tree-style decompositions become ineffective as dimensionality rises.
- Locality-sensitive hashing (LSH) uses randomized hash functions designed to map nearby points together more often than distant points.
- Its approximate-search costs depend strongly on ε but, apart from reading coordinates, can avoid direct dependence on dimension D.
- For ε = 1, the lecture gives illustrative bounds of about N^(8/7) space and N^(1/7) query time; optimized FALCONN implementations can beat scanning on large, high-dimensional datasets.
- Hierarchical Navigable Small World (HNSW) graphs became highly effective in practice, despite earlier theoretical concerns about graph-search failures.
- The lecture presents HNSW as a high-dimensional extension of the skip-list idea: sparse upper levels guide the search toward a dense base layer.
- HNSW-style systems outperformed the theoretically motivated LSH approach in practical high-dimensional search benchmarks.
- The base structure connects each dataset point to a small number of its nearest neighbors, forming a K-nearest-neighbor graph.
- A query can start at an entry point and greedily move to a neighbor closer to the query.
- Greedy traversal alone can stop at a local minimum or require many hops, which motivates additional search mechanisms.
- Beam search keeps the top K candidates found so far instead of committing to just the single closest current node.
- Retaining multiple candidates (for example, a beam width of 10) makes it less likely that the search gets trapped in a local minimum.
- The candidate beam can continue exploring graph neighbors until no better reachable candidates remain.
- HNSW randomly promotes a fraction of points into sparser upper layers, where longer-range graph edges improve navigation; search descends toward the full K-nearest-neighbor graph at the bottom.
- FAISS, Microsoft DiskANN, Qdrant, and Pinecone are examples of systems associated with modern vector search; implementations also use reduced precision in upper layers to save memory and computation.
- Approximate nearest- and K-nearest-neighbor search is now practical for high-dimensional vectors using Euclidean or cosine distance, and related distance measures can often be transformed into compatible forms.
Transcript excerpt
0:16 So let's get started everyone. So thanks for coming back. Um so um so today we're gonna talk about uh nearest neighbor search. Um so this will be building on like the modeling sort of lecture we had. Um um so last week on Thursday where we talked about the different notions of distance. This is going to be more of like a scalability lecture. Now that we have a notion of distance what can we do with it? Um um so how can we do things efficiently? Um before I get into it, let's um uh so I just want to remind everyone in case you weren't uh I'm so paying attention up until now.
1:03 The first homework assignment is due today at the end of the day. It's be turned into grade scope. Um everyone's been able to figure out grade scope. That's not We had initial trouble syncing stuff, but uh Okay. Um uh so how many people think they've mostly finished the assignment or it's turned in? People still working on it a little bit. All right. Okay, great. So it I there weren't wasn't a lot of activity. Um so in the office hours so uh so if you um but in the future if you get kind of stuck on things uh you know the office hours with TAS are a great resource to help there is still one office hour so
1:54 left there's my time after the lecture if you have questions um and so then Arman will have his office hours uh in the Mel engineering building. So if you after class you grab a quick lunch and and walk back over there. Uh um um so you still have time to consult with them. Uh so great. So okay, good. Um so um uh
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, UofU Data Science.