usearch 2.15.2 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/binding.gyp +1 -1
- package/c/CMakeLists.txt +10 -3
- package/cpp/README.md +1 -1
- package/cpp/bench.cpp +2 -2
- package/cpp/test.cpp +16 -0
- package/include/usearch/index.hpp +44 -17
- package/include/usearch/index_dense.hpp +51 -89
- package/include/usearch/index_plugins.hpp +468 -43
- package/javascript/lib.cpp +17 -5
- package/javascript/usearch.test.js +205 -34
- package/package.json +1 -1
- package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
- package/prebuilds/linux-arm64/usearch.node +0 -0
- package/prebuilds/linux-x64/usearch.node +0 -0
- package/simsimd/.git-blame-ignore-revs +2 -0
- package/simsimd/CODE_OF_CONDUCT.md +128 -0
- package/simsimd/CONTRIBUTING.md +84 -26
- package/simsimd/Cargo.lock +1 -1
- package/simsimd/Cargo.toml +4 -4
- package/simsimd/MANIFEST.in +3 -0
- package/simsimd/Package.swift +15 -3
- package/simsimd/README.md +534 -177
- package/simsimd/binding.gyp +6 -2
- package/simsimd/build.rs +13 -1
- package/simsimd/c/lib.c +266 -53
- package/simsimd/include/simsimd/binary.h +321 -112
- package/simsimd/include/simsimd/curved.h +803 -0
- package/simsimd/include/simsimd/dot.h +694 -521
- package/simsimd/include/simsimd/elementwise.h +1437 -0
- package/simsimd/include/simsimd/geospatial.h +9 -3
- package/simsimd/include/simsimd/mesh.h +69 -0
- package/simsimd/include/simsimd/probability.h +234 -206
- package/simsimd/include/simsimd/simsimd.h +1476 -617
- package/simsimd/include/simsimd/sparse.h +1428 -0
- package/simsimd/include/simsimd/spatial.h +1556 -742
- package/simsimd/include/simsimd/types.h +276 -132
- package/simsimd/javascript/lib.c +1 -2
- package/simsimd/javascript/simsimd.ts +4 -4
- package/simsimd/package.json +4 -4
- package/simsimd/rust/lib.rs +179 -1
- package/simsimd/scripts/bench.cxx +1070 -0
- package/simsimd/scripts/bench.ipynb +187 -0
- package/simsimd/{javascript → scripts}/bench.js +1 -1
- package/simsimd/{rust/benches/sqeuclidean.rs → scripts/bench_sqeuclidean.rs} +6 -6
- package/simsimd/scripts/bench_vectors.py +700 -0
- package/simsimd/scripts/bench_vectors_live.py +213 -0
- package/simsimd/scripts/test.c +155 -0
- package/simsimd/{javascript → scripts}/test.mjs +2 -2
- package/simsimd/scripts/test.py +1410 -0
- package/simsimd/swift/{source/SimSIMD.swift → SimSIMD.swift} +6 -2
- package/simsimd/swift/{tests/SimSIMDTests.swift → Test.swift} +1 -1
- /package/simsimd/{rust/benches/cosine.rs → scripts/bench_cosine.rs} +0 -0
- /package/simsimd/{rust/benches/native.rs → scripts/bench_native.rs} +0 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cells": [
|
|
3
|
+
{
|
|
4
|
+
"cell_type": "code",
|
|
5
|
+
"execution_count": 1,
|
|
6
|
+
"metadata": {},
|
|
7
|
+
"outputs": [],
|
|
8
|
+
"source": [
|
|
9
|
+
"import numpy as np\n",
|
|
10
|
+
"import scipy as sp\n",
|
|
11
|
+
"import simsimd as simd"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"cell_type": "code",
|
|
16
|
+
"execution_count": 2,
|
|
17
|
+
"metadata": {},
|
|
18
|
+
"outputs": [],
|
|
19
|
+
"source": [
|
|
20
|
+
"simsimd_f = simd.cosine\n",
|
|
21
|
+
"conventional_f = sp.spatial.distance.cosine"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"cell_type": "code",
|
|
26
|
+
"execution_count": 3,
|
|
27
|
+
"metadata": {},
|
|
28
|
+
"outputs": [],
|
|
29
|
+
"source": [
|
|
30
|
+
"count = 1000 # Common number of documents in a batch\n",
|
|
31
|
+
"ndim = 1536 # OpenAI Ada v2 embeddings API returns 1536-dim vectors\n",
|
|
32
|
+
"A = np.random.randn(count, ndim).astype(np.float32)\n",
|
|
33
|
+
"B = np.random.randn(count, ndim).astype(np.float32)"
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"cell_type": "code",
|
|
38
|
+
"execution_count": 4,
|
|
39
|
+
"metadata": {},
|
|
40
|
+
"outputs": [
|
|
41
|
+
{
|
|
42
|
+
"name": "stdout",
|
|
43
|
+
"output_type": "stream",
|
|
44
|
+
"text": [
|
|
45
|
+
"16.3 ms ± 3.84 ms per loop (mean ± std. dev. of 10 runs, 1 loop each)\n"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"source": [
|
|
50
|
+
"%%timeit -n 1 -r 10\n",
|
|
51
|
+
"result_np = [conventional_f(A[i], B[i]) for i in range(count)]"
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"cell_type": "code",
|
|
56
|
+
"execution_count": 5,
|
|
57
|
+
"metadata": {},
|
|
58
|
+
"outputs": [
|
|
59
|
+
{
|
|
60
|
+
"name": "stdout",
|
|
61
|
+
"output_type": "stream",
|
|
62
|
+
"text": [
|
|
63
|
+
"437 µs ± 15.6 µs per loop (mean ± std. dev. of 10 runs, 1 loop each)\n"
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
"source": [
|
|
68
|
+
"%%timeit -n 1 -r 10\n",
|
|
69
|
+
"result_simd = simsimd_f(A, B)"
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"cell_type": "code",
|
|
74
|
+
"execution_count": 6,
|
|
75
|
+
"metadata": {},
|
|
76
|
+
"outputs": [],
|
|
77
|
+
"source": [
|
|
78
|
+
"A = np.random.randn(count, ndim).astype(np.float16)\n",
|
|
79
|
+
"B = np.random.randn(count, ndim).astype(np.float16)"
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"cell_type": "code",
|
|
84
|
+
"execution_count": 7,
|
|
85
|
+
"metadata": {},
|
|
86
|
+
"outputs": [
|
|
87
|
+
{
|
|
88
|
+
"name": "stdout",
|
|
89
|
+
"output_type": "stream",
|
|
90
|
+
"text": [
|
|
91
|
+
"36.7 ms ± 843 µs per loop (mean ± std. dev. of 10 runs, 1 loop each)\n"
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"source": [
|
|
96
|
+
"%%timeit -n 1 -r 10\n",
|
|
97
|
+
"result_np = [conventional_f(A[i], B[i]) for i in range(count)]"
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"cell_type": "code",
|
|
102
|
+
"execution_count": 8,
|
|
103
|
+
"metadata": {},
|
|
104
|
+
"outputs": [
|
|
105
|
+
{
|
|
106
|
+
"name": "stdout",
|
|
107
|
+
"output_type": "stream",
|
|
108
|
+
"text": [
|
|
109
|
+
"437 µs ± 7.61 µs per loop (mean ± std. dev. of 10 runs, 1 loop each)\n"
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
"source": [
|
|
114
|
+
"%%timeit -n 1 -r 10\n",
|
|
115
|
+
"result_simd = simsimd_f(A, B)"
|
|
116
|
+
]
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"cell_type": "code",
|
|
120
|
+
"execution_count": 9,
|
|
121
|
+
"metadata": {},
|
|
122
|
+
"outputs": [],
|
|
123
|
+
"source": [
|
|
124
|
+
"A = np.random.randint(-100, 100, (count, ndim), np.int8)\n",
|
|
125
|
+
"B = np.random.randint(-100, 100, (count, ndim), np.int8)"
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"cell_type": "code",
|
|
130
|
+
"execution_count": 10,
|
|
131
|
+
"metadata": {},
|
|
132
|
+
"outputs": [
|
|
133
|
+
{
|
|
134
|
+
"name": "stdout",
|
|
135
|
+
"output_type": "stream",
|
|
136
|
+
"text": [
|
|
137
|
+
"12.4 ms ± 493 µs per loop (mean ± std. dev. of 10 runs, 1 loop each)\n"
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
"source": [
|
|
142
|
+
"%%timeit -n 1 -r 10\n",
|
|
143
|
+
"result_np = [conventional_f(A[i], B[i]) for i in range(count)]"
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"cell_type": "code",
|
|
148
|
+
"execution_count": 11,
|
|
149
|
+
"metadata": {},
|
|
150
|
+
"outputs": [
|
|
151
|
+
{
|
|
152
|
+
"name": "stdout",
|
|
153
|
+
"output_type": "stream",
|
|
154
|
+
"text": [
|
|
155
|
+
"63.6 µs ± 3.27 µs per loop (mean ± std. dev. of 10 runs, 1 loop each)\n"
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"source": [
|
|
160
|
+
"%%timeit -n 1 -r 10\n",
|
|
161
|
+
"result_simd = simsimd_f(A, B)"
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
"metadata": {
|
|
166
|
+
"kernelspec": {
|
|
167
|
+
"display_name": "base",
|
|
168
|
+
"language": "python",
|
|
169
|
+
"name": "python3"
|
|
170
|
+
},
|
|
171
|
+
"language_info": {
|
|
172
|
+
"codemirror_mode": {
|
|
173
|
+
"name": "ipython",
|
|
174
|
+
"version": 3
|
|
175
|
+
},
|
|
176
|
+
"file_extension": ".py",
|
|
177
|
+
"mimetype": "text/x-python",
|
|
178
|
+
"name": "python",
|
|
179
|
+
"nbconvert_exporter": "python",
|
|
180
|
+
"pygments_lexer": "ipython3",
|
|
181
|
+
"version": "3.10.11"
|
|
182
|
+
},
|
|
183
|
+
"orig_nbformat": 4
|
|
184
|
+
},
|
|
185
|
+
"nbformat": 4,
|
|
186
|
+
"nbformat_minor": 2
|
|
187
|
+
}
|
|
@@ -2,7 +2,7 @@ const benchmark = require('benchmark');
|
|
|
2
2
|
const math = require('mathjs');
|
|
3
3
|
const usearch = require('usearch');
|
|
4
4
|
const MetricKind = usearch.MetricKind;
|
|
5
|
-
const simsimd = require("
|
|
5
|
+
const simsimd = require("../javascript/dist/cjs/simsimd.js");
|
|
6
6
|
|
|
7
7
|
// Assuming the vectors are of the same length
|
|
8
8
|
function cosineDistance(a, b) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
|
2
2
|
use simsimd::SpatialSimilarity as SimSIMD;
|
|
3
3
|
|
|
4
|
-
mod
|
|
4
|
+
mod bench_native;
|
|
5
5
|
|
|
6
6
|
const DIMENSIONS: usize = 1536;
|
|
7
7
|
|
|
8
8
|
pub fn l2sq_benchmark(c: &mut Criterion) {
|
|
9
9
|
let inputs: (Vec<f32>, Vec<f32>) = (
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
bench_native::generate_random_vector(DIMENSIONS),
|
|
11
|
+
bench_native::generate_random_vector(DIMENSIONS),
|
|
12
12
|
);
|
|
13
13
|
|
|
14
14
|
let mut group = c.benchmark_group("SIMD SqEuclidean");
|
|
@@ -18,13 +18,13 @@ pub fn l2sq_benchmark(c: &mut Criterion) {
|
|
|
18
18
|
b.iter(|| SimSIMD::sqeuclidean(&inputs.0, &inputs.1))
|
|
19
19
|
});
|
|
20
20
|
group.bench_with_input(BenchmarkId::new("Rust Procedural", i), &i, |b, _| {
|
|
21
|
-
b.iter(||
|
|
21
|
+
b.iter(|| bench_native::baseline_l2sq_procedural(&inputs.0, &inputs.1))
|
|
22
22
|
});
|
|
23
23
|
group.bench_with_input(BenchmarkId::new("Rust Functional", i), &i, |b, _| {
|
|
24
|
-
b.iter(||
|
|
24
|
+
b.iter(|| bench_native::baseline_l2sq_functional(&inputs.0, &inputs.1))
|
|
25
25
|
});
|
|
26
26
|
group.bench_with_input(BenchmarkId::new("Rust Unrolled", i), &i, |b, _| {
|
|
27
|
-
b.iter(||
|
|
27
|
+
b.iter(|| bench_native::baseline_l2sq_unrolled(&inputs.0, &inputs.1))
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
}
|