Skip to main content

Scalable approximate nearest neighbor search for variable-length binary bit-vectors using NPHD metric.

Project description

iscc-usearch

Tests Python License Ask DeepWiki

A vector search library extending USearch with sharded indexes, variable-length binary vectors, and 128-bit keys.

Looking for a ready-to-use ISCC search engine with CLI and REST API? See iscc-search, which uses iscc-usearch internally.

iscc-usearch is a Python library that extends USearch - a high-performance HNSW library adopted by ClickHouse, LangChain, and others - with three independent capabilities:

Sharded HNSW indexes (ShardedIndex) keep a single active shard in RAM for writes while completed shards are memory-mapped for reads. Works with any vector type and metric USearch supports, including user-defined distance functions. Insert throughput stays consistent and memory stays bounded as the index grows to billions of vectors.

Normalized Prefix Hamming Distance (NphdIndex, ShardedNphdIndex) compares binary vectors of mixed bit-lengths - a 64-bit query finds nearest neighbors among 256-bit vectors with comparable distances. Purpose-built for ISCC (ISO 24138) content fingerprints, also applicable to Matryoshka embeddings, perceptual hashes, and locality-sensitive hashing.

128-bit UUID keys (ShardedIndex128, ShardedNphdIndex128) extend the key space from 64-bit integers to 128-bit bytes(16) keys. Useful when your identifiers are UUIDs, 128-bit hashes, or structured multi-part keys that don't fit in a uint64.

Key features:

  • Bounded memory - only one shard in RAM at a time, the rest memory-mapped
  • Billions of vectors - sharded indexes scale well beyond single-machine RAM
  • Full CRUD - add, remove, upsert, compact, and dirty-counter-driven flush across index variants
  • Durable saves - buffer-then-write persistence with atomic rename and stable-storage flushes
  • Diagnostics - ShardedIndex.stats() for structured monitoring snapshots
  • Mixed bit-lengths - 64-bit and 256-bit vectors coexist in the same index
  • 128-bit keys - bytes(16) UUID keys when 64-bit integers are not enough
  • Any distance metric - user-defined metrics via USearch's plugin system
  • Fast - inherits USearch's HNSW engine, benchmarked at 10x the throughput of FAISS

ShardedIndex and NPHD architecture overview

NphdIndex architecture overview

Which index class?

Class Var-len Keys Shards Use when...
NphdIndex uint64 Binary variable-length, fits in RAM
ShardedIndex uint64 Exceeds RAM, any metric
ShardedIndex128 128-bit Same, with 128-bit keys
ShardedNphdIndex uint64 Binary variable-length, exceeds RAM
ShardedNphdIndex128 128-bit Binary variable-length, 128-bit keys

Installation

pip install iscc-usearch

Quick start

Variable-length binary (NphdIndex):

import numpy as np
from iscc_usearch import NphdIndex

index = NphdIndex(max_dim=256)

# Mix 64-bit and 128-bit vectors in the same index
index.add(1, np.array([255, 128, 64, 32, 16, 8, 4, 2], dtype=np.uint8))
index.add(2, np.array([255, 128, 64, 32, 16, 8, 4, 2, 1, 0, 255, 128, 64, 32, 16, 8], dtype=np.uint8))

# Search with a 64-bit query - NPHD compares the common prefix
query = np.array([255, 128, 64, 32, 16, 8, 4, 2], dtype=np.uint8)
matches = index.search(query, count=2)

print(matches.keys)  # Nearest neighbor keys
print(matches.distances)  # NPHD distances in [0.0, 1.0]

Sharded HNSW (ShardedIndex):

import numpy as np
from iscc_usearch import ShardedIndex

# Shards are stored in a directory on disk
index = ShardedIndex(ndim=64, path="my_index", dtype="f32")

# Add vectors - shards rotate automatically when size limit is reached
keys = list(range(1000))
vectors = np.random.rand(1000, 64).astype(np.float32)
index.add(keys, vectors)

# Search across all shards
matches = index.search(vectors[0], count=10)

print(matches.keys)  # Nearest neighbor keys
print(matches.distances)  # Cosine distances

Documentation

Full documentation: https://usearch.iscc.codes/

License

Apache-2.0

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

iscc_usearch-0.8.0.tar.gz (43.8 kB view details)

Uploaded Source

Built Distribution

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

iscc_usearch-0.8.0-py3-none-any.whl (48.0 kB view details)

Uploaded Python 3

File details

Details for the file iscc_usearch-0.8.0.tar.gz.

File metadata

  • Download URL: iscc_usearch-0.8.0.tar.gz
  • Upload date:
  • Size: 43.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","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 iscc_usearch-0.8.0.tar.gz
Algorithm Hash digest
SHA256 e5287c855af6f8d5221d8b466364c8b06ea0128e1afef29663b9f2e29bfa5b4a
MD5 9138564bb8768e0fdb5278a5e2509d40
BLAKE2b-256 17ef79d48ef85008faa4b00e165e029320fe3a3807ecc64e3fd927ea96606eaf

See more details on using hashes here.

File details

Details for the file iscc_usearch-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: iscc_usearch-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 48.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","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 iscc_usearch-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc3f39812de33f955e80112388e7bfca6d3280290b6cba5e25f457288ee6a33b
MD5 eea60b06978911537b52f733d469d17c
BLAKE2b-256 b6ecce5ef069ae379e9e925a14cfecf92b4a4bd3a40b464cd9113e052543ed0a

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