A pure-Python approximate nearest neighbor search library built on Nearest Neighbor Descent, with broad distance metric support.
microsoft/SPTAG
A C++ library for large-scale approximate nearest neighbor vector search, with index build, search, and distributed serving toolkits.
- Stars
- 5,021
- Forks
- 625
- Open issues
- 143
- Last commit
- 2 days ago
What is it?
SPTAG (Space Partition Tree And Graph) is a library for approximate nearest neighbor search over vectors, the kind of lookup used in semantic search and recommendation systems. Given a query vector, it returns the stored vectors with the smallest L2 or cosine distance, trading a small amount of accuracy for much faster lookups than exhaustive comparison.
It offers two index variants: SPTAG-KDT, which uses kd-trees and has lower index build cost, and SPTAG-BKT, which uses balanced k-means trees and is intended for higher search accuracy on very high-dimensional data. Both combine a space partition tree with a relative neighborhood graph, and the search alternates between the two to find results.
The library supports online vector insertion and deletion without full rebuilds, and can distribute search across multiple machines. It includes a Python wrapper and builds on Linux, Windows, and Docker.
Key features
- 01Supports L2 and cosine distance for vector similarity.
- 02Offers kd-tree (SPTAG-KDT) and balanced k-means tree (SPTAG-BKT) index variants.
- 03Allows online vector insertion and deletion without rebuilding the index.
- 04Distributes search across multiple machines for serving.
- 05Includes a Python wrapper and a tutorial for building an online vector search service.
Use cases
- Building a large-scale semantic search backend over embedding vectors.
- Serving nearest-neighbor lookups for recommendation or image similarity.
- Indexing datasets that change frequently and need online updates.
- Running vector search across several machines when one index is too large.
Quick start
- 1
Clone the repository with its submodules
git clone --recurse-submodules https://github.com/microsoft/SPTAG - 2
Build with CMake from the build directory (requires swig, cmake and boost)
mkdir build && cd build && cmake -DSPDK=OFF -DROCKSDB=OFF .. && make - 3
Run the SPTAGTest binary in the Release folder to verify the build
Things to know
- Building from source requires swig, cmake and boost, and the Linux and Windows steps differ.
- Fast clone of the repository relies on Git LFS and submodules.
In collections
Topics
FAQ
- What is SPTAG?
- A C++ library for large-scale approximate nearest neighbor vector search, with index build, search, and distributed serving toolkits. SPTAG (Space Partition Tree And Graph) is a library for approximate nearest neighbor search over vectors, the kind of lookup used in semantic search and recommendation systems. Given a query vector, it returns the stored vectors with the smallest L2 or cosine distance, trading a small amount of accuracy for much faster lookups than exhaustive comparison.
- Is SPTAG free to use? What license does it have?
- SPTAG is open source under the MIT license. Check the license terms before using it in commercial products.
- Is SPTAG still maintained?
- Actively maintained. The last commit to SPTAG was on Nov 6, 2026.
- What can I use SPTAG for?
- Building a large-scale semantic search backend over embedding vectors. Serving nearest-neighbor lookups for recommendation or image similarity. Indexing datasets that change frequently and need online updates. Running vector search across several machines when one index is too large.
- How do I install SPTAG?
- Clone the repository with its submodules: git clone --recurse-submodules https://github.com/microsoft/SPTAG Build with CMake from the build directory (requires swig, cmake and boost): mkdir build && cd build && cmake -DSPDK=OFF -DROCKSDB=OFF .. && make Run the SPTAGTest binary in the Release folder to verify the build
- Where can I get SPTAG?
- The source code and installation instructions are on GitHub: https://github.com/microsoft/SPTAG
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Header-only C++ library with Python bindings for fast approximate nearest neighbor search using the HNSW graph algorithm.
A C++ library and command-line tool for fast approximate nearest neighbor search over high-dimensional vectors, using graph and tree indexes.
A single-file C++ library for approximate nearest-neighbor vector search and clustering, with bindings for Python, JavaScript, Rust, Java, Go, Swift and more.
A Postgres extension in Rust that adds a DiskANN-based index and label filtering on top of pgvector for faster, cheaper vector search.
Open-source vector similarity search extension for Postgres, storing and querying embeddings alongside your relational data.