Saturday, December 07, 2024

AI: fast embeddings search with SIMD (JS, Python, ...)

usearch - npm
Smaller & Faster Single-File
Similarity Search & Clustering Engine for Vectors


C++ 11Python 3JavaScriptJavaRustC 99Objective-CSwiftC#GoLangWolfram
Linux • MacOS • Windows • iOS • Android • WebAssembly • SQLite3


10x faster HNSW implementation than FAISS.
✅ Simple and extensible single C++11 header library.
Trusted by giants like Google and DBs like ClickHouse & DuckDB.
SIMD-optimized and user-defined metrics with JIT compilation.
✅ Hardware-agnostic f16 & i8 - half-precision & quarter-precision support.

unum-cloud/usearch: Fast Open-Source Search & Clustering engine × for Vectors & 🔜 Strings × in C++, C, Python, JavaScript, Rust, Java, Objective-C, Swift, C#, GoLang, and Wolfram 🔍 @GitHub

Unum · USearch 2.16.2 documentation @GitHub

USearch is a high-performance library for building and querying vector search indexes, optimized for Node.js and WASM environments.


Alternative

@sroussey/simsimd - npm

Hardware-Accelerated Similarity Metrics and Distance Functions
  • Zero-dependency header-only C 99 library with bindings for Python and JavaScript.
  • Targets ARM NEON, SVE, x86 AVX2, AVX-512 (VNNI, FP16) hardware backends.
  • Zero-copy compatible with NumPy, PyTorch, TensorFlow, and other tensors.
  • Handles f64 double-, f32 single-, and f16 half-precision, i8 integral, and binary vectors.
  • Up to 200x faster than scipy.spatial.distance and numpy.inner.
  • Used in USearch and several DBMS products.


JavaScript

npm i @sroussey/simsimd

import { dot } from '@sroussey/simsimd';
const vector1 = Float32Array.from([1, 2, 3]);
const vector2 = Float32Array.from([4, 5, 6]);
const dotProduct = dot(vector1, vector2); 
// Calculate cosine similarity using the dot product
const cosineSimilarity = dotProduct / (magnitude(vector1) * magnitude(vector2));

Python
pip install simsimd
import simsimd
import numpy as np
vec1 = np.random.randn(1536).astype(np.float32)
vec2 = np.random.randn(1536).astype(np.float32)
dist = simsimd.cosine(vec1, vec2)


No comments: