Skip to main content

knn-inspect for Python

Reads OpenSearch k-NN native segment files (.faiss, .faissc) offline: verifies them, reports graph statistics, and measures recall against brute force. These are the five commands of the knn-inspect CLI, as Python functions. Neither Faiss nor Java is needed.

pip install knn-inspect
import numpy as np
import knn_inspect

report = knn_inspect.verify("_2_165_vec.faiss", space="cosine")
print(report["status"])  # clean, warnings, or failed
print(report.text)       # as `knn-inspect verify` prints it

queries = np.random.default_rng(1).random((100, 128), dtype=np.float32)
print(knn_inspect.recall("_2_165_vec.faiss", queries=queries, k=10)["recall"])

Functions

Function The command
info(path) A native file's layout, dimensions, HNSW parameters or IVF lists, envelope
verify(path, *, space=None, max_findings=5) Every structural check
stats(path) Per-level graph statistics, or an IVF index's list sizes
recall(path, *, queries=None, sample=None, ...) Search results, the tool's own or given, scored against exact brute force
scan(path, *, space=None, max_findings=5) verify and a summary for every native file under a directory

Options are keyword-only, named as the command's flags (--max-findings as max_findings), with the command's defaults; help(knn_inspect.recall) lists recall's.

Each function returns a Report: a dict equal to what json.loads gives of the command's --json output, described field by field in docs/json.md, with the command's text as report.text.

recall takes its inputs as files, as the command does, or as data:

  • queries: a buffer (a numpy array, array.array, bytes) of float32 vectors, or for a binary file of packed bits, or a sequence of float vectors. A 2-D array's row width is held to the file's dimension; a 1-D buffer is read as a queries file's bytes are.
  • results: a sequence of label sequences, one per query, in query order.
  • ids: a sequence of ints naming node i as ids[i], when the result lists use ids other than the file's labels.

Errors and warnings

A report that cannot be built raises knn_inspect.Error, its message the command's error line with options named as keywords. Options refused before the file is opened, contradictory or out of range, raise knn_inspect.OptionsError, which is also a ValueError. What recall warns of (for a graph without its vectors, what scan's check of the field's files finds that does not stop the search) is issued as a knn_inspect.RecallWarning before the report is returned or the error raised.

The functions release the GIL while they run.

Building from source

With a Rust toolchain (the repository's rust-toolchain.toml) and a virtual environment active, from python/:

pip install maturin pytest numpy
maturin develop --release
pytest

The tests compare every report with the CLI's on the repository's fixtures, building the CLI with cargo.

Metadata

Release files for knn-inspect 0.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for knn-inspect 0.17.0
File Size Uploaded Provenance
knn_inspect-0.17.0.tar.gz 338.0 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for knn-inspect 0.17.0
File
knn_inspect-0.17.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
knn_inspect-0.17.0-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details
knn_inspect-0.17.0-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details
knn_inspect-0.17.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details

Total release size: 3.3 MB

Release files / knn_inspect-0.17.0.tar.gz

Download URL knn_inspect-0.17.0.tar.gz
Size 338.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9e7bbe0d352f93f26592bdeb6474fffc28ef18ccffe1e9fe821e01b981134d6c
BLAKE2b-256 checksum
How to use checksums
84c528ef6578f86cda391a8534b64d5cc2b3631db7c85ced4b4d40fd7115a98a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / knn_inspect-0.17.0-cp311-abi3-win_amd64.whl

Download URL knn_inspect-0.17.0-cp311-abi3-win_amd64.whl
Size 628.1 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
ff2058d6626dcf31d326d4f5e9fb1ffff3f97c6a35fa46b35348f0845dc084d2
BLAKE2b-256 checksum
How to use checksums
af554ff051cb045c0a1c1e182158a4dad2accbcd9ec637263bd59721502e03c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / knn_inspect-0.17.0-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL knn_inspect-0.17.0-cp311-abi3-manylinux_2_28_x86_64.whl
Size 817.4 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
f472f1f88ae87f01fd85717d729d05a868ada0df95cdaf14463292892cda8d8b
BLAKE2b-256 checksum
How to use checksums
b48d44096742c8156d84eabcc3a027d83ebac554a4431ace250b357561b662c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / knn_inspect-0.17.0-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL knn_inspect-0.17.0-cp311-abi3-manylinux_2_28_aarch64.whl
Size 798.8 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
d1e5b87be0af44be778359b4dff3ddccd90290433374af18a92857438890f752
BLAKE2b-256 checksum
How to use checksums
0fcc07e44cb628efec8bb0518dfeb38f3312083259b56618cd406fa339728fb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / knn_inspect-0.17.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL knn_inspect-0.17.0-cp311-abi3-macosx_11_0_arm64.whl
Size 733.3 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1d418a36eaf30e18d8b076fe7a29c75337605793709ddd6c1f1c37129705f1db
BLAKE2b-256 checksum
How to use checksums
7e7fb82d585bb9c3b106e1798d779e611e31536fad7fcce1902cd0f559f7b4e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Security for knn-inspect 0.17.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for knn_inspect-0.17.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.17.0 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page