usearch 2.9.1 → 2.10.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.
Files changed (169) hide show
  1. package/README.md +50 -52
  2. package/javascript/{types → dist/cjs}/usearch.d.ts +90 -115
  3. package/javascript/dist/cjs/usearch.js +531 -0
  4. package/javascript/dist/esm/usearch.d.ts +212 -0
  5. package/javascript/{usearch.js → dist/esm/usearch.js} +202 -153
  6. package/package.json +25 -23
  7. package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
  8. package/prebuilds/linux-arm64/usearch.node +0 -0
  9. package/prebuilds/linux-x64/usearch.node +0 -0
  10. package/prebuilds/win32-ia32/usearch.node +0 -0
  11. package/prebuilds/win32-x64/usearch.node +0 -0
  12. package/.clang-format +0 -10
  13. package/.clang-tidy +0 -60
  14. package/.cmake-format.py +0 -19
  15. package/.dockerignore +0 -93
  16. package/.gitattributes +0 -9
  17. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
  18. package/.github/ISSUE_TEMPLATE/config.yml +0 -5
  19. package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -64
  20. package/.github/workflows/Dockerfile.libs +0 -36
  21. package/.github/workflows/prerelease.yml +0 -331
  22. package/.github/workflows/release.yml +0 -722
  23. package/.github/workflows/update_version.sh +0 -15
  24. package/.gitmodules +0 -9
  25. package/.releaserc +0 -90
  26. package/CITATION.cff +0 -11
  27. package/CMakeLists.txt +0 -324
  28. package/CODE_OF_CONDUCT.md +0 -128
  29. package/CONTRIBUTING.md +0 -353
  30. package/Cargo.toml +0 -19
  31. package/Dockerfile +0 -16
  32. package/VERSION +0 -1
  33. package/assets/unum.png +0 -0
  34. package/assets/usearch-approaches-transparent.png +0 -0
  35. package/assets/usearch-approaches-white.png +0 -0
  36. package/assets/usearch-neighbor-types.png +0 -0
  37. package/binding.gyp +0 -87
  38. package/build.gradle +0 -204
  39. package/build.rs +0 -18
  40. package/c/CMakeLists.txt +0 -25
  41. package/c/README.md +0 -34
  42. package/c/lib.cpp +0 -358
  43. package/c/test.c +0 -374
  44. package/c/usearch.h +0 -311
  45. package/cmake/clipp.cmake +0 -7
  46. package/cmake/config.cmake.in +0 -15
  47. package/cmake/emscripten.cmake +0 -8
  48. package/cmake/jemalloc.cmake +0 -62
  49. package/cmake/pkg-config.pc.in +0 -4
  50. package/cmake/usearchConfigVersion.cmake.in +0 -20
  51. package/conanfile.py +0 -26
  52. package/cpp/CMakeLists.txt +0 -14
  53. package/cpp/README.md +0 -161
  54. package/cpp/bench.cpp +0 -618
  55. package/cpp/test.cpp +0 -323
  56. package/fp16/CMakeLists.txt +0 -176
  57. package/fp16/LICENSE +0 -11
  58. package/fp16/README.md +0 -20
  59. package/fp16/bench/alt-element.cc +0 -89
  60. package/fp16/bench/from-alt-array.cc +0 -175
  61. package/fp16/bench/from-ieee-array.cc +0 -399
  62. package/fp16/bench/ieee-element.cc +0 -272
  63. package/fp16/bench/to-alt-array.cc +0 -91
  64. package/fp16/bench/to-ieee-array.cc +0 -303
  65. package/fp16/cmake/DownloadGoogleBenchmark.cmake +0 -15
  66. package/fp16/cmake/DownloadGoogleTest.cmake +0 -15
  67. package/fp16/cmake/DownloadPSimd.cmake +0 -15
  68. package/fp16/configure.py +0 -65
  69. package/fp16/confu.yaml +0 -8
  70. package/fp16/include/fp16/__init__.py +0 -0
  71. package/fp16/include/fp16/avx.py +0 -50
  72. package/fp16/include/fp16/avx2.py +0 -53
  73. package/fp16/include/fp16/bitcasts.h +0 -92
  74. package/fp16/include/fp16/fp16.h +0 -451
  75. package/fp16/include/fp16/psimd.h +0 -131
  76. package/fp16/include/fp16.h +0 -11
  77. package/fp16/jni/Android.mk +0 -6
  78. package/fp16/jni/Application.mk +0 -4
  79. package/fp16/test/alt-from-fp32-value.cc +0 -498
  80. package/fp16/test/alt-to-fp32-bits.cc +0 -263
  81. package/fp16/test/alt-to-fp32-psimd.cc +0 -145
  82. package/fp16/test/alt-to-fp32-value.cc +0 -348
  83. package/fp16/test/alt-to-fp32x2-psimd.cc +0 -245
  84. package/fp16/test/bitcasts.cc +0 -56
  85. package/fp16/test/ieee-from-fp32-value.cc +0 -523
  86. package/fp16/test/ieee-to-fp32-bits.cc +0 -333
  87. package/fp16/test/ieee-to-fp32-psimd.cc +0 -312
  88. package/fp16/test/ieee-to-fp32-value.cc +0 -420
  89. package/fp16/test/ieee-to-fp32x2-psimd.cc +0 -541
  90. package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +0 -96
  91. package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +0 -96
  92. package/fp16/test/peachpy/stubs.py +0 -38
  93. package/fp16/test/tables.cc +0 -530
  94. package/fp16/test/tables.h +0 -13
  95. package/fp16/third-party/THHalf.h +0 -92
  96. package/fp16/third-party/eigen-half.h +0 -170
  97. package/fp16/third-party/float16-compressor.h +0 -80
  98. package/fp16/third-party/half.hpp +0 -2916
  99. package/fp16/third-party/npy-halffloat.h +0 -328
  100. package/include/usearch/index.hpp +0 -3836
  101. package/include/usearch/index_dense.hpp +0 -2004
  102. package/include/usearch/index_plugins.hpp +0 -2203
  103. package/javascript/lib.cpp +0 -341
  104. package/javascript/types/usearch.d.ts.map +0 -1
  105. package/javascript/usearch.test.js +0 -74
  106. package/package-ci.json +0 -10
  107. package/pyproject.toml +0 -51
  108. package/setup.py +0 -201
  109. package/simsimd/.releaserc +0 -86
  110. package/simsimd/Cargo.lock +0 -708
  111. package/simsimd/Cargo.toml +0 -36
  112. package/simsimd/LICENSE +0 -201
  113. package/simsimd/README.md +0 -275
  114. package/simsimd/binding.gyp +0 -36
  115. package/simsimd/build.rs +0 -20
  116. package/simsimd/include/simsimd/binary.h +0 -201
  117. package/simsimd/include/simsimd/probability.h +0 -548
  118. package/simsimd/include/simsimd/simsimd.h +0 -456
  119. package/simsimd/include/simsimd/spatial.h +0 -1175
  120. package/simsimd/include/simsimd/types.h +0 -207
  121. package/simsimd/javascript/bench.js +0 -127
  122. package/simsimd/javascript/fallback.ts +0 -193
  123. package/simsimd/javascript/lib.c +0 -102
  124. package/simsimd/javascript/node-gyp-build.d.ts +0 -1
  125. package/simsimd/javascript/simsimd.ts +0 -124
  126. package/simsimd/javascript/test.mjs +0 -153
  127. package/simsimd/javascript/tsconfig-base.json +0 -25
  128. package/simsimd/javascript/tsconfig-cjs.json +0 -8
  129. package/simsimd/javascript/tsconfig-esm.json +0 -8
  130. package/simsimd/package-lock.json +0 -1688
  131. package/simsimd/package.json +0 -61
  132. package/simsimd/rust/benches/cosine.rs +0 -27
  133. package/simsimd/rust/benches/native.rs +0 -27
  134. package/simsimd/rust/benches/sqeuclidean.rs +0 -27
  135. package/simsimd/rust/lib.c +0 -68
  136. package/simsimd/rust/lib.rs +0 -232
  137. package/sqlite/README.md +0 -178
  138. package/sqlite/lib.cpp +0 -325
  139. package/stringzilla/CONTRIBUTING.md +0 -429
  140. package/stringzilla/Cargo.lock +0 -25
  141. package/stringzilla/Cargo.toml +0 -26
  142. package/stringzilla/LICENSE +0 -201
  143. package/stringzilla/README.md +0 -1281
  144. package/stringzilla/VERSION +0 -1
  145. package/stringzilla/assets/cover-strinzilla.jpeg +0 -0
  146. package/stringzilla/assets/meme-stringzilla-v2.jpeg +0 -0
  147. package/stringzilla/assets/meme-stringzilla-v3.jpeg +0 -0
  148. package/stringzilla/binding.gyp +0 -16
  149. package/stringzilla/build.rs +0 -14
  150. package/stringzilla/c/lib.c +0 -304
  151. package/stringzilla/cli/README.md +0 -48
  152. package/stringzilla/cli/split.py +0 -72
  153. package/stringzilla/cli/wc.py +0 -37
  154. package/stringzilla/include/stringzilla/experimental.h +0 -724
  155. package/stringzilla/include/stringzilla/module.modulemap +0 -9
  156. package/stringzilla/include/stringzilla/stringzilla.h +0 -5240
  157. package/stringzilla/include/stringzilla/stringzilla.hpp +0 -3830
  158. package/stringzilla/javascript/lib.c +0 -125
  159. package/stringzilla/javascript/stringzilla.js +0 -22
  160. package/stringzilla/package-ci.json +0 -10
  161. package/stringzilla/package.json +0 -32
  162. package/stringzilla/rust/lib.rs +0 -362
  163. package/stringzilla/swift/StringProtocol+StringZilla.swift +0 -280
  164. package/stringzilla/swift/Test.swift +0 -60
  165. package/tsconfig.json +0 -21
  166. package/wasmer.toml +0 -12
  167. package/winlibinstaller.bat +0 -42
  168. /package/{simsimd/javascript/dist-package-cjs.json → javascript/dist/cjs/package.json} +0 -0
  169. /package/{simsimd/javascript/dist-package-esm.json → javascript/dist/esm/package.json} +0 -0
package/c/test.c DELETED
@@ -1,374 +0,0 @@
1
- #include <errno.h>
2
- #include <stdio.h> // `remove`
3
- #include <stdlib.h>
4
- #include <sys/stat.h>
5
-
6
- #include "usearch.h"
7
-
8
- #define ASSERT(must_be_true, message) \
9
- if (!(must_be_true)) { \
10
- printf("Assert: %s\n", message); \
11
- exit(-1); \
12
- }
13
-
14
- /**
15
- * @brief Creates and initializes vectors with random float values.
16
- *
17
- * @param count The number of vectors.
18
- * @param dimensions The number of dimensions per vector.
19
- * @return A pointer to the first element of the vectors, that must be @b free-ed afterwards.
20
- */
21
- float* create_vectors(size_t const count, size_t const dimensions) {
22
- float* data = (float*)malloc(count * dimensions * sizeof(float));
23
- ASSERT(data, "Failed to allocate memory");
24
- for (size_t index = 0; index < count * dimensions; ++index)
25
- data[index] = (float)rand() / (float)RAND_MAX;
26
- return data;
27
- }
28
-
29
- usearch_init_options_t create_options(size_t const dimensions) {
30
- usearch_init_options_t opts;
31
- opts.connectivity = 3; // 32 in faiss
32
- opts.dimensions = dimensions;
33
- opts.expansion_add = 40; // 40 in faiss
34
- opts.expansion_search = 16; // 10 in faiss
35
- opts.metric_kind = usearch_metric_ip_k;
36
- opts.metric = NULL;
37
- opts.quantization = usearch_scalar_f32_k;
38
- return opts;
39
- }
40
-
41
- /**
42
- * This test is designed to verify the initialization of the index with specific dimensions and ensures that the
43
- * associated properties are set correctly. It initializes the index twice, checking for errors at each step, and
44
- * performs a reserve operation to pre-allocate space in the index, verifying the correct settings of size, capacity,
45
- * dimensions, and connectivity after each operation.
46
- */
47
- void test_init(size_t const collection_size, size_t const dimensions) {
48
- printf("Test: Index Initialization...\n");
49
-
50
- // Init index
51
- usearch_error_t error = NULL;
52
- usearch_init_options_t opts = create_options(dimensions);
53
- usearch_index_t index = usearch_init(&opts, &error);
54
- ASSERT(!error, error);
55
- usearch_free(index, &error);
56
- ASSERT(!error, error);
57
-
58
- // Init second time
59
- index = usearch_init(&opts, &error);
60
- ASSERT(!error, error);
61
-
62
- ASSERT(usearch_size(index, &error) == 0, error);
63
- ASSERT(usearch_capacity(index, &error) == 0, error);
64
- ASSERT(usearch_dimensions(index, &error) == dimensions, error);
65
- ASSERT(usearch_connectivity(index, &error) == opts.connectivity, error);
66
-
67
- // Reserve
68
- usearch_reserve(index, collection_size, &error);
69
- ASSERT(!error, error);
70
- ASSERT(usearch_size(index, &error) == 0, error);
71
- ASSERT(usearch_capacity(index, &error) == collection_size, error);
72
- ASSERT(usearch_dimensions(index, &error) == dimensions, error);
73
- ASSERT(usearch_connectivity(index, &error) == opts.connectivity, error);
74
-
75
- usearch_free(index, &error);
76
- ASSERT(!error, error);
77
-
78
- printf("Test: Index Initialization - PASSED\n");
79
- }
80
-
81
- /**
82
- * This test validates the addition of vectors to the index. It initializes the index and reserves space for vectors.
83
- * It then iteratively adds vectors to the index and checks if the index contains the added vectors by verifying the
84
- * size, capacity, and presence of each vector in the index.
85
- */
86
- void test_add_vector(size_t const collection_size, size_t const dimensions) {
87
- printf("Test: Add Vector...\n");
88
-
89
- usearch_error_t error = NULL;
90
- usearch_init_options_t opts = create_options(dimensions);
91
- usearch_index_t index = usearch_init(&opts, &error);
92
- usearch_reserve(index, collection_size, &error);
93
-
94
- // Add vectors
95
- float* data = create_vectors(collection_size, dimensions);
96
- for (size_t i = 0; i < collection_size; ++i) {
97
- usearch_key_t key = i;
98
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
99
- ASSERT(!error, error);
100
- }
101
-
102
- ASSERT(usearch_size(index, &error) == collection_size, error);
103
- ASSERT(usearch_capacity(index, &error) == collection_size, error);
104
-
105
- // Check vectors in the index
106
- for (size_t i = 0; i < collection_size; ++i) {
107
- usearch_key_t key = i;
108
- ASSERT(usearch_contains(index, key, &error), error);
109
- }
110
- ASSERT(!usearch_contains(index, -1, &error), error); // Non existing key
111
-
112
- free(data);
113
- usearch_free(index, &error);
114
- printf("Test: Add Vector - PASSED\n");
115
- }
116
-
117
- /**
118
- * This test ensures that vectors added to the index can be correctly found. It initializes the index, reserves space,
119
- * and adds vectors. It then performs a search query for each added vector to ensure that the vectors are correctly
120
- * found in the index, validating the count of found vectors.
121
- */
122
- void test_find_vector(size_t const collection_size, size_t const dimensions) {
123
- printf("Test: Find Vector...\n");
124
-
125
- usearch_error_t error = NULL;
126
- usearch_init_options_t opts = create_options(dimensions);
127
- usearch_index_t index = usearch_init(&opts, &error);
128
- usearch_reserve(index, collection_size, &error);
129
-
130
- // Create result buffers
131
- usearch_key_t* keys = (usearch_key_t*)malloc(collection_size * sizeof(usearch_key_t));
132
- float* distances = (float*)malloc(collection_size * sizeof(float));
133
- ASSERT(keys && distances, "Failed to allocate memory");
134
-
135
- // Add vectors
136
- float* data = create_vectors(collection_size, dimensions);
137
- for (size_t i = 0; i < collection_size; ++i) {
138
- usearch_key_t key = i;
139
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
140
- ASSERT(!error, error);
141
- }
142
-
143
- // Find the vectors
144
- for (size_t i = 0; i < collection_size; i++) {
145
- size_t found_count = usearch_search(index, data + i * dimensions, usearch_scalar_f32_k, collection_size, keys,
146
- distances, &error);
147
- ASSERT(!error, error);
148
- ASSERT(found_count >= 1 && found_count <= collection_size, "Vector is missing");
149
- }
150
-
151
- free(data);
152
- free(keys);
153
- free(distances);
154
- usearch_free(index, &error);
155
- printf("Test: Find Vector - PASSED\n");
156
- }
157
-
158
- /**
159
- * This test checks the ability of the index to handle multiple vectors associated with the same key. It initializes
160
- * the index with the multi-option enabled, reserves space, and adds multiple vectors with the same key. The test then
161
- * retrieves vectors associated with the key from the index and checks the count of retrieved vectors.
162
- */
163
- void test_get_vector(size_t const collection_size, size_t const dimensions) {
164
- printf("Test: Get Vector...\n");
165
-
166
- usearch_error_t error = NULL;
167
- usearch_init_options_t opts = create_options(dimensions);
168
- opts.multi = true;
169
- usearch_index_t index = usearch_init(&opts, &error);
170
- usearch_reserve(index, collection_size, &error);
171
-
172
- // Create result buffers
173
- float* vectors = (float*)malloc(collection_size * dimensions * sizeof(float));
174
- ASSERT(vectors, "Failed to allocate memory");
175
-
176
- // Add multiple vectors with SAME key
177
- usearch_key_t const key = 1;
178
- float* data = create_vectors(collection_size, dimensions);
179
- for (size_t i = 0; i < collection_size; i++) {
180
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
181
- ASSERT(!error, error);
182
- }
183
-
184
- // Retrieve vectors from index
185
- size_t found_count = usearch_get(index, key, collection_size, vectors, usearch_scalar_f32_k, &error);
186
- ASSERT(found_count == collection_size, "Vector is missing");
187
-
188
- free(vectors);
189
- free(data);
190
- usearch_free(index, &error);
191
-
192
- printf("Test: Get Vector - PASSED\n");
193
- }
194
-
195
- /**
196
- * This test ensures that vectors can be successfully removed from the index. It initializes the index, reserves space,
197
- * and adds vectors. It then iteratively removes each vector from the index and checks for errors. However, note that
198
- * the assert in this test expects an error, indicating that the remove functionality is not currently supported.
199
- */
200
- void test_remove_vector(size_t const collection_size, size_t const dimensions) {
201
- printf("Test: Remove Vector...\n");
202
-
203
- usearch_error_t error = NULL;
204
- usearch_init_options_t opts = create_options(dimensions);
205
- usearch_index_t index = usearch_init(&opts, &error);
206
- usearch_reserve(index, collection_size, &error);
207
-
208
- // Add vectors
209
- float* data = create_vectors(collection_size, dimensions);
210
- for (size_t i = 0; i < collection_size; ++i) {
211
- usearch_key_t key = i;
212
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
213
- ASSERT(!error, error);
214
- }
215
-
216
- // Remove the vectors
217
- for (size_t i = 0; i < collection_size; i++) {
218
- usearch_key_t key = i;
219
- usearch_remove(index, key, &error);
220
- ASSERT(!error, "Currently, Remove is not supported");
221
- }
222
-
223
- free(data);
224
- usearch_free(index, &error);
225
- printf("Test: Remove Vector - PASSED\n");
226
- }
227
-
228
- /**
229
- * This test validates the save and load functionality of the index. It initializes the index, reserves space, and adds
230
- * vectors. The index is then saved to a file and freed. A new index is initialized, and the previously saved index is
231
- * loaded into it. The test then validates the loaded index properties and ensures that it contains all the vectors
232
- * from the saved index.
233
- */
234
- void test_save_load(size_t const collection_size, size_t const dimensions) {
235
- printf("Test: Save/Load...\n");
236
-
237
- usearch_error_t error = NULL;
238
- usearch_init_options_t opts = create_options(dimensions);
239
- usearch_init_options_t weird_ops = opts;
240
- weird_ops.connectivity = 11;
241
- weird_ops.expansion_add = 15;
242
- weird_ops.expansion_search = 19;
243
- weird_ops.metric_kind = usearch_metric_pearson_k;
244
- weird_ops.quantization = usearch_scalar_f64_k;
245
- usearch_index_t index = usearch_init(&weird_ops, &error);
246
- usearch_reserve(index, collection_size, &error);
247
-
248
- // Add vectors
249
- float* data = create_vectors(collection_size, dimensions);
250
- for (size_t i = 0; i < collection_size; ++i) {
251
- usearch_key_t key = i;
252
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
253
- ASSERT(!error, error);
254
- }
255
-
256
- // Save and free the index
257
- usearch_save(index, "tmp.usearch", &error);
258
- ASSERT(!error, error);
259
- usearch_free(index, &error);
260
- ASSERT(!error, error);
261
-
262
- // Reset the options
263
- opts.connectivity = 0;
264
- opts.dimensions = 0;
265
- opts.expansion_add = 0;
266
- opts.expansion_search = 0;
267
- opts.metric = NULL;
268
- opts.quantization = usearch_scalar_unknown_k;
269
- opts.metric_kind = usearch_metric_unknown_k;
270
-
271
- // Reinit
272
- index = usearch_init(&opts, &error);
273
- ASSERT(!error, error);
274
- ASSERT(usearch_size(index, &error) == 0, error);
275
-
276
- // Load
277
- usearch_load(index, "tmp.usearch", &error);
278
- ASSERT(!error, error);
279
- ASSERT(usearch_size(index, &error) == collection_size, error);
280
- ASSERT(usearch_capacity(index, &error) == collection_size, error);
281
- ASSERT(usearch_dimensions(index, &error) == dimensions, error);
282
- ASSERT(usearch_connectivity(index, &error) == weird_ops.connectivity, error);
283
-
284
- // Check vectors in the index
285
- for (size_t i = 0; i < collection_size; ++i) {
286
- usearch_key_t key = i;
287
- ASSERT(usearch_contains(index, key, &error), error);
288
- }
289
-
290
- // Create result buffers
291
- usearch_key_t* keys = (usearch_key_t*)malloc(collection_size * sizeof(usearch_key_t));
292
- float* distances = (float*)malloc(collection_size * sizeof(float));
293
- ASSERT(keys && distances, "Failed to allocate memory");
294
-
295
- // Find the vectors
296
- for (size_t i = 0; i < collection_size; i++) {
297
- size_t found_count = usearch_search(index, data + i * dimensions, usearch_scalar_f32_k, collection_size, keys,
298
- distances, &error);
299
- ASSERT(!error, error);
300
- ASSERT(found_count >= 1 && found_count <= collection_size, "Vector is missing");
301
- }
302
-
303
- free(data);
304
- free(keys);
305
- free(distances);
306
- usearch_free(index, &error);
307
-
308
- // Remove the file from disk
309
- remove("tmp.usearch");
310
-
311
- printf("Test: Save/Load - PASSED\n");
312
- }
313
-
314
- /**
315
- * This test is designed to validate the view functionality of the index. It initializes the index, reserves space, and
316
- * adds vectors. The index is then saved to a file and freed. A new index is initialized and a view is created from the
317
- * saved index file. The test is mainly focused on ensuring that no errors occur during these operations, but it does
318
- * not verify the properties or contents of the viewed index.
319
- */
320
- void test_view(size_t const collection_size, size_t const dimensions) {
321
- printf("Test: View...\n");
322
-
323
- usearch_error_t error = NULL;
324
- usearch_init_options_t opts = create_options(dimensions);
325
- usearch_index_t index = usearch_init(&opts, &error);
326
- usearch_reserve(index, collection_size, &error);
327
-
328
- // Add vectors
329
- float* data = create_vectors(collection_size, dimensions);
330
- for (size_t i = 0; i < collection_size; ++i) {
331
- usearch_key_t key = i;
332
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
333
- ASSERT(!error, error);
334
- }
335
-
336
- // Save and free the index
337
- usearch_save(index, "tmp.usearch", &error);
338
- ASSERT(!error, error);
339
- usearch_free(index, &error);
340
- ASSERT(!error, error);
341
-
342
- // Reinit
343
- index = usearch_init(&opts, &error);
344
- ASSERT(!error, error);
345
-
346
- // View
347
- usearch_view(index, "tmp.usearch", &error);
348
- ASSERT(!error, error);
349
-
350
- free(data);
351
- usearch_free(index, &error);
352
- printf("Test: View - PASSED\n");
353
- }
354
-
355
- int main(int argc, char const* argv[]) {
356
-
357
- size_t collection_sizes[] = {11, 512};
358
- size_t dimensions[] = {83, 1};
359
- for (size_t index = 0; index < sizeof(collection_sizes) / sizeof(collection_sizes[0]); ++index) {
360
- for (size_t jdx = 0; jdx < sizeof(dimensions) / sizeof(dimensions[0]); ++jdx) {
361
- test_init(collection_sizes[index], dimensions[jdx]);
362
- test_add_vector(collection_sizes[index], dimensions[jdx]);
363
- test_find_vector(collection_sizes[index], dimensions[jdx]);
364
- test_get_vector(collection_sizes[index], dimensions[jdx]);
365
- test_remove_vector(collection_sizes[index], dimensions[jdx]);
366
- test_save_load(collection_sizes[index], dimensions[jdx]);
367
- test_view(collection_sizes[index], dimensions[jdx]);
368
- }
369
- }
370
-
371
- (void)argc;
372
- (void)argv;
373
- return 0;
374
- }
package/c/usearch.h DELETED
@@ -1,311 +0,0 @@
1
- #ifndef UNUM_USEARCH_H
2
- #define UNUM_USEARCH_H
3
-
4
- #ifdef __cplusplus
5
- extern "C" {
6
- #endif
7
-
8
- #ifndef USEARCH_EXPORT
9
- #if defined(_WIN32) && !defined(__MINGW32__)
10
- #define USEARCH_EXPORT __declspec(dllexport)
11
- #else
12
- #define USEARCH_EXPORT
13
- #endif
14
- #endif
15
-
16
- #include <stdbool.h> // `bool`
17
- #include <stddef.h> // `size_t`
18
- #include <stdint.h> // `uint64_t`
19
-
20
- USEARCH_EXPORT typedef void* usearch_index_t;
21
- USEARCH_EXPORT typedef uint64_t usearch_key_t;
22
- USEARCH_EXPORT typedef float usearch_distance_t;
23
-
24
- /**
25
- * @brief Pointer to a null-terminated error message.
26
- * Returned error messages @b don't need to be deallocated.
27
- */
28
- USEARCH_EXPORT typedef char const* usearch_error_t;
29
-
30
- /**
31
- * @brief Type-punned callback for "metrics" or "distance functions",
32
- * that accepts pointers to two vectors and measures their @b dis-similarity.
33
- */
34
- USEARCH_EXPORT typedef usearch_distance_t (*usearch_metric_t)(void const*, void const*);
35
-
36
- /**
37
- * @brief Enumerator for the most common kinds of `usearch_metric_t`.
38
- * Those are supported out of the box, with SIMD-optimizations for most common hardware.
39
- */
40
- USEARCH_EXPORT typedef enum usearch_metric_kind_t {
41
- usearch_metric_unknown_k = 0,
42
- usearch_metric_cos_k = 1,
43
- usearch_metric_ip_k = 2,
44
- usearch_metric_l2sq_k = 3,
45
- usearch_metric_haversine_k = 4,
46
- usearch_metric_divergence_k = 5,
47
- usearch_metric_pearson_k = 6,
48
- usearch_metric_jaccard_k = 7,
49
- usearch_metric_hamming_k = 8,
50
- usearch_metric_tanimoto_k = 9,
51
- usearch_metric_sorensen_k = 10,
52
- } usearch_metric_kind_t;
53
-
54
- USEARCH_EXPORT typedef enum usearch_scalar_kind_t {
55
- usearch_scalar_unknown_k = 0,
56
- usearch_scalar_f32_k = 1,
57
- usearch_scalar_f64_k = 2,
58
- usearch_scalar_f16_k = 3,
59
- usearch_scalar_i8_k = 4,
60
- usearch_scalar_b1_k = 5,
61
- } usearch_scalar_kind_t;
62
-
63
- USEARCH_EXPORT typedef struct usearch_init_options_t {
64
- /**
65
- * @brief The metric kind used for distance calculation between vectors.
66
- */
67
- usearch_metric_kind_t metric_kind;
68
- /**
69
- * @brief The @b optional custom distance metric function used for distance calculation between vectors.
70
- * If the `metric_kind` is set to `usearch_metric_unknown_k`, this function pointer mustn't be `NULL`.
71
- */
72
- usearch_metric_t metric;
73
- /**
74
- * @brief The scalar kind used for quantization of vector data during indexing.
75
- */
76
- usearch_scalar_kind_t quantization;
77
- /**
78
- * @brief The number of dimensions in the vectors to be indexed.
79
- * Must be defined for most metrics, but can be avoided for `usearch_metric_haversine_k`.
80
- */
81
- size_t dimensions;
82
- /**
83
- * @brief The @b optional connectivity parameter that limits connections-per-node in graph.
84
- */
85
- size_t connectivity;
86
- /**
87
- * @brief The @b optional expansion factor used for index construction when adding vectors.
88
- */
89
- size_t expansion_add;
90
- /**
91
- * @brief The @b optional expansion factor used for index construction during search operations.
92
- */
93
- size_t expansion_search;
94
- /**
95
- * @brief When set allows multiple vectors to map to the same key.
96
- */
97
- bool multi;
98
- } usearch_init_options_t;
99
-
100
- /**
101
- * @brief Initializes a new instance of the index.
102
- * @param options Pointer to the `usearch_init_options_t` structure containing initialization options.
103
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
104
- * @return A handle to the initialized USearch index, or `NULL` on failure.
105
- */
106
- USEARCH_EXPORT usearch_index_t usearch_init(usearch_init_options_t* options, usearch_error_t* error);
107
-
108
- /**
109
- * @brief Frees the resources associated with the index.
110
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
111
- */
112
- USEARCH_EXPORT void usearch_free(usearch_index_t, usearch_error_t* error);
113
-
114
- /**
115
- * @brief Reports expected file size after serialization.
116
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
117
- */
118
- USEARCH_EXPORT size_t usearch_serialized_length(usearch_index_t, usearch_error_t* error);
119
-
120
- /**
121
- * @brief Saves the index to a file.
122
- * @param[in] path The file path where the index will be saved.
123
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
124
- */
125
- USEARCH_EXPORT void usearch_save(usearch_index_t, char const* path, usearch_error_t* error);
126
-
127
- /**
128
- * @brief Loads the index from a file.
129
- * @param[in] path The file path from where the index will be loaded.
130
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
131
- */
132
- USEARCH_EXPORT void usearch_load(usearch_index_t, char const* path, usearch_error_t* error);
133
-
134
- /**
135
- * @brief Creates a view of the index from a file without copying it into memory.
136
- * @param[in] path The file path from where the view will be created.
137
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
138
- */
139
- USEARCH_EXPORT void usearch_view(usearch_index_t, char const* path, usearch_error_t* error);
140
-
141
- /**
142
- * @brief Loads index metadata from a file.
143
- * @param[in] path The file path from where the index will be loaded.
144
- * @param[out] options Pointer to the `usearch_init_options_t` structure to be populated.
145
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
146
- * @return A handle to the initialized USearch index, or `NULL` on failure.
147
- */
148
- USEARCH_EXPORT void usearch_metadata(char const* path, usearch_init_options_t* options, usearch_error_t* error);
149
-
150
- /**
151
- * @brief Saves the index to an in-memory buffer.
152
- * @param[in] buffer The in-memory continuous buffer where the index will be saved.
153
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
154
- */
155
- USEARCH_EXPORT void usearch_save_buffer(usearch_index_t, void* buffer, size_t length, usearch_error_t* error);
156
-
157
- /**
158
- * @brief Loads the index from an in-memory buffer.
159
- * @param[in] buffer The in-memory continuous buffer from where the index will be loaded.
160
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
161
- */
162
- USEARCH_EXPORT void usearch_load_buffer(usearch_index_t, void const* buffer, size_t length, usearch_error_t* error);
163
-
164
- /**
165
- * @brief Creates a view of the index from an in-memory buffer without copying it into memory.
166
- * @param[in] buffer The in-memory continuous buffer from where the view will be created.
167
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
168
- */
169
- USEARCH_EXPORT void usearch_view_buffer(usearch_index_t, void const* buffer, size_t length, usearch_error_t* error);
170
-
171
- /**
172
- * @brief Loads index metadata from an in-memory buffer.
173
- * @param[in] path The file path from where the index will be loaded.
174
- * @param[out] options Pointer to the `usearch_init_options_t` structure to be populated.
175
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
176
- * @return A handle to the initialized USearch index, or `NULL` on failure.
177
- */
178
- USEARCH_EXPORT void usearch_metadata_buffer(void const* buffer, size_t length, usearch_init_options_t* options,
179
- usearch_error_t* error);
180
-
181
- USEARCH_EXPORT size_t usearch_size(usearch_index_t, usearch_error_t* error);
182
- USEARCH_EXPORT size_t usearch_capacity(usearch_index_t, usearch_error_t* error);
183
- USEARCH_EXPORT size_t usearch_dimensions(usearch_index_t, usearch_error_t* error);
184
- USEARCH_EXPORT size_t usearch_connectivity(usearch_index_t, usearch_error_t* error);
185
-
186
- /**
187
- * @brief Reserves memory for a specified number of incoming vectors.
188
- * @param[in] capacity The desired total capacity including current size.
189
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
190
- */
191
- USEARCH_EXPORT void usearch_reserve(usearch_index_t, size_t capacity, usearch_error_t* error);
192
-
193
- /**
194
- * @brief Adds a vector with a key to the index.
195
- * @param[in] key The key associated with the vector.
196
- * @param[in] vector Pointer to the vector data.
197
- * @param[in] vector_kind The scalar type used in the vector data.
198
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
199
- */
200
- USEARCH_EXPORT void usearch_add( //
201
- usearch_index_t, usearch_key_t key, //
202
- void const* vector, usearch_scalar_kind_t vector_kind, usearch_error_t* error);
203
-
204
- /**
205
- * @brief Checks if the index contains a vector with a specific key.
206
- * @param[in] key The key to be checked.
207
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
208
- * @return `true` if the index contains the vector with the given key, `false` otherwise.
209
- */
210
- USEARCH_EXPORT bool usearch_contains(usearch_index_t, usearch_key_t, usearch_error_t* error);
211
-
212
- /**
213
- * @brief Counts the number of entries in the index under a specific key.
214
- * @param[in] key The key to be checked.
215
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
216
- * @return Number of vectors found under that key.
217
- */
218
- USEARCH_EXPORT size_t usearch_count(usearch_index_t, usearch_key_t, usearch_error_t* error);
219
-
220
- /**
221
- * @brief Performs k-Approximate Nearest Neighbors (kANN) Search for closest vectors to query.
222
- * @param[in] query_vector Pointer to the query vector data.
223
- * @param[in] query_kind The scalar type used in the query vector data.
224
- * @param[in] count Upper bound on the number of neighbors to search, the "k" in "kANN".
225
- * @param[out] keys Output buffer for up to `count` nearest neighbors keys.
226
- * @param[out] distances Output buffer for up to `count` distances to nearest neighbors.
227
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
228
- * @return Number of found matches.
229
- */
230
- USEARCH_EXPORT size_t usearch_search( //
231
- usearch_index_t, //
232
- void const* query_vector, usearch_scalar_kind_t query_kind, //
233
- size_t count, usearch_key_t* keys, usearch_distance_t* distances, usearch_error_t* error);
234
-
235
- /**
236
- * @brief Retrieves the vector associated with the given key from the index.
237
- * @param[in] key The key of the vector to retrieve.
238
- * @param[out] vector Pointer to the memory where the vector data will be copied.
239
- * @param[in] count Number of vectors that can be fitted into `vector` for multi-vector entries.
240
- * @param[in] vector_kind The scalar type used in the vector data.
241
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
242
- * @return Number of vectors found under that name and exported to `vector`.
243
- */
244
- USEARCH_EXPORT size_t usearch_get( //
245
- usearch_index_t, usearch_key_t key, size_t count, //
246
- void* vector, usearch_scalar_kind_t vector_kind, usearch_error_t* error);
247
-
248
- /**
249
- * @brief Removes the vector associated with the given key from the index.
250
- * @param[in] key The key of the vector to be removed.
251
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
252
- * @return Number of vectors found under that name and dropped from the index.
253
- */
254
- USEARCH_EXPORT size_t usearch_remove(usearch_index_t, usearch_key_t key, usearch_error_t* error);
255
-
256
- /**
257
- * @brief Renames the vector to map to a different key.
258
- * @param[in] from The key of the vector to be renamed.
259
- * @param[in] to New key for found entry.
260
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
261
- * @return Number of vectors found under that name and renamed.
262
- */
263
- USEARCH_EXPORT size_t usearch_rename(usearch_index_t, usearch_key_t from, usearch_key_t to, usearch_error_t* error);
264
-
265
- /**
266
- * @brief Computes the distance between two equi-dimensional vectors.
267
- * @param[in] vector_first The first vector for comparison.
268
- * @param[in] vector_second The second vector for comparison.
269
- * @param[in] scalar_kind The scalar type used in the vectors.
270
- * @param[in] dimensions The number of dimensions in each vector.
271
- * @param[in] metric_kind The metric kind used for distance calculation between vectors.
272
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
273
- * @return Distance between given vectors.
274
- */
275
- USEARCH_EXPORT usearch_distance_t usearch_distance( //
276
- void const* vector_first, void const* vector_second, //
277
- usearch_scalar_kind_t scalar_kind, size_t dimensions, //
278
- usearch_metric_kind_t metric_kind, usearch_error_t* error);
279
-
280
- /**
281
- * @brief Multi-threaded exact nearest neighbors search for equi-dimensional vectors.
282
- * @param[in] dataset Pointer to the first scalar of the dataset matrix.
283
- * @param[in] queries Pointer to the first scalar of the queries matrix.
284
- * @param[in] dataset_size Number of vectors in the `dataset`.
285
- * @param[in] queries_size Number of vectors in the `queries` set.
286
- * @param[in] dataset_stride Number of bytes between starts of consecutive vectors in `dataset`.
287
- * @param[in] queries_stride Number of bytes between starts of consecutive vectors in `queries`.
288
- * @param[in] scalar_kind The scalar type used in the vectors.
289
- * @param[in] dimensions The number of dimensions in each vector.
290
- * @param[in] metric_kind The metric kind used for distance calculation between vectors.
291
- * @param[in] count Upper bound on the number of neighbors to search, the "k" in "kANN".
292
- * @param[in] threads Upper bound for the number of CPU threads to use.
293
- * @param[out] keys Output buffer for up to `count` nearest neighbors keys.
294
- * @param[out] distances Output buffer for up to `count` distances to nearest neighbors.
295
- * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
296
- * @return Number of found matches.
297
- */
298
- USEARCH_EXPORT void usearch_exact_search( //
299
- void const* dataset, size_t dataset_size, size_t dataset_stride, //
300
- void const* queries, size_t queries_size, size_t queries_stride, //
301
- usearch_scalar_kind_t scalar_kind, size_t dimensions, //
302
- usearch_metric_kind_t metric_kind, size_t count, size_t threads, //
303
- usearch_key_t* keys, size_t keys_stride, //
304
- usearch_distance_t* distances, size_t distances_stride, //
305
- usearch_error_t* error);
306
-
307
- #ifdef __cplusplus
308
- }
309
- #endif
310
-
311
- #endif // UNUM_USEARCH_H
package/cmake/clipp.cmake DELETED
@@ -1,7 +0,0 @@
1
- include(FetchContent)
2
- FetchContent_Declare(
3
- clipp
4
- GIT_REPOSITORY https://github.com/muellan/clipp
5
- GIT_TAG v1.2.3
6
- )
7
- FetchContent_MakeAvailable(clipp)