An approximate nearest neighbor (ANN) algorithm finds vectors close to a query vector without comparing the query against every stored vector. It trades exact nearest-neighbor results for faster search over large collections. In a listing search system, ANN retrieves semantically similar candidates; price and date filters then enforce explicit constraints, and a final ranker decides what to show. section 4.5.1 section 4.2.6
A production search pipeline can separate work that happens before a query from work that must happen during it:
- Generate and store listing embeddings in a vector database when listings are created or updated, without making users wait for that work. section 4.2.6
- Embed the incoming query, run ANN search for semantic candidates, apply traditional filters, then rank the remaining results using semantic similarity and other factors. section 4.2.6
Hierarchical Navigable Small World (HNSW) is one way to implement ANN search. Its index connects vectors in layers, from a sparse upper graph to a bottom layer containing all vectors. Search follows connections toward the query at one layer, then descends to refine its choice. This avoids the full O(n) scan required by naive nearest-neighbor search; the described HNSW approach has O(log n) search complexity. Index settings make the speed–quality trade-off operational: increasing M, the maximum connections per node, or efConstruction, the thoroughness of index building, can improve accuracy while using more memory or taking longer to index. Values of 16 and 100, respectively, are suggested starting points rather than substitutes for testing. section 4.5.1
Figure 4.7 HNSW indexes vectors in multiple layers. The search path demonstrates how queries efficiently traverse from sparse upper layers to dense lower layers.
The layered index and search path make it easier to see how HNSW narrows the search without scanning every vector. section 4.5.1
Evaluate ANN as part of the whole search experience, not just as an isolated retrieval step. Ranking accuracy matters, but booking conversion, user satisfaction, and results for long-tail queries show whether the complete pipeline helps users. section 4.2.6




