usearch 2.9.2 → 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 (172) hide show
  1. package/README.md +39 -38
  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} +199 -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 -361
  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 -382
  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 -2213
  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/CONTRIBUTING.md +0 -88
  111. package/simsimd/Cargo.lock +0 -709
  112. package/simsimd/Cargo.toml +0 -44
  113. package/simsimd/LICENSE +0 -201
  114. package/simsimd/README.md +0 -317
  115. package/simsimd/binding.gyp +0 -36
  116. package/simsimd/build.rs +0 -20
  117. package/simsimd/include/simsimd/binary.h +0 -245
  118. package/simsimd/include/simsimd/complex.h +0 -174
  119. package/simsimd/include/simsimd/probability.h +0 -548
  120. package/simsimd/include/simsimd/simsimd.h +0 -465
  121. package/simsimd/include/simsimd/spatial.h +0 -1267
  122. package/simsimd/include/simsimd/types.h +0 -208
  123. package/simsimd/javascript/bench.js +0 -127
  124. package/simsimd/javascript/fallback.ts +0 -193
  125. package/simsimd/javascript/lib.c +0 -102
  126. package/simsimd/javascript/node-gyp-build.d.ts +0 -1
  127. package/simsimd/javascript/simsimd.ts +0 -124
  128. package/simsimd/javascript/test.mjs +0 -153
  129. package/simsimd/javascript/tsconfig-base.json +0 -25
  130. package/simsimd/javascript/tsconfig-cjs.json +0 -8
  131. package/simsimd/javascript/tsconfig-esm.json +0 -8
  132. package/simsimd/package-lock.json +0 -1688
  133. package/simsimd/package.json +0 -61
  134. package/simsimd/rust/benches/cosine.rs +0 -27
  135. package/simsimd/rust/benches/native.rs +0 -30
  136. package/simsimd/rust/benches/sqeuclidean.rs +0 -27
  137. package/simsimd/rust/lib.c +0 -45
  138. package/simsimd/rust/lib.rs +0 -550
  139. package/sqlite/README.md +0 -178
  140. package/sqlite/lib.cpp +0 -325
  141. package/stringzilla/CONTRIBUTING.md +0 -446
  142. package/stringzilla/Cargo.lock +0 -25
  143. package/stringzilla/Cargo.toml +0 -26
  144. package/stringzilla/LICENSE +0 -201
  145. package/stringzilla/README.md +0 -1422
  146. package/stringzilla/VERSION +0 -1
  147. package/stringzilla/assets/cover-strinzilla.jpeg +0 -0
  148. package/stringzilla/assets/meme-stringzilla-v2.jpeg +0 -0
  149. package/stringzilla/assets/meme-stringzilla-v3.jpeg +0 -0
  150. package/stringzilla/binding.gyp +0 -16
  151. package/stringzilla/build.rs +0 -87
  152. package/stringzilla/c/lib.c +0 -337
  153. package/stringzilla/cli/README.md +0 -65
  154. package/stringzilla/cli/__init__.py +0 -0
  155. package/stringzilla/cli/split.py +0 -105
  156. package/stringzilla/cli/wc.py +0 -117
  157. package/stringzilla/include/stringzilla/experimental.h +0 -845
  158. package/stringzilla/include/stringzilla/module.modulemap +0 -9
  159. package/stringzilla/include/stringzilla/stringzilla.h +0 -5370
  160. package/stringzilla/include/stringzilla/stringzilla.hpp +0 -3838
  161. package/stringzilla/javascript/lib.c +0 -125
  162. package/stringzilla/javascript/stringzilla.js +0 -22
  163. package/stringzilla/package-ci.json +0 -10
  164. package/stringzilla/package.json +0 -32
  165. package/stringzilla/rust/lib.rs +0 -873
  166. package/stringzilla/swift/StringProtocol+StringZilla.swift +0 -280
  167. package/stringzilla/swift/Test.swift +0 -60
  168. package/tsconfig.json +0 -21
  169. package/wasmer.toml +0 -12
  170. package/winlibinstaller.bat +0 -42
  171. /package/{simsimd/javascript/dist-package-cjs.json → javascript/dist/cjs/package.json} +0 -0
  172. /package/{simsimd/javascript/dist-package-esm.json → javascript/dist/esm/package.json} +0 -0
package/c/test.c DELETED
@@ -1,382 +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
- opts.multi = false;
39
- return opts;
40
- }
41
-
42
- /**
43
- * This test is designed to verify the initialization of the index with specific dimensions and ensures that the
44
- * associated properties are set correctly. It initializes the index twice, checking for errors at each step, and
45
- * performs a reserve operation to pre-allocate space in the index, verifying the correct settings of size, capacity,
46
- * dimensions, and connectivity after each operation.
47
- */
48
- void test_init(size_t const collection_size, size_t const dimensions) {
49
- printf("Test: Index Initialization... %zu vectors, %zu dimensions \n", collection_size, dimensions);
50
-
51
- // Init index
52
- usearch_error_t error = NULL;
53
- usearch_init_options_t opts = create_options(dimensions);
54
- usearch_index_t index = usearch_init(&opts, &error);
55
- ASSERT(!error, error);
56
- usearch_free(index, &error);
57
- ASSERT(!error, error);
58
-
59
- // Init second time
60
- index = usearch_init(&opts, &error);
61
- ASSERT(!error, error);
62
-
63
- ASSERT(usearch_size(index, &error) == 0, error);
64
- ASSERT(usearch_capacity(index, &error) == 0, error);
65
- ASSERT(usearch_dimensions(index, &error) == dimensions, error);
66
- ASSERT(usearch_connectivity(index, &error) == opts.connectivity, error);
67
-
68
- // Reserve
69
- usearch_reserve(index, collection_size, &error);
70
- ASSERT(!error, error);
71
- ASSERT(usearch_size(index, &error) == 0, error);
72
- ASSERT(usearch_capacity(index, &error) == collection_size, error);
73
- ASSERT(usearch_dimensions(index, &error) == dimensions, error);
74
- ASSERT(usearch_connectivity(index, &error) == opts.connectivity, error);
75
-
76
- usearch_free(index, &error);
77
- ASSERT(!error, error);
78
-
79
- printf("Test: Index Initialization - PASSED\n");
80
- }
81
-
82
- /**
83
- * This test validates the addition of vectors to the index. It initializes the index and reserves space for vectors.
84
- * It then iteratively adds vectors to the index and checks if the index contains the added vectors by verifying the
85
- * size, capacity, and presence of each vector in the index.
86
- */
87
- void test_add_vector(size_t const collection_size, size_t const dimensions) {
88
- printf("Test: Add Vector... %zu vectors, %zu dimensions \n", collection_size, dimensions);
89
-
90
- usearch_error_t error = NULL;
91
- usearch_init_options_t opts = create_options(dimensions);
92
- usearch_index_t index = usearch_init(&opts, &error);
93
- usearch_reserve(index, collection_size, &error);
94
-
95
- // Add vectors
96
- float* data = create_vectors(collection_size, dimensions);
97
- for (size_t i = 0; i < collection_size; ++i) {
98
- usearch_key_t key = i;
99
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
100
- ASSERT(!error, error);
101
- }
102
-
103
- ASSERT(usearch_size(index, &error) == collection_size, error);
104
- ASSERT(usearch_capacity(index, &error) == collection_size, error);
105
-
106
- // Check vectors in the index
107
- for (size_t i = 0; i < collection_size; ++i) {
108
- usearch_key_t key = i;
109
- ASSERT(usearch_contains(index, key, &error), error);
110
- }
111
- ASSERT(!usearch_contains(index, -1, &error), error); // Non existing key
112
-
113
- free(data);
114
- usearch_free(index, &error);
115
- printf("Test: Add Vector - PASSED\n");
116
- }
117
-
118
- /**
119
- * This test ensures that vectors added to the index can be correctly found. It initializes the index, reserves space,
120
- * and adds vectors. It then performs a search query for each added vector to ensure that the vectors are correctly
121
- * found in the index, validating the count of found vectors.
122
- */
123
- void test_find_vector(size_t const collection_size, size_t const dimensions) {
124
- printf("Test: Find Vector... %zu vectors, %zu dimensions \n", collection_size, dimensions);
125
-
126
- usearch_error_t error = NULL;
127
- usearch_init_options_t opts = create_options(dimensions);
128
- usearch_index_t index = usearch_init(&opts, &error);
129
- usearch_reserve(index, collection_size, &error);
130
-
131
- // Create result buffers
132
- usearch_key_t* keys = (usearch_key_t*)malloc(collection_size * sizeof(usearch_key_t));
133
- float* distances = (float*)malloc(collection_size * sizeof(float));
134
- ASSERT(keys && distances, "Failed to allocate memory");
135
-
136
- // Add vectors
137
- float* data = create_vectors(collection_size, dimensions);
138
- for (size_t i = 0; i < collection_size; ++i) {
139
- usearch_key_t key = i;
140
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
141
- ASSERT(!error, error);
142
- }
143
-
144
- // Find the vectors
145
- for (size_t i = 0; i < collection_size; i++) {
146
- size_t found_count = usearch_search(index, data + i * dimensions, usearch_scalar_f32_k, collection_size, keys,
147
- distances, &error);
148
- ASSERT(!error, error);
149
- ASSERT(found_count >= 1 && found_count <= collection_size, "Vector is missing");
150
- }
151
-
152
- free(data);
153
- free(keys);
154
- free(distances);
155
- usearch_free(index, &error);
156
- printf("Test: Find Vector - PASSED\n");
157
- }
158
-
159
- /**
160
- * This test checks the ability of the index to handle multiple vectors associated with the same key. It initializes
161
- * the index with the multi-option enabled, reserves space, and adds multiple vectors with the same key. The test then
162
- * retrieves vectors associated with the key from the index and checks the count of retrieved vectors.
163
- */
164
- void test_get_vector(size_t const collection_size, size_t const dimensions) {
165
- printf("Test: Get Vector... %zu vectors, %zu dimensions \n", collection_size, dimensions);
166
-
167
- usearch_error_t error = NULL;
168
- usearch_init_options_t opts = create_options(dimensions);
169
- opts.multi = true;
170
- usearch_index_t index = usearch_init(&opts, &error);
171
- usearch_reserve(index, collection_size, &error);
172
-
173
- // Create result buffers
174
- float* vectors = (float*)malloc(collection_size * dimensions * sizeof(float));
175
- ASSERT(vectors, "Failed to allocate memory");
176
-
177
- // Add multiple vectors with SAME key
178
- usearch_key_t const key = 1;
179
- float* data = create_vectors(collection_size, dimensions);
180
- for (size_t i = 0; i < collection_size; i++) {
181
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
182
- ASSERT(!error, error);
183
- }
184
-
185
- // Retrieve vectors from index
186
- size_t found_count = usearch_get(index, key, collection_size, vectors, usearch_scalar_f32_k, &error);
187
- ASSERT(found_count == collection_size, "Vector is missing");
188
-
189
- free(vectors);
190
- free(data);
191
- usearch_free(index, &error);
192
-
193
- printf("Test: Get Vector - PASSED\n");
194
- }
195
-
196
- /**
197
- * This test ensures that vectors can be successfully removed from the index. It initializes the index, reserves space,
198
- * and adds vectors. It then iteratively removes each vector from the index and checks for errors. However, note that
199
- * the assert in this test expects an error, indicating that the remove functionality is not currently supported.
200
- */
201
- void test_remove_vector(size_t const collection_size, size_t const dimensions) {
202
- printf("Test: Remove Vector... %zu vectors, %zu dimensions \n", collection_size, dimensions);
203
-
204
- usearch_error_t error = NULL;
205
- usearch_init_options_t opts = create_options(dimensions);
206
- usearch_index_t index = usearch_init(&opts, &error);
207
- usearch_reserve(index, collection_size, &error);
208
-
209
- // Add vectors
210
- float* data = create_vectors(collection_size, dimensions);
211
- for (size_t i = 0; i < collection_size; ++i) {
212
- usearch_key_t key = i;
213
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
214
- ASSERT(!error, error);
215
- }
216
-
217
- // Remove the vectors
218
- for (size_t i = 0; i < collection_size; i++) {
219
- usearch_key_t key = i;
220
- usearch_remove(index, key, &error);
221
- ASSERT(!error, "Currently, Remove is not supported");
222
- }
223
-
224
- free(data);
225
- usearch_free(index, &error);
226
- printf("Test: Remove Vector - PASSED\n");
227
- }
228
-
229
- /**
230
- * This test validates the save and load functionality of the index. It initializes the index, reserves space, and adds
231
- * vectors. The index is then saved to a file and freed. A new index is initialized, and the previously saved index is
232
- * loaded into it. The test then validates the loaded index properties and ensures that it contains all the vectors
233
- * from the saved index.
234
- */
235
- void test_save_load(size_t const collection_size, size_t const dimensions) {
236
- printf("Test: Save/Load... %zu vectors, %zu dimensions \n", collection_size, dimensions);
237
- float* data = create_vectors(collection_size, dimensions);
238
-
239
- usearch_error_t error = NULL;
240
- usearch_init_options_t opts = create_options(dimensions);
241
- usearch_init_options_t weird_ops = opts;
242
- weird_ops.connectivity = 11;
243
- weird_ops.expansion_add = 15;
244
- weird_ops.expansion_search = 19;
245
- weird_ops.metric_kind = usearch_metric_pearson_k;
246
- weird_ops.quantization = usearch_scalar_f64_k;
247
-
248
- {
249
-
250
- usearch_index_t index = usearch_init(&weird_ops, &error);
251
- usearch_reserve(index, collection_size, &error);
252
-
253
- // Add vectors
254
- for (size_t i = 0; i < collection_size; ++i) {
255
- usearch_key_t key = i;
256
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
257
- ASSERT(!error, error);
258
- }
259
-
260
- // Save and free the index
261
- usearch_save(index, "tmp.usearch", &error);
262
- ASSERT(!error, error);
263
- usearch_free(index, &error);
264
- ASSERT(!error, error);
265
- }
266
-
267
- // Reset the options
268
- opts.connectivity = 0;
269
- opts.dimensions = 0;
270
- opts.expansion_add = 0;
271
- opts.expansion_search = 0;
272
- opts.metric = NULL;
273
- opts.quantization = usearch_scalar_unknown_k;
274
- opts.metric_kind = usearch_metric_unknown_k;
275
-
276
- // Reinit
277
- {
278
-
279
- usearch_index_t index = usearch_init(&opts, &error);
280
- ASSERT(!error, error);
281
- ASSERT(usearch_size(index, &error) == 0, error);
282
-
283
- // Load
284
- usearch_load(index, "tmp.usearch", &error);
285
- ASSERT(!error, error);
286
- ASSERT(usearch_size(index, &error) == collection_size, error);
287
- ASSERT(usearch_capacity(index, &error) == collection_size, error);
288
- ASSERT(usearch_dimensions(index, &error) == dimensions, error);
289
- ASSERT(usearch_connectivity(index, &error) == weird_ops.connectivity, error);
290
-
291
- // Check vectors in the index
292
- for (size_t i = 0; i < collection_size; ++i) {
293
- usearch_key_t key = i;
294
- ASSERT(usearch_contains(index, key, &error), error);
295
- }
296
-
297
- // Create result buffers
298
- usearch_key_t* keys = (usearch_key_t*)malloc(collection_size * sizeof(usearch_key_t));
299
- float* distances = (float*)malloc(collection_size * sizeof(float));
300
- ASSERT(keys && distances, "Failed to allocate memory");
301
-
302
- // Find the vectors
303
- for (size_t i = 0; i < collection_size; i++) {
304
- size_t found_count = usearch_search(index, data + i * dimensions, usearch_scalar_f32_k, collection_size,
305
- keys, distances, &error);
306
- ASSERT(!error, error);
307
- ASSERT(found_count >= 1 && found_count <= collection_size, "Vector is missing");
308
- }
309
-
310
- free(keys);
311
- free(distances);
312
- usearch_free(index, &error);
313
- }
314
-
315
- free(data);
316
-
317
- // Remove the file from disk
318
- remove("tmp.usearch");
319
- printf("Test: Save/Load - PASSED\n");
320
- }
321
-
322
- /**
323
- * This test is designed to validate the view functionality of the index. It initializes the index, reserves space, and
324
- * adds vectors. The index is then saved to a file and freed. A new index is initialized and a view is created from the
325
- * saved index file. The test is mainly focused on ensuring that no errors occur during these operations, but it does
326
- * not verify the properties or contents of the viewed index.
327
- */
328
- void test_view(size_t const collection_size, size_t const dimensions) {
329
- printf("Test: View... %zu vectors, %zu dimensions \n", collection_size, dimensions);
330
-
331
- usearch_error_t error = NULL;
332
- usearch_init_options_t opts = create_options(dimensions);
333
- usearch_index_t index = usearch_init(&opts, &error);
334
- usearch_reserve(index, collection_size, &error);
335
-
336
- // Add vectors
337
- float* data = create_vectors(collection_size, dimensions);
338
- for (size_t i = 0; i < collection_size; ++i) {
339
- usearch_key_t key = i;
340
- usearch_add(index, key, data + i * dimensions, usearch_scalar_f32_k, &error);
341
- ASSERT(!error, error);
342
- }
343
-
344
- // Save and free the index
345
- usearch_save(index, "tmp.usearch", &error);
346
- ASSERT(!error, error);
347
- usearch_free(index, &error);
348
- ASSERT(!error, error);
349
-
350
- // Reinit
351
- index = usearch_init(&opts, &error);
352
- ASSERT(!error, error);
353
-
354
- // View
355
- usearch_view(index, "tmp.usearch", &error);
356
- ASSERT(!error, error);
357
-
358
- free(data);
359
- usearch_free(index, &error);
360
- printf("Test: View - PASSED\n");
361
- }
362
-
363
- int main(int argc, char const* argv[]) {
364
-
365
- size_t collection_sizes[] = {11, 512};
366
- size_t dimensions[] = {83, 2}; // Not all distance functions make sense for 1 dimensional data
367
- for (size_t index = 0; index < sizeof(collection_sizes) / sizeof(collection_sizes[0]); ++index) {
368
- for (size_t jdx = 0; jdx < sizeof(dimensions) / sizeof(dimensions[0]); ++jdx) {
369
- test_init(collection_sizes[index], dimensions[jdx]);
370
- test_add_vector(collection_sizes[index], dimensions[jdx]);
371
- test_find_vector(collection_sizes[index], dimensions[jdx]);
372
- test_get_vector(collection_sizes[index], dimensions[jdx]);
373
- test_remove_vector(collection_sizes[index], dimensions[jdx]);
374
- test_save_load(collection_sizes[index], dimensions[jdx]);
375
- test_view(collection_sizes[index], dimensions[jdx]);
376
- }
377
- }
378
-
379
- (void)argc;
380
- (void)argv;
381
- return 0;
382
- }
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