# Voyager

> Fast approximate nearest-neighbor search for embeddings, with matching Python and Java bindings

- Category: Retrieval & Knowledge (RAG) / Vector Databases
- Language: Python, Java
- Licence: Apache-2.0
- Repository: https://github.com/spotify/voyager
- Website: https://spotify.github.io/voyager/
- Canonical page: https://ai-tldr.dev/tools/voyager/

## In short

Voyager is a library for fast approximate nearest-neighbor search over an in-memory collection of vectors. It is built on the HNSW algorithm (based on the hnswlib package) and adds extra features for convenience and speed. It sits in the Vector Databases category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python, Java and licensed Apache-2.0.

## Overview

Voyager is a library for fast approximate nearest-neighbor search over an in-memory collection of vectors. It is built on the HNSW algorithm (based on the hnswlib package) and adds extra features for convenience and speed. Spotify uses it in production, where it is queried hundreds of millions of times per day.

It is an embedded, in-process library rather than a separate database server: you build an index inside your application, query it directly, and save or load it from disk. It ships bindings for both Python and Java (and Scala via the Java artifact) with feature parity and index compatibility, so an index built in one language can be loaded in the other.

It fits the embedded vector-database category and is aimed at developers who need similarity search over embeddings without running a standalone service. The project positions itself as a successor to Spotify's Annoy, offering higher recall.

## What it does

- HNSW-based approximate nearest-neighbor search over in-memory vectors
- Python and Java bindings with feature parity and cross-language index compatibility
- Indexes can be saved to disk and reloaded later, including across languages
- Used in production at Spotify, serving hundreds of millions of queries per day
- Higher recall than Annoy, the library it is intended to succeed
- Prebuilt wheels for Linux, macOS, and Windows across Python 3.9-3.13

## Getting started

Install the package for your language, then build an index, add vectors, and query for nearest neighbors.

1. Install for Python

   Install Voyager from PyPI.

```bash
pip install voyager
```

2. Install for Java

   Add the Voyager artifact to your pom.xml. Check the Releases page for the latest version.

```xml
<dependency>
  <groupId>com.spotify</groupId>
  <artifactId>voyager</artifactId>
  <version>2.1.0</version>
</dependency>
```

3. Build an index and query it (Python)

   Create an Index, add vectors, query for the closest items, and save the index to disk.

```python
import numpy as np
from voyager import Index, Space

# Create an empty Index object that can store vectors:
index = Index(Space.Euclidean, num_dimensions=5)
id_a = index.add_item([1, 2, 3, 4, 5])
id_b = index.add_item([6, 7, 8, 9, 10])

print(id_a)  # => 0
print(id_b)  # => 1

# Find the two closest elements:
neighbors, distances = index.query([1, 2, 3, 4, 5], k=2)
print(neighbors)  # => [0, 1]
print(distances)  # => [0.0, 125.0]

# Save the index to disk to reload later (or in Java!)
index.save("output_file.voy")
```

## When to use it

- Add similarity search over text or image embeddings to an app without running a separate vector database service
- Power recommendation and related-item features by querying nearest neighbors in an embedding space
- Build an index in Python during offline processing, then load and serve it from a Java or Scala application
- Migrate from Annoy to get higher recall while keeping an embedded, in-process workflow
