# DiskANN

[![DiskANN Pull Request Build and Test](https://github.com/microsoft/DiskANN/actions/workflows/pr-test.yml/badge.svg)](https://github.com/microsoft/DiskANN/actions/workflows/pr-test.yml)

DiskANN is a suite of scalable, accurate and cost-effective approximate nearest neighbor search
algorithms for large-scale vector search that support real-time changes and simple filters. This
code is based on ideas from the
[DiskANN](https://papers.nips.cc/paper/9527-rand-nsg-fast-accurate-billion-point-nearest-neighbor-search-on-a-single-node.pdf),
[Fresh-DiskANN](https://arxiv.org/abs/2105.09613) and the
[Filtered-DiskANN](https://harsha-simhadri.org/pubs/Filtered-DiskANN23.pdf) papers with further
improvements. This code forked off from [code for NSG](https://github.com/ZJULearning/nsg)
algorithm.

This project has adopted the
[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more
information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or
comments.

See [guidelines](CONTRIBUTING.md) for contributing to this project.

## Linux build:

Install the following packages through apt-get

```bash
sudo apt install make cmake g++ libaio-dev libgoogle-perftools-dev clang-format libboost-all-dev
```

### Install Intel MKL

#### Ubuntu 20.04 or newer

```bash
sudo apt install libmkl-full-dev
```

#### Earlier versions of Ubuntu

Install Intel MKL either by downloading the
[oneAPI MKL installer](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html)
or using
[apt](https://software.intel.com/en-us/articles/installing-intel-free-libs-and-python-apt-repo) (we
tested with build 2019.4-070 and 2022.1.2.146).

```
# OneAPI MKL Installer
wget https://registrationcenter-download.intel.com/akdlm/irc_nas/18487/l_BaseKit_p_2022.1.2.146.sh
sudo sh l_BaseKit_p_2022.1.2.146.sh -a --components intel.oneapi.lin.mkl.devel --action install --eula accept -s
```

### Build

```bash
mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j
```

## Windows build:

The Windows version has been tested with Enterprise editions of Visual Studio 2022, 2019 and 2017.
It should work with the Community and Professional editions as well without any changes.

**Prerequisites:**

- CMake 3.15+ (available in VisualStudio 2019+ or from https://cmake.org)
- NuGet.exe (install from https://www.nuget.org/downloads)
  - The build script will use NuGet to get MKL, OpenMP and Boost packages.
- DiskANN git repository checked out together with submodules. To check out submodules after git
  clone:

```
git submodule init
git submodule update
```

- Environment variables:
  - [optional] If you would like to override the Boost library listed in windows/packages.config.in,
    set BOOST_ROOT to your Boost folder.

**Build steps:**

- Open the "x64 Native Tools Command Prompt for VS 2019" (or corresponding version) and change to
  DiskANN folder
- Create a "build" directory inside it
- Change to the "build" directory and run

```
cmake ..
```

OR for Visual Studio 2017 and earlier:

```
<full-path-to-installed-cmake>\cmake ..
```

- This will create a diskann.sln solution. Open it from VisualStudio and build either Release or
  Debug configuration.
  - Alternatively, use MSBuild:

```
msbuild.exe diskann.sln /m /nologo /t:Build /p:Configuration="Release" /property:Platform="x64"
```

```
* This will also build gperftools submodule for libtcmalloc_minimal dependency.
```

- Generated binaries are stored in the x64/Release or x64/Debug directories.

## Usage:

Please see the following pages on using the compiled code:

- [Commandline interface for building and search SSD based indices](workflows/SSD_index.md)
- [Commandline interface for building and search in memory indices](workflows/in_memory_index.md)
- [Commandline examples for using in-memory streaming indices](workflows/dynamic_index.md)
- [Commandline interface for building and search in memory indices with label data and filters](workflows/filtered_in_memory.md)
- [Commandline interface for building and search SSD based indices with label data and filters](workflows/filtered_ssd_index.md)
- To be added: Python interfaces and docker files

Please cite this software in your work as:

```
@misc{diskann-github,
   author = {Simhadri, Harsha Vardhan and Krishnaswamy, Ravishankar and Srinivasa, Gopal and Subramanya, Suhas Jayaram and Antonijevic, Andrija and Pryce, Dax and Kaczynski, David and Williams, Shane and Gollapudi, Siddarth and Sivashankar, Varun and Karia, Neel and Singh, Aditi and Jaiswal, Shikhar and Mahapatro, Neelam and Adams, Philip and Tower, Bryan}},
   title = {{DiskANN: Graph-structured Indices for Scalable, Fast, Fresh and Filtered Approximate Nearest Neighbor Search}},
   url = {https://github.com/Microsoft/DiskANN},
   version = {0.5},
   year = {2023}
}
```
