FAISS implementation of multiclass and multilabel K-Nearest Neighbors Classifiers.
Project description
faissknn
faissknn contains implementations for both multiclass and multilabel K-Nearest Neighbors Classifier implementations. The classifiers follow the scikit-learn: fit, predict, and predict_proba methods.
Install
pip install faissknn
Pulls in faiss-cpu along with numpy and torch. Works everywhere — no GPU, CUDA driver, or system toolkit required.
GPU acceleration (CUDA 12.x)
For GPU-enabled FAISS on CUDA 12.x hosts (NVIDIA driver R525+), install the [cuda] extra, which adds faiss-cuda-cu128 (Taylor Geospatial's GPU wheels for CUDA 12.8). No system CUDA toolkit needed — the runtime libraries come from nvidia-cuda-runtime-cu12 / nvidia-cublas-cu12 on PyPI.
pip install "faissknn[cuda]"
pip uninstall -y faiss-cpu
pip install --force-reinstall faiss-cuda-cu128
These wheels also run on CUDA 13 hosts (driver R580+) via NVIDIA's forward-compat guarantee — you just don't get the sm_100 (Blackwell) arch.
Blackwell users (B100 / B200)
If you need sm_100 baked in, use the CUDA 13 wheel via the [cu13] extra, which adds faiss-cuda:
pip install "faissknn[cu13]"
pip uninstall -y faiss-cpu
pip install --force-reinstall faiss-cuda
Why the uninstall+reinstall? faiss-cpu, faiss-cuda-cu128, and faiss-cuda all ship the same faiss/ module, so they can't cleanly coexist. The extra adds the GPU package to the resolution, but removing faiss-cpu and force-reinstalling is what actually gives you a clean GPU install. uv/pip can't auto-detect the host CUDA driver, so this is a one-time manual choice.
Usage
Multiclass:
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from faissknn import FaissKNNClassifier
x, y = make_classification()
x_train, x_test, y_train, y_test = train_test_split(x, y)
model = FaissKNNClassifier(
n_neighbors=5,
n_classes=None,
device="cpu"
)
model.fit(x_train, y_train)
y_pred = model.predict(x_test) # (N,)
y_proba = model.predict_proba(x_test) # (N, C)
Multilabel:
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from faissknn import FaissKNNMultilabelClassifier
x, y = make_multilabel_classification()
x_train, x_test, y_train, y_test = train_test_split(x, y)
model = FaissKNNMultilabelClassifier(
n_neighbors=5,
device="cpu"
)
model.fit(x_train, y_train)
y_pred = model.predict(x_test) # (N, C)
y_proba = model.predict_proba(x_test) # (N, C)
GPU/CUDA: faissknn also supports running on the GPU to speed up computation. Simply change the device to cuda or a specific cuda device cuda:0
model = FaissKNNClassifier(
n_neighbors=5,
device="cuda"
)
model = FaissKNNClassifier(
n_neighbors=5,
device="cuda:0"
)
Cite
If you use faissknn in your research, please considering citing!
@software{isaac_corley_2026_18370748,
author = {Isaac Corley},
title = {isaaccorley/faissknn: Zenodo Cite},
month = jan,
year = 2026,
publisher = {Zenodo},
version = {v0.0.3},
doi = {10.5281/zenodo.18370748},
url = {https://doi.org/10.5281/zenodo.18370748},
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file faissknn-0.2.0.tar.gz.
File metadata
- Download URL: faissknn-0.2.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcf08224e3021c3b1bc4eb97a7d176e352e572a6a8a72ddea208444261e25a56
|
|
| MD5 |
55e4e5619b316215653ad270f773ec17
|
|
| BLAKE2b-256 |
b7c8e658ba1e99a975f6b5ff3255cb6de66d133dabb0f79b1f0f1072d9625a00
|
File details
Details for the file faissknn-0.2.0-py3-none-any.whl.
File metadata
- Download URL: faissknn-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0028e4c79303dd92e23b06961b5b2212a08e76f861e958a6d83cfc102b00663
|
|
| MD5 |
97fe57984fd718b9f210e2c701c62ff1
|
|
| BLAKE2b-256 |
863f2ce818b2c255199dbfc799b8b7744aed3298d3be9bee0fb83c51132b5bd0
|