Cloud.Unum.USearch
2.8.10
See the version list below for details.
dotnet add package Cloud.Unum.USearch --version 2.8.10
NuGet\Install-Package Cloud.Unum.USearch -Version 2.8.10
<PackageReference Include="Cloud.Unum.USearch" Version="2.8.10" />
paket add Cloud.Unum.USearch --version 2.8.10
#r "nuget: Cloud.Unum.USearch, 2.8.10"
// Install Cloud.Unum.USearch as a Cake Addin #addin nuget:?package=Cloud.Unum.USearch&version=2.8.10 // Install Cloud.Unum.USearch as a Cake Tool #tool nuget:?package=Cloud.Unum.USearch&version=2.8.10
<h1 align="center">USearch</h1> <h3 align="center"> Smaller & <a href="https://www.unum.cloud/blog/2023-11-07-scaling-vector-search-with-intel">Faster</a> Single-File<br/> Similarity Search Engine for <a href="https://github.com/ashvardanian/simsimd">Vectors</a> & π <a href="https://github.com/ashvardanian/stringzilla">Texts</a> </h3> <br/>
<p align="center"> <a href="https://discord.gg/A6wxt6dS9j"><img height="25" src="https://github.com/unum-cloud/.github/raw/main/assets/discord.svg" alt="Discord"></a> <a href="https://www.linkedin.com/company/unum-cloud/"><img height="25" src="https://github.com/unum-cloud/.github/raw/main/assets/linkedin.svg" alt="LinkedIn"></a> <a href="https://twitter.com/unum_cloud"><img height="25" src="https://github.com/unum-cloud/.github/raw/main/assets/twitter.svg" alt="Twitter"></a> <a href="https://unum.cloud/post"><img height="25" src="https://github.com/unum-cloud/.github/raw/main/assets/blog.svg" alt="Blog"></a> <a href="https://github.com/unum-cloud/usearch"><img height="25" src="https://github.com/unum-cloud/.github/raw/main/assets/github.svg" alt="GitHub"></a> </p>
<p align="center"> Spatial β’ Binary β’ Probabilistic β’ User-Defined Metrics <br/> <a href="https://unum-cloud.github.io/usearch/cpp">C++ 11</a> β’ <a href="https://unum-cloud.github.io/usearch/python">Python 3</a> β’ <a href="https://unum-cloud.github.io/usearch/javascript">JavaScript</a> β’ <a href="https://unum-cloud.github.io/usearch/java">Java</a> β’ <a href="https://unum-cloud.github.io/usearch/rust">Rust</a> β’ <a href="https://unum-cloud.github.io/usearch/c">C 99</a> β’ <a href="https://unum-cloud.github.io/usearch/objective-c">Objective-C</a> β’ <a href="https://unum-cloud.github.io/usearch/swift">Swift</a> β’ <a href="https://unum-cloud.github.io/usearch/csharp">C#</a> β’ <a href="https://unum-cloud.github.io/usearch/golang">GoLang</a> β’ <a href="https://unum-cloud.github.io/usearch/wolfram">Wolfram</a> <br/> Linux β’ MacOS β’ Windows β’ iOS β’ WebAssembly </p>
<div align="center"> <a href="https://pypi.org/project/usearch/"> <img alt="PyPI" src="https://img.shields.io/pypi/dm/usearch?label=PyPi%20pulls"> </a> <a href="https://www.npmjs.com/package/usearch"> <img alt="NPM" src="https://img.shields.io/npm/dy/usearch?label=NPM%20pulls"> </a> <a href="https://crates.io/crates/usearch"> <img alt="Crate" src="https://img.shields.io/crates/d/usearch?label=Crate%20pulls"> </a> <a href="https://www.nuget.org/packages/Cloud.Unum.USearch"> <img alt="NuGet" src="https://img.shields.io/nuget/dt/Cloud.Unum.USearch?label=NuGet%20pulls"> </a> <a href="https://central.sonatype.com/artifact/cloud.unum/usearch/overview"> <img alt="Maven" src="https://img.shields.io/nexus/r/cloud.unum/usearch?server=https%3A%2F%2Fs01.oss.sonatype.org%2F&label=Maven%20version"> </a> <a href="https://hub.docker.com/r/unum/usearch"> <img alt="Docker" src="https://img.shields.io/docker/pulls/unum/usearch?label=Docker%20pulls"> </a> <img alt="GitHub code size in bytes" src="https://img.shields.io/github/languages/code-size/unum-cloud/usearch?label=Repo%20size"> </div>
- β 20x faster than FAISS implementation of HNSW algorithm.
- β Simple and extensible single C++11 header implementation.
- β Compatible with a dozen programming languages out of the box.
- β Trusted by some of the most loved Datalakes and Databases, like ClickHouse.
- β SIMD-optimized and user-defined metrics with JIT compilation.
- β
Hardware-agnostic
f16
&i8
- half-precision & quarter-precision support. - β View large indexes from disk without loading into RAM.
- β Heterogeneous lookups, renaming/relabeling, and on-the-fly deletions.
- β Variable dimensionality vectors for unique applications, including search over compressed data.
- β Binary Tanimoto and Sorensen coefficients for Genomics and Chemistry applications.
- β
Space-efficient point-clouds with
uint40_t
, accommodating 4B+ size. - β Compatible with OpenMP and custom "executors" for fine-grained control over CPU utilization.
- β Near-real-time clustering and sub-clustering for Tens or Millions of clusters.
- β Semantic Search and Joins.
Technical Insights and related articles:
- Uses Horner's method for polynomial approximations, beating GCC 12 by 119x.
- Uses Arm SVE and x86 AVX-512's masked loads to eliminate tail
for
-loops. - Uses AVX-512 FP16 for half-precision operations, that few compilers vectorize.
- Substitutes LibC's
sqrt
calls with bithacks using Jan Kadlec's constant. - For every language implements a custom separate binding.
- For Python avoids slow PyBind11, and even
PyArg_ParseTuple
for speed. - For JavaScript uses typed arrays and NAPI for zero-copy calls.
Comparison with FAISS
FAISS is a widely recognized standard for high-performance vector search engines. USearch and FAISS both employ the same HNSW algorithm, but they differ significantly in their design principles. USearch is compact and broadly compatible without sacrificing performance, primarily focusing on user-defined metrics and fewer dependencies.
FAISS | USearch | Improvement | |
---|---|---|---|
Indexing time β° | |||
100 Million 96d f32 , f16 , i8 vectors |
2.6 h, 2.6 h, 2.6 h | 0.3 h, 0.2 h, 0.2 h | 9.6x, 10.4x, 10.7x |
100 Million 1536d f32 , f16 , i8 vectors |
5.0 h, 4.1 h, 3.8 h | 2.1 h, 1.1 h, 0.8 h | 2.3x 3.6x, 4.4x |
Codebase length ΒΉ | 84 K SLOC in faiss/ |
3 K SLOC in usearch/ |
maintainable |
Supported metrics Β² | 9 fixed metrics | any user-defined metrics | extendible |
Supported languages Β³ | C++, Python | 10 languages | portable |
Supported ID types β΄ | 32-bit, 64-bit | 32-bit, 40-bit, 64-bit | efficient |
Required dependencies β΅ | BLAS, OpenMP | - | light-weight |
Bindings βΆ | SWIG | Native | low-latency |
β° Tested on Intel Sapphire Rapids, with the simplest inner-product distance, equivalent recall, and memory consumption while also providing far superior search speed. ΒΉ A shorter codebase makes the project easier to maintain and audit. Β² User-defined metrics allow you to customize your search for various applications, from GIS to creating custom metrics for composite embeddings from multiple AI models or hybrid full-text and semantic search. Β³ With USearch, you can reuse the same preconstructed index in various programming languages. β΄ The 40-bit integer allows you to store 4B+ vectors without allocating 8 bytes for every neighbor reference in the proximity graph. β΅ Lack of obligatory dependencies makes USearch much more portable. βΆ Native bindings introduce lower call latencies than more straightforward approaches.
Base functionality is identical to FAISS, and the interface must be familiar if you have ever investigated Approximate Nearest Neighbors search:
$ pip install numpy usearch
import numpy as np
from usearch.index import Index
index = Index(ndim=3)
vector = np.array([0.2, 0.6, 0.4])
index.add(42, vector)
matches = index.search(vector, 10)
assert matches[0].key == 42
assert matches[0].distance <= 0.001
assert np.allclose(index[42], vector)
More settings are always available, and the API is designed to be as flexible as possible.
index = Index(
ndim=3, # Define the number of dimensions in input vectors
metric='cos', # Choose 'l2sq', 'haversine' or other metric, default = 'ip'
dtype='f32', # Quantize to 'f16' or 'i8' if needed, default = 'f32'
connectivity=16, # Optional: Limit number of neighbors per graph node
expansion_add=128, # Optional: Control the recall of indexing
expansion_search=64, # Optional: Control the quality of the search
)
Serialization & Serving Index
from Disk
USearch supports multiple forms of serialization:
- Into a file defined with a path.
- Into a stream defined with a callback, serializing or reconstructing incrementally.
- Into a buffer of fixed length or a memory-mapped file that supports random access.
The latter allows you to serve indexes from external memory, enabling you to optimize your server choices for indexing speed and serving costs. This can result in 20x cost reduction on AWS and other public clouds.
index.save("index.usearch")
loaded_copy = index.load("index.usearch")
view = Index.restore("index.usearch", view=True)
other_view = Index(ndim=..., metric=CompiledMetric(...))
other_view.view("index.usearch")
Exact vs. Approximate Search
Approximate search methods, such as HNSW, are predominantly used when an exact brute-force search becomes too resource-intensive.
This typically occurs when you have millions of entries in a collection.
For smaller collections, we offer a more direct approach with the search
method.
from usearch.index import search, MetricKind, Matches, BatchMatches
import numpy as np
# Generate 10'000 random vectors with 1024 dimensions
vectors = np.random.rand(10_000, 1024).astype(np.float32)
vector = np.random.rand(1024).astype(np.float32)
one_in_many: Matches = search(vectors, vector, 50, MetricKind.L2sq, exact=True)
many_in_many: BatchMatches = search(vectors, vectors, 50, MetricKind.L2sq, exact=True)
If you pass the exact=True
argument, the system bypasses indexing altogether and performs a brute-force search through the entire dataset using SIMD-optimized similarity metrics from SimSIMD.
When compared to FAISS's IndexFlatL2
in Google Colab, USearch may offer up to a 20x performance improvement:
faiss.IndexFlatL2
: 55.3 ms.usearch.index.search
: 2.54 ms.
Indexes
for Multi-Index Lookups
For larger workloads targeting billions or even trillions of vectors, parallel multi-index lookups become invaluable. Instead of constructing one extensive index, you can build multiple smaller ones and view them together.
from usearch.index import Indexes
multi_index = Indexes(
indexes: Iterable[usearch.index.Index] = [...],
paths: Iterable[os.PathLike] = [...],
view: bool = False,
threads: int = 0,
)
multi_index.search(...)
Clustering
Once the index is constructed, it can cluster entries much faster than using a separate clustering algorithm implementation.
Essentially, the Index
itself can be seen as a clustering, allowing iterative deepening.
clustering = index.cluster(
min_count=10, # Optional
max_count=15, # Optional
threads=..., # Optional
)
# Get the clusters and their sizes
centroid_keys, sizes = clustering.centroids_popularity
# Use Matplotlib to draw a histogram
clustering.plot_centroids_popularity()
# Export a NetworkX graph of the clusters
g = clustering.network
# Get members of a specific cluster
first_members = clustering.members_of(centroid_keys[0])
# Deepen into that cluster, splitting it into more parts, all the same arguments supported
sub_clustering = clustering.subcluster(min_count=..., max_count=...)
The resulting clustering isn't identical to K-Means or other conventional approaches but serves the same purpose. Alternatively, using Scikit-Learn on a 1 Million point dataset, one may expect queries to take anywhere from minutes to hours, depending on the number of clusters you want to highlight. For 50'000 clusters, the performance difference between USearch and conventional clustering methods may easily reach 100x.
Joins, One-to-One, One-to-Many, and Many-to-Many Mappings
One of the big questions these days is how AI will change the world of databases and data management.
Most databases are still struggling to implement high-quality fuzzy search, and the only kind of joins they know are deterministic.
A join
differs from searching for every entry, requiring a one-to-one mapping banning collisions among separate search results.
Exact Search | Fuzzy Search | Semantic Search ? |
---|---|---|
Exact Join | Fuzzy Join ? | Semantic Join ?? |
Using USearch, one can implement sub-quadratic complexity approximate, fuzzy, and semantic joins. This can be useful in any fuzzy-matching tasks common to Database Management Software.
men = Index(...)
women = Index(...)
pairs: dict = men.join(women, max_proposals=0, exact=False)
Read more in the post: Combinatorial Stable Marriages for Semantic Search π
User-Defined Functions
While most vector search packages concentrate on just a few metrics - "Inner Product distance" and "Euclidean distance," USearch extends this list to include any user-defined metrics. This flexibility allows you to customize your search for various applications, from computing geospatial coordinates with the rare Haversine distance to creating custom metrics for composite embeddings from multiple AI models.
Unlike older approaches indexing high-dimensional spaces, like KD-Trees and Locality Sensitive Hashing, HNSW doesn't require vectors to be identical in length. They only have to be comparable. So you can apply it in obscure applications, like searching for similar sets or fuzzy text matching, using GZip as a distance function.
Read more about JIT and UDF in USearch Python SDK.
Memory Efficiency, Downcasting, and Quantization
Training a quantization model and dimension-reduction is a common approach to accelerate vector search.
Those, however, are only sometimes reliable, can significantly affect the statistical properties of your data, and require regular adjustments if your distribution shifts.
Instead, we have focused on high-precision arithmetic over low-precision downcasted vectors.
The same index, and add
and search
operations will automatically down-cast or up-cast between f64_t
, f32_t
, f16_t
, i8_t
, and single-bit representations.
You can use the following command to check, if hardware acceleration is enabled:
$ python -c 'from usearch.index import Index; print(Index(ndim=768, metric="cos", dtype="f16").hardware_acceleration)'
> avx512+f16
$ python -c 'from usearch.index import Index; print(Index(ndim=166, metric="tanimoto").hardware_acceleration)'
> avx512+popcnt
Using smaller numeric types will save you RAM needed to store the vectors, but you can also compress the neighbors lists forming our proximity graphs.
By default, 32-bit uint32_t
is used to enumerate those, which is not enough if you need to address over 4 Billion entries.
For such cases we provide a custom uint40_t
type, that will still be 37.5% more space-efficient than the commonly used 8-byte integers, and will scale up to 1 Trillion entries.
Functionality
By now, the core functionality is supported across all bindings. Broader functionality is ported per request. In some cases, like Batch operations, feature parity is meaningless, as the host language has full multi-threading capabilities and the USearch index structure is concurrent by design, so the users can implement batching/scheduling/load-balancing in the most optimal way for their applications.
C++ 11 | Python 3 | C 99 | Java | JavaScript | Rust | GoLang | Swift | |
---|---|---|---|---|---|---|---|---|
Add, search, remove | β | β | β | β | β | β | β | β |
Save, load, view | β | β | β | β | β | β | β | β |
User-defined metrics | β | β | β | β | β | β | β | β |
Batch operations | β | β | β | β | β | β | β | β |
Joins | β | β | β | β | β | β | β | β |
Variable-length vectors | β | β | β | β | β | β | β | β |
4B+ capacities | β | β | β | β | β | β | β | β |
Application Examples
USearch + AI = Multi-Modal Semantic Search
AI has a growing number of applications, but one of the coolest classic ideas is to use it for Semantic Search. One can take an encoder model, like the multi-modal UForm, and a web-programming framework, like UCall, and build a text-to-image search platform in just 20 lines of Python.
import ucall
import uform
import usearch
import numpy as np
import PIL as pil
server = ucall.Server()
model = uform.get_model('unum-cloud/uform-vl-multilingual')
index = usearch.index.Index(ndim=256)
@server
def add(key: int, photo: pil.Image.Image):
image = model.preprocess_image(photo)
vector = model.encode_image(image).detach().numpy()
index.add(key, vector.flatten(), copy=True)
@server
def search(query: str) -> np.ndarray:
tokens = model.preprocess_text(query)
vector = model.encode_text(tokens).detach().numpy()
matches = index.search(vector.flatten(), 3)
return matches.keys
server.run()
A more complete demo with Streamlit is available on GitHub. We have pre-processed some commonly used datasets, cleaned the images, produced the vectors, and pre-built the index.
Dataset | Modalities | Images | Download |
---|---|---|---|
Unsplash | Images & Descriptions | 25 K | HuggingFace / Unum |
Conceptual Captions | Images & Descriptions | 3 M | HuggingFace / Unum |
Arxiv | Titles & Abstracts | 2 M | HuggingFace / Unum |
USearch + RDKit = Molecular Search
Comparing molecule graphs and searching for similar structures is expensive and slow. It can be seen as a special case of the NP-Complete Subgraph Isomorphism problem. Luckily, domain-specific approximate methods exist. The one commonly used in Chemistry is to generate structures from SMILES and later hash them into binary fingerprints. The latter are searchable with binary similarity metrics, like the Tanimoto coefficient. Below is an example using the RDKit package.
from usearch.index import Index, MetricKind
from rdkit import Chem
from rdkit.Chem import AllChem
import numpy as np
molecules = [Chem.MolFromSmiles('CCOC'), Chem.MolFromSmiles('CCO')]
encoder = AllChem.GetRDKitFPGenerator()
fingerprints = np.vstack([encoder.GetFingerprint(x) for x in molecules])
fingerprints = np.packbits(fingerprints, axis=1)
index = Index(ndim=2048, metric=MetricKind.Tanimoto)
keys = np.arange(len(molecules))
index.add(keys, fingerprints)
matches = index.search(fingerprints, 10)
USearch + POI Coordinates = GIS Applications... on iOS?
With Objective-C and Swift iOS bindings, USearch can be easily used in mobile applications. The SwiftVectorSearch project illustrates how to build a dynamic, real-time search system on iOS. In this example, we use 2-dimensional vectorsβencoded as latitude and longitudeβto find the closest Points of Interest (POIs) on a map. The search is based on the Haversine distance metric but can easily be extended to support high-dimensional vectors.
Integrations
- GPTCache: Python.
- LangChain: Python and JavaScript.
- ClickHouse: C++.
- Microsoft Semantic Kernel: Python and C#.
- LanternDB: C++ and Rust.
Citations
@software{Vardanian_USearch_2023,
doi = {10.5281/zenodo.7949416},
author = {Vardanian, Ash},
title = {{USearch by Unum Cloud}},
url = {https://github.com/unum-cloud/usearch},
version = {2.8.10},
year = {2023},
month = oct,
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.16.2 | 123 | 11/4/2024 |
2.16.1 | 66 | 11/3/2024 |
2.16.0 | 79 | 10/29/2024 |
2.15.3 | 129 | 10/10/2024 |
2.15.2 | 163 | 9/28/2024 |
2.15.1 | 160 | 8/28/2024 |
2.14.0 | 99 | 8/19/2024 |
2.13.5 | 110 | 8/18/2024 |
2.13.4 | 106 | 8/15/2024 |
2.13.3 | 100 | 8/14/2024 |
2.13.2 | 115 | 8/12/2024 |
2.13.1 | 86 | 8/7/2024 |
2.13.0 | 99 | 8/6/2024 |
2.12.0 | 278 | 4/29/2024 |
2.11.7 | 133 | 4/15/2024 |
2.11.6 | 123 | 4/14/2024 |
2.11.5 | 107 | 4/12/2024 |
2.11.4 | 112 | 4/11/2024 |
2.11.3 | 109 | 4/10/2024 |
2.11.2 | 101 | 4/10/2024 |
2.11.1 | 100 | 4/10/2024 |
2.11.0 | 115 | 4/8/2024 |
2.10.5 | 109 | 4/4/2024 |
2.10.4 | 104 | 4/2/2024 |
2.10.3 | 101 | 4/2/2024 |
2.10.2 | 106 | 4/1/2024 |
2.10.1 | 106 | 4/1/2024 |
2.10.0 | 120 | 3/31/2024 |
2.9.2 | 154 | 3/5/2024 |
2.9.1 | 307 | 2/27/2024 |
2.9.0 | 119 | 2/22/2024 |
2.8.16 | 238 | 1/24/2024 |
2.8.15 | 149 | 1/9/2024 |
2.8.14 | 187 | 11/26/2023 |
2.8.13 | 128 | 11/18/2023 |
2.8.12 | 114 | 11/13/2023 |
2.8.11 | 123 | 11/11/2023 |
2.8.10 | 124 | 11/11/2023 |
2.8.9 | 128 | 11/9/2023 |
2.8.7 | 116 | 11/9/2023 |
2.8.6 | 111 | 11/6/2023 |
2.8.5 | 122 | 11/6/2023 |
2.8.4 | 112 | 11/6/2023 |
2.8.3 | 108 | 11/5/2023 |
2.8.2 | 148 | 10/30/2023 |
2.8.1 | 123 | 10/24/2023 |
2.7.7 | 138 | 10/22/2023 |
2.7.3 | 131 | 10/21/2023 |
2.7.2 | 127 | 10/17/2023 |
2.7.1 | 129 | 10/17/2023 |
2.7.0 | 132 | 10/13/2023 |
2.6.1 | 131 | 10/13/2023 |
2.6.0 | 124 | 9/25/2023 |
2.5.1 | 117 | 9/20/2023 |
2.4.1 | 121 | 9/18/2023 |
2.4.0 | 123 | 9/18/2023 |
2.3.2 | 135 | 9/10/2023 |
2.3.1 | 132 | 9/8/2023 |
2.3.0 | 140 | 9/6/2023 |
2.2.1 | 121 | 9/5/2023 |
2.2.0 | 120 | 9/5/2023 |
2.1.3 | 124 | 9/4/2023 |
2.1.2 | 117 | 9/4/2023 |
2.1.1 | 131 | 9/2/2023 |
2.1.0 | 133 | 8/31/2023 |
2.0.2 | 135 | 8/30/2023 |
2.0.1 | 143 | 8/28/2023 |
2.0.0 | 141 | 8/28/2023 |