Skip to main content

FAISS implementation of multiclass and multilabel K-Nearest Neighbors Classifiers.

Project description

faissknn

DOI

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-cuda-cu128 (Taylor Geospatial's GPU-enabled FAISS wheels for CUDA 12.8) along with numpy and torch. No system CUDA toolkit required — the runtime libraries come from nvidia-cuda-runtime-cu12 / nvidia-cublas-cu12 on PyPI.

The default wheel works on:

  • CPU-only hostsimport faiss succeeds, faiss.get_num_gpus() returns 0, all CPU index types work
  • CUDA 12.x hosts (NVIDIA driver R525+) — full GPU acceleration
  • CUDA 13 hosts (NVIDIA 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:

pip install "faissknn[cu13]"
pip uninstall -y faiss-cuda-cu128
pip install --force-reinstall faiss-cuda

The [cu13] extra adds faiss-cuda to the resolution, but because both packages ship the same faiss/ module the manual uninstall+reinstall is what actually gives you a clean 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

faissknn-0.1.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

faissknn-0.1.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file faissknn-0.1.1.tar.gz.

File metadata

  • Download URL: faissknn-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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

Hashes for faissknn-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ec21ece0fa0eb407a156acce1f43e6fbcae6118950887062234d8e3b5c1c6b26
MD5 5e43ba9158fd486a2d1094804a6f9865
BLAKE2b-256 c7dd215c7534599ffa9a17e1b1127afea2cc4ed4c16a2da24031d647b0ef0f1a

See more details on using hashes here.

File details

Details for the file faissknn-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: faissknn-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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

Hashes for faissknn-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a32d00fc59d01b070257e06130744e8a9e26cb1b4a5af478c35f43c3aa55ca5
MD5 7efc6d2518b3b7d92d599766362e4f0b
BLAKE2b-256 5ca1aa5cdd7c123d7ba5bc5b12a407e8216d0aa18dfb3f052bc2904b7713ba6c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page