lorann

Approximate Nearest Neighbor search using reduced-rank regression, with extremely fast queries, tiny memory usage, and rapid indexing on modern vector embeddings.

https://github.com/ejaasaari/lorann

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.9%) to scientific vocabulary

Keywords

approximate-nearest-neighbor-search cpp embeddings machine-learning nearest-neighbor-search nearest-neighbors python vector-database vector-index vector-search
Last synced: 6 months ago · JSON representation

Repository

Approximate Nearest Neighbor search using reduced-rank regression, with extremely fast queries, tiny memory usage, and rapid indexing on modern vector embeddings.

Basic Info
Statistics
  • Stars: 46
  • Watchers: 2
  • Forks: 3
  • Open Issues: 0
  • Releases: 3
Topics
approximate-nearest-neighbor-search cpp embeddings machine-learning nearest-neighbor-search nearest-neighbors python vector-database vector-index vector-search
Created over 1 year ago · Last pushed 7 months ago
Metadata Files
Readme License Citation

README.md

LoRANN

Approximate nearest neighbor search library implementing reduced-rank regression (NeurIPS '24), a technique enabling extremely fast queries, tiny memory usage, and rapid indexing on modern embedding datasets.


Build status Paper Documentation PyPI License GitHub stars

  • Header-only C++17 library with Python bindings
  • Query speed matching state-of-the-art graph methods but with tiny memory usage
  • Optimized for modern high-dimensional (d > 100) embedding data sets
  • Optimized for modern CPU architectures with acceleration for AVX2, AVX-512, and ARM NEON
  • State-of-the-art query speed for GPU batch queries (experimental)
  • Supported data types: float32, float16, bfloat16, uint8, binary
  • Supported distances: (negative) inner product, Euclidean distance, cosine distance
  • Support for index serialization

Getting started

Python

Install the module with pip install lorann

[!TIP] On macOS, it is recommended to use the Homebrew version of Clang as the compiler:

shell script brew install llvm libomp CC=/opt/homebrew/opt/llvm/bin/clang CXX=/opt/homebrew/opt/llvm/bin/clang++ pip install lorann

A minimal example for indexing and querying a dataset using LoRANN is provided below:

```python import lorann import numpy as np from sklearn.datasets import fetch_openml # scikit-learn is used only for loading the data

X, _ = fetchopenml("mnist784", version=1, returnXy=True, as_frame=False) X = np.ascontiguousarray(X, dtype=np.float32)

data = X[:60000] index = lorann.LorannIndex( data=data, nclusters=256, globaldim=128, quantizationbits=8, distance=lorann.L2, )

index.build(verbose=False)

k = 10 approximate = index.search(X[-1], k, clusterstosearch=8, pointstorerank=100) exact = index.exact_search(X[-1], k)

print('Approximate:', approximate) print('Exact:', exact) ```

The data matrix should have type float32, float16, uint8, or uint16 (for bfloat16). For binary data (packed into uint8 bytes using e.g. numpy.packbits), use LorannBinaryIndex.

The distance should be either lorann.L2 (for squared Euclidean distance), lorann.IP (for inner product), or lorann.HAMMING (only for binary data). For cosine distance, normalize vectors to unit norm and use lorann.IP.

For a more detailed example, see examples/example.py.

Python documentation

C++

LoRANN is a header-only library so no installation is required: just include the header lorann/lorann.h. A C++ compiler with C++17 support (e.g. gcc/g++ >= 7) is required.

[!TIP] It is recommended to target the correct instruction set (e.g., by using -march=native) as LoRANN makes heavy use of SIMD intrinsics. The quantized version of LoRANN can use AVX-512 VNNI instructions, available in Intel Cascade Lake (and later) and AMD Zen 4, for improved performance.

Usage is similar to the Python version:

```cpp Lorann::Lorann index(data, nsamples, dim, nclusters, global_dim); index.build();

index.search(query, k, clusterstosearch, pointstorerank, output); ```

For a complete example, see examples/cpp.

C++ documentation

GPU

Hardware accelerators such as GPUs and TPUs can be used to speed up ANN search for queries that arrive in batches. GPU support in LoRANN is experimental and available only as a Python module. For index building, the GPU is currently used only partially.

Usage is similar to the CPU version, just with a different import:

python from lorann_gpu import LorannIndex

The GPU submodule is implemented with and depends on PyTorch, but a native CUDA implementation would provide better performance and will be available in the future. All index structures are by default saved as torch.float32 to ensure numerical stability. However, for most embedding datasets, better performance can be obtained by passing dtype=torch.float16 to the index constructor.

For a complete example, see examples/gpu_example.py

Citation

If you use the library in an academic context, please consider citing the following paper:

Jääsaari, E., Hyvönen, V., Roos, T. LoRANN: Low-Rank Matrix Factorization for Approximate Nearest Neighbor Search. Advances in Neural Information Processing Systems 37 (2024): 102121-102153.

~~~~ @article{Jaasaari2024lorann, title={{LoRANN}: Low-Rank Matrix Factorization for Approximate Nearest Neighbor Search}, author={J{\"a}{\"a}saari, Elias and Hyv{\"o}nen, Ville and Roos, Teemu}, journal={Advances in Neural Information Processing Systems}, volume={37}, pages={102121--102153}, year={2024} } ~~~~

License

LoRANN is available under the MIT License (see LICENSE). Note that third-party libraries in the lorann folder may be distributed under other open source licenses (see licenses).

Owner

  • Name: Elias Jääsaari
  • Login: ejaasaari
  • Kind: user
  • Company: Carnegie Mellon University

GitHub Events

Total
  • Create event: 9
  • Release event: 3
  • Issues event: 2
  • Watch event: 44
  • Delete event: 1
  • Issue comment event: 6
  • Push event: 61
  • Fork event: 3
Last Year
  • Create event: 9
  • Release event: 3
  • Issues event: 2
  • Watch event: 44
  • Delete event: 1
  • Issue comment event: 6
  • Push event: 61
  • Fork event: 3

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 1
  • Total pull requests: 0
  • Average time to close issues: about 22 hours
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 0
  • Average comments per issue: 6.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: about 22 hours
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 6.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • qfshen23 (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 33 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 4
  • Total maintainers: 1
pypi.org: lorann

Approximate Nearest Neighbor search library with extremely fast queries, tiny memory usage, and rapid indexing.

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 33 Last month
Rankings
Dependent packages count: 9.8%
Stargazers count: 12.6%
Forks count: 24.7%
Average: 25.5%
Dependent repos count: 55.0%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/build.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
.github/workflows/docs-gh-pages.yml actions
  • JamesIves/github-pages-deploy-action v4 composite
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
Dockerfile docker
  • python 3.12 build
pyproject.toml pypi
python/requirements.txt pypi
  • numpy >=1.21.0
python/setup.py pypi
  • numpy *