Non Metric Space (Approximate) Library

A Non-Metric Space Library ('NMSLIB' <>) wrapper, which according to the authors "is an efficient cross-platform similarity search library and a toolkit for evaluation of similarity search methods. The goal of the 'NMSLIB' <> Library is to create an effective and comprehensive toolkit for searching in generic non-metric spaces. Being comprehensive is important, because no single method is likely to be sufficient in all cases. Also note that exact solutions are hardly efficient in high dimensions and/or non-metric spaces. Hence, the main focus is on approximate methods". The wrapper also includes Approximate Kernel k-Nearest-Neighbor functions based on the 'NMSLIB' <> 'Python' Library.

The nmslibR package is a wrapper of the Non-Metric Space Library (NMSLIB) python package. More details on the functionality of the nmslibR package can be found in the package Documentation and Vignette.


System Requirements

  • Python (>= 2.7)

All modules should be installed in the default python configuration (the configuration that the R-session displays as default), otherwise errors will occur during the nmslibR package installation (reticulate::py_discover_config() might be useful here).

The installation notes for Linux, Macintosh, Windows are based on Python 3.


Installation of the system requirements,

sudo apt-get install python3-pip
sudo pip3 install --upgrade setuptools
sudo pip3 install -U numpy
sudo pip3 install --upgrade scipy
sudo apt-get install libboost-all-dev libgsl0-dev libeigen3-dev
sudo apt-get install cmake
pip3 install --upgrade pybind11
sudo pip3 install nmslib


Installation of the system requirements,

dnf install python3-pip
sudo pip3 install --upgrade setuptools
sudo pip3 install -U numpy
sudo pip3 install --upgrade scipy
yum install python3-devel
yum install boost-devel
yum install gsl-devel
yum install eigen3-devel
pip3 install --upgrade pybind11
sudo pip3 install nmslib

Macintosh OSX

Upgrade python to version 3 using,

brew upgrade python

Install the requirements,

sudo pip3 install --upgrade pip setuptools wheel
sudo pip3 install -U numpy
sudo pip3 install --upgrade scipy
brew install boost
brew install eigen
brew install gsl
brew install cmake
brew link --overwrite cmake
pip3 install --upgrade pybind11
sudo pip3 install nmslib

After a successful installation of the requirements the user should open an R session and give the following reticulate command to change to the relevant (brew-python) directory (otherwise the nmslibR package won't work properly),


and then,


to validate that a user is in the python version where nmslibR is installed.

Windows OS

First download of for windows

Update the Environment variables ( Control Panel >> System and Security >> System >> Advanced system settings >> Environment variables >> System variables >> Path >> Edit ) by adding ( for instance in case of python 2.7 ),


Install the Build Tools for Visual Studio

Open the Command prompt (console) and install / upgrade the system requirements,

pip3 install --upgrade pip setuptools wheel
pip3 install -U numpy
pip3 install --upgrade scipy

Installation of cmake

First download cmake for Windows, win64-x64 Installer. Once the file is downloaded run the .exe file and during installation make sure to add CMake to the system PATH for all users.

Then install the nmslib library,

pip3 install --upgrade pybind11
pip3 install nmslib

Installation of the nmslibR package

To install the package from CRAN use,


and to download the latest version from Github use the install_github function of the devtools package,

devtools::install_github(repo = 'mlampros/nmslibR')

Use the following link to report bugs/issues,


nmslibR 1.0.3

I updated the file and especially the installation instructions for all mentioned operating systems i.e. Linux, Macintosh, Windows (switch from python2 to python3 due to pybind11 issues).

nmslibR 1.0.2

  • The dgCMatrix_2scipy_sparse function was renamed to TO_scipy_sparse and now accepts either a dgCMatrix or a dgRMatrix as input. The appropriate format for the nmslibR package in case of sparse matrices is the dgRMatrix format (scipy.sparse.csr_matrix)
  • I added an onload.R file to inform the users about the previous change [ related with the issue : ]
  • I removed the utils.R file which included internal functions of the KernelKnn package. Rather than including the file I now use the getFromNamespace function of the utils package.
  • Due to the previous changes I modified the Vignette and the tests too.

nmslibR 1.0.1

  • I commented the example(s) and test(s) related to the dgCMatrix_2scipy_sparse function [ if (["sysname"] != 'Darwin') ], because the scipy-sparse library on CRAN is not upgraded and the older version includes a bug (TypeError : could not interpret data type). This leads to an error on Macintosh Operating System ( reference : )
  • I added links to the github repository (master repository, issues)

nmslibR 1.0.0

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


1.0.6 by Lampros Mouselimis, 4 months ago

Report a bug at

Browse source code at

Authors: Lampros Mouselimis [aut, cre] , B. Naidan [cph] (Author of the Non-Metric Space Library (NMSLIB)) , L. Boytsov [cph] (Author of the Non-Metric Space Library (NMSLIB)) , Yu. Malkov [cph] (Author of the Non-Metric Space Library (NMSLIB)) , B. Frederickson [cph] (Author of the Non-Metric Space Library (NMSLIB)) , D. Novak [cph] (Author of the Non-Metric Space Library (NMSLIB))

Documentation:   PDF Manual  

Apache License (>= 2) license

Imports Rcpp, reticulate, R6, Matrix, KernelKnn, utils

Suggests testthat, covr, knitr, rmarkdown

Linking to Rcpp, RcppArmadillo

System requirements: python3-dev: apt-get install -y python3-dev (deb), python3-pip: apt-get install -y python3-pip (deb), numpy: pip3 install numpy (deb), scipy: pip3 install scipy (deb), nmslib: pip3 install --no-binary :all: nmslib (deb)

See at CRAN