Annoy

Spotify's C++ and Python library for memory-mapped, read-only approximate nearest neighbor indexes.

Open SourceSelf HostedOffline Capable
0.0 (0)

About

Spotify uses Annoy to find similar tracks and users for recommendations, and the design reflects that job: you add integer-keyed vectors, build a forest of random-projection trees, write the index to a file, then memory-map it from many processes. Because the file sits in the OS page cache, many workers can query one index without private copies, and an index can be built once and shipped like any other artifact. Metrics are angular (cosine), Euclidean, Manhattan, Hamming and dot product. Recall is tuned in two places: extra trees at build time improve it but enlarge the file, and a higher search_k per lookup improves it but slows queries. The catch is immutability: a built index cannot take new items, so changing data means a rebuild, though an on-disk build mode handles datasets larger than RAM. The core is C++ included through one header, with official Python bindings on pip and community ports for R, Java, Go, Rust and Node. It runs on CPU, needs no server, and is Apache-2.0 licensed. A good fit for batch-built embedding indexes of moderate dimension; for frequent updates or metadata filtering, use a vector database.

Should you use Annoy?

Pick it when

Pick Annoy when you build an index once, ship it as a file, and serve lookups from many worker processes that share it through memory mapping, such as nightly recommendation or embedding tables on CPU-only servers.

Look elsewhere when

Skip it if vectors change during the day: Annoy indexes are read-only, so every addition means a rebuild. HNSWlib or Voyager accept new items in place, and FAISS adds product quantization for compressed billion-scale indexes.

Alternatives to Annoy

  • Voyager

    Spotify's newer HNSW library with matching Python and Java bindings that accepts new items; holds the index in RAM instead of sharing one memory-mapped file.

  • HNSWlib

    Supports incremental inserts, updates, and deletions where Annoy needs a full rebuild, but gives up Annoy's low-overhead sharing of one mapped file.

  • FAISS

    Many more index types, product quantization, and GPU search for billion-scale data, at the cost of a heavier dependency and more tuning than Annoy.

  • USearch

    Also serves memory-mapped indexes from disk, while an in-RAM index accepts new vectors, and f16, i8, and binary precision shrink the files.

Reviews (0)

Leave a Review

No reviews yet. Be the first to review!

Details

Price
Free
Platform
Local/Desktop
Difficulty
Easy (2/5)
License
Apache-2.0
Added
Apr 3, 2026

Tags