Annoy logo

Annoy

Fast, memory-efficient approximate nearest-neighbor search with shared on-disk indexes

Annoy provides high-speed approximate nearest-neighbor queries using static, mmap-able indexes that can be shared across processes, with low memory footprint and support for multiple distance metrics.

Overview

Overview

Annoy is designed for developers who need rapid similarity search over large, high‑dimensional datasets. It builds a forest of random projection trees that enable fast approximate nearest‑neighbor queries while keeping memory usage minimal.

Core Capabilities

The library creates static indexes that are saved to disk and can be memory‑mapped by any number of processes, allowing instant lookups without reloading. It supports Euclidean, Manhattan, cosine (angular), Hamming, and dot‑product metrics, offers multi‑threaded index construction, and provides native Python bindings alongside a C++ API.

Deployment Scenarios

Because indexes are immutable after building, they can be generated once and distributed across workers in batch jobs, Hadoop pipelines, or production services. The on‑disk build option lets you handle datasets that exceed available RAM, and the mmap approach enables efficient sharing across multiple processes.

Highlights

Static file indexes that can be mmap‑shared across processes
Supports Euclidean, Manhattan, cosine, Hamming, and dot product metrics
Low memory usage with optional on‑disk building for massive datasets
Multi‑threaded index construction and Python bindings for easy integration

Pros

  • Fast query latency even with millions of vectors
  • Small on‑disk and in‑memory footprint
  • Simple API works in Python and C++
  • Indexes can be reused without rebuilding

Considerations

  • Index is immutable after build – cannot add items later
  • Performance degrades with very high dimensionality (>1000)
  • Only integer item identifiers are supported
  • Approximate results may miss exact nearest neighbors

Managed products teams compare with

When teams consider Annoy, these hosted platforms usually appear on the same shortlist.

Pinecone logo

Pinecone

Managed vector database for AI applications

Qdrant logo

Qdrant

Open-source vector database

ZIL

Zilliz

Managed vector database service for AI applications

Looking for a hosted option? These are the services engineering teams benchmark against before choosing open source.

Fit guide

Great for

  • Recommendation engines needing rapid similarity lookups
  • Batch processing pipelines where a single index is shared across workers
  • Applications with limited RAM that benefit from disk‑mapped indexes
  • Projects that require multiple distance metrics without switching libraries

Not ideal when

  • Real‑time systems that must insert new vectors continuously
  • Datasets with dimensions in the tens of thousands
  • Use cases requiring string or UUID identifiers without external mapping
  • Scenarios demanding exact nearest‑neighbor guarantees

How teams use it

Music recommendation at Spotify

Retrieve similar tracks in milliseconds, powering personalized playlists

Large‑scale image similarity search

Serve nearest images from a pre‑computed index for visual search applications

Hadoop job for user‑item matching

Each mapper mmaps the same index, enabling fast matching across massive datasets

Realtime ad‑targeting prototype

Build the index once and serve queries across multiple services with minimal latency

Tech snapshot

C++49%
Python31%
Lua10%
Go5%
C3%
SWIG2%

Tags

c-plus-plusluaapproximate-nearest-neighbor-searchpythonlocality-sensitive-hashingnearest-neighbor-searchgolang

Frequently asked questions

How does Annoy achieve fast queries?

It builds multiple random projection trees and uses memory‑mapped static indexes, reducing I/O and memory overhead.

Can I add items after building the index?

No, the index is immutable after the build step; you must rebuild to incorporate new vectors.

Which distance metrics are available?

Euclidean, Manhattan, cosine (angular), Hamming, and dot product.

How large a dataset can Annoy handle?

It can index millions of vectors; on‑disk building allows datasets larger than available RAM.

Is there GPU support?

Annoy is CPU‑only and does not provide GPU acceleration.

Project at a glance

Active
Stars
14,132
Watchers
14,132
Forks
1,219
LicenseApache-2.0
Repo age12 years old
Last commit3 months ago
Primary languageC++

Last synced 10 hours ago