usearch 2.10.3 → 2.11.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 (114) hide show
  1. package/README.md +28 -8
  2. package/binding.gyp +101 -0
  3. package/c/CMakeLists.txt +27 -0
  4. package/c/README.md +244 -0
  5. package/c/lib.cpp +459 -0
  6. package/c/test.c +386 -0
  7. package/c/usearch.h +451 -0
  8. package/cmake/clipp.cmake +7 -0
  9. package/cmake/config.cmake.in +15 -0
  10. package/cmake/emscripten.cmake +8 -0
  11. package/cmake/jemalloc.cmake +62 -0
  12. package/cmake/pkg-config.pc.in +4 -0
  13. package/cmake/usearchConfigVersion.cmake.in +20 -0
  14. package/cpp/CMakeLists.txt +14 -0
  15. package/cpp/README.md +161 -0
  16. package/cpp/bench.cpp +616 -0
  17. package/cpp/test.cpp +335 -0
  18. package/fp16/CMakeLists.txt +176 -0
  19. package/fp16/LICENSE +11 -0
  20. package/fp16/README.md +20 -0
  21. package/fp16/bench/alt-element.cc +89 -0
  22. package/fp16/bench/from-alt-array.cc +175 -0
  23. package/fp16/bench/from-ieee-array.cc +399 -0
  24. package/fp16/bench/ieee-element.cc +272 -0
  25. package/fp16/bench/to-alt-array.cc +91 -0
  26. package/fp16/bench/to-ieee-array.cc +303 -0
  27. package/fp16/cmake/DownloadGoogleBenchmark.cmake +15 -0
  28. package/fp16/cmake/DownloadGoogleTest.cmake +15 -0
  29. package/fp16/cmake/DownloadPSimd.cmake +15 -0
  30. package/fp16/configure.py +65 -0
  31. package/fp16/confu.yaml +8 -0
  32. package/fp16/include/fp16/__init__.py +0 -0
  33. package/fp16/include/fp16/avx.py +50 -0
  34. package/fp16/include/fp16/avx2.py +53 -0
  35. package/fp16/include/fp16/bitcasts.h +92 -0
  36. package/fp16/include/fp16/fp16.h +451 -0
  37. package/fp16/include/fp16/psimd.h +131 -0
  38. package/fp16/include/fp16.h +11 -0
  39. package/fp16/jni/Android.mk +6 -0
  40. package/fp16/jni/Application.mk +4 -0
  41. package/fp16/test/alt-from-fp32-value.cc +498 -0
  42. package/fp16/test/alt-to-fp32-bits.cc +263 -0
  43. package/fp16/test/alt-to-fp32-psimd.cc +145 -0
  44. package/fp16/test/alt-to-fp32-value.cc +348 -0
  45. package/fp16/test/alt-to-fp32x2-psimd.cc +245 -0
  46. package/fp16/test/bitcasts.cc +56 -0
  47. package/fp16/test/ieee-from-fp32-value.cc +523 -0
  48. package/fp16/test/ieee-to-fp32-bits.cc +333 -0
  49. package/fp16/test/ieee-to-fp32-psimd.cc +312 -0
  50. package/fp16/test/ieee-to-fp32-value.cc +420 -0
  51. package/fp16/test/ieee-to-fp32x2-psimd.cc +541 -0
  52. package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +96 -0
  53. package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +96 -0
  54. package/fp16/test/peachpy/stubs.py +38 -0
  55. package/fp16/test/tables.cc +530 -0
  56. package/fp16/test/tables.h +13 -0
  57. package/fp16/third-party/THHalf.h +92 -0
  58. package/fp16/third-party/eigen-half.h +170 -0
  59. package/fp16/third-party/float16-compressor.h +80 -0
  60. package/fp16/third-party/half.hpp +2916 -0
  61. package/fp16/third-party/npy-halffloat.h +328 -0
  62. package/include/usearch/index.hpp +3838 -0
  63. package/include/usearch/index_dense.hpp +2022 -0
  64. package/include/usearch/index_plugins.hpp +2317 -0
  65. package/javascript/dist/cjs/usearch.js +5 -5
  66. package/javascript/dist/esm/usearch.js +2 -2
  67. package/javascript/dist-package-cjs.json +3 -0
  68. package/javascript/dist-package-esm.json +3 -0
  69. package/javascript/lib.cpp +350 -0
  70. package/javascript/node-gyp-build.d.ts +1 -0
  71. package/javascript/tsconfig-base.json +25 -0
  72. package/javascript/tsconfig-cjs.json +8 -0
  73. package/javascript/tsconfig-esm.json +8 -0
  74. package/javascript/usearch.test.js +84 -0
  75. package/javascript/usearch.ts +640 -0
  76. package/package.json +14 -7
  77. package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
  78. package/prebuilds/linux-arm64/usearch.node +0 -0
  79. package/prebuilds/linux-x64/usearch.node +0 -0
  80. package/prebuilds/win32-ia32/usearch.node +0 -0
  81. package/prebuilds/win32-x64/usearch.node +0 -0
  82. package/simsimd/.releaserc +87 -0
  83. package/simsimd/CONTRIBUTING.md +114 -0
  84. package/simsimd/Cargo.lock +709 -0
  85. package/simsimd/Cargo.toml +44 -0
  86. package/simsimd/LICENSE +201 -0
  87. package/simsimd/README.md +708 -0
  88. package/simsimd/binding.gyp +36 -0
  89. package/simsimd/build.rs +51 -0
  90. package/simsimd/c/lib.c +110 -0
  91. package/simsimd/include/simsimd/binary.h +258 -0
  92. package/simsimd/include/simsimd/dot.h +1237 -0
  93. package/simsimd/include/simsimd/geospatial.h +37 -0
  94. package/simsimd/include/simsimd/probability.h +563 -0
  95. package/simsimd/include/simsimd/simsimd.h +1129 -0
  96. package/simsimd/include/simsimd/spatial.h +1019 -0
  97. package/simsimd/include/simsimd/types.h +309 -0
  98. package/simsimd/javascript/bench.js +127 -0
  99. package/simsimd/javascript/dist-package-cjs.json +3 -0
  100. package/simsimd/javascript/dist-package-esm.json +3 -0
  101. package/simsimd/javascript/fallback.ts +203 -0
  102. package/simsimd/javascript/lib.c +107 -0
  103. package/simsimd/javascript/node-gyp-build.d.ts +1 -0
  104. package/simsimd/javascript/simsimd.ts +135 -0
  105. package/simsimd/javascript/test.mjs +179 -0
  106. package/simsimd/javascript/tsconfig-base.json +37 -0
  107. package/simsimd/javascript/tsconfig-cjs.json +8 -0
  108. package/simsimd/javascript/tsconfig-esm.json +8 -0
  109. package/simsimd/package-lock.json +1709 -0
  110. package/simsimd/package.json +61 -0
  111. package/simsimd/rust/benches/cosine.rs +27 -0
  112. package/simsimd/rust/benches/native.rs +30 -0
  113. package/simsimd/rust/benches/sqeuclidean.rs +27 -0
  114. package/simsimd/rust/lib.rs +778 -0
package/c/usearch.h ADDED
@@ -0,0 +1,451 @@
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 Retrieves the version of the library.
102
+ * @return The version of the library.
103
+ */
104
+ USEARCH_EXPORT char const* usearch_version(void);
105
+
106
+ /**
107
+ * @brief Initializes a new instance of the index.
108
+ * @param options Pointer to the `usearch_init_options_t` structure containing initialization options.
109
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
110
+ * @return A handle to the initialized USearch index, or `NULL` on failure.
111
+ */
112
+ USEARCH_EXPORT usearch_index_t usearch_init(usearch_init_options_t* options, usearch_error_t* error);
113
+
114
+ /**
115
+ * @brief Frees the resources associated with the index.
116
+ * @param[inout] index The handle to the USearch index to be freed.
117
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
118
+ */
119
+ USEARCH_EXPORT void usearch_free(usearch_index_t index, usearch_error_t* error);
120
+
121
+ /**
122
+ * @brief Reports the memory usage of the index.
123
+ * @param[in] index The handle to the USearch index to be queried.
124
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
125
+ * @return Number of bytes used by the index.
126
+ */
127
+ USEARCH_EXPORT size_t usearch_memory_usage(usearch_index_t index, usearch_error_t* error);
128
+
129
+ /**
130
+ * @brief Reports the SIMD capabilities used by the index on the current CPU.
131
+ * @param[in] index The handle to the USearch index to be queried.
132
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
133
+ * @return The codename of the SIMD instruction set used by the index.
134
+ */
135
+ USEARCH_EXPORT char const* usearch_hardware_acceleration(usearch_index_t index, usearch_error_t* error);
136
+
137
+ /**
138
+ * @brief Reports expected file size after serialization.
139
+ * @param[in] index The handle to the USearch index to be serialized.
140
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
141
+ */
142
+ USEARCH_EXPORT size_t usearch_serialized_length(usearch_index_t index, usearch_error_t* error);
143
+
144
+ /**
145
+ * @brief Saves the index to a file.
146
+ * @param[in] index The handle to the USearch index to be serialized.
147
+ * @param[in] path The file path where the index will be saved.
148
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
149
+ */
150
+ USEARCH_EXPORT void usearch_save(usearch_index_t index, char const* path, usearch_error_t* error);
151
+
152
+ /**
153
+ * @brief Loads the index from a file.
154
+ * @param[inout] index The handle to the USearch index to be populated from path.
155
+ * @param[in] path The file path from where the index will be loaded.
156
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
157
+ */
158
+ USEARCH_EXPORT void usearch_load(usearch_index_t index, char const* path, usearch_error_t* error);
159
+
160
+ /**
161
+ * @brief Creates a view of the index from a file without copying it into memory.
162
+ * @param[inout] index The handle to the USearch index to be populated with a file view.
163
+ * @param[in] path The file path from where the view will be created.
164
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
165
+ */
166
+ USEARCH_EXPORT void usearch_view(usearch_index_t index, char const* path, usearch_error_t* error);
167
+
168
+ /**
169
+ * @brief Loads index metadata from a file.
170
+ * @param[in] path The file path from where the index will be loaded.
171
+ * @param[out] options Pointer to the `usearch_init_options_t` structure to be populated.
172
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
173
+ * @return A handle to the initialized USearch index, or `NULL` on failure.
174
+ */
175
+ USEARCH_EXPORT void usearch_metadata(char const* path, usearch_init_options_t* options, usearch_error_t* error);
176
+
177
+ /**
178
+ * @brief Saves the index to an in-memory buffer.
179
+ * @param[in] index The handle to the USearch index to be serialized.
180
+ * @param[in] buffer The in-memory continuous buffer where the index will be saved.
181
+ * @param[in] length The length of the buffer in bytes.
182
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
183
+ */
184
+ USEARCH_EXPORT void usearch_save_buffer(usearch_index_t index, void* buffer, size_t length, usearch_error_t* error);
185
+
186
+ /**
187
+ * @brief Loads the index from an in-memory buffer.
188
+ * @param[inout] index The handle to the USearch index to be populated from buffer.
189
+ * @param[in] buffer The in-memory continuous buffer from where the index will be loaded.
190
+ * @param[in] length The length of the buffer in bytes.
191
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
192
+ */
193
+ USEARCH_EXPORT void usearch_load_buffer(usearch_index_t index, void const* buffer, size_t length,
194
+ usearch_error_t* error);
195
+
196
+ /**
197
+ * @brief Creates a view of the index from an in-memory buffer without copying it into memory.
198
+ * @param[inout] index The handle to the USearch index to be populated with a buffer view.
199
+ * @param[in] buffer The in-memory continuous buffer from where the view will be created.
200
+ * @param[in] length The length of the buffer in bytes.
201
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
202
+ */
203
+ USEARCH_EXPORT void usearch_view_buffer(usearch_index_t index, void const* buffer, size_t length,
204
+ usearch_error_t* error);
205
+
206
+ /**
207
+ * @brief Loads index metadata from an in-memory buffer.
208
+ * @param[in] buffer The in-memory continuous buffer from where the view will be created.
209
+ * @param[out] options Pointer to the `usearch_init_options_t` structure to be populated.
210
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
211
+ * @return A handle to the initialized USearch index, or `NULL` on failure.
212
+ */
213
+ USEARCH_EXPORT void usearch_metadata_buffer(void const* buffer, size_t length, usearch_init_options_t* options,
214
+ usearch_error_t* error);
215
+
216
+ /**
217
+ * @brief Reports the current size (number of vectors) of the index.
218
+ * @param[in] index The handle to the USearch index to be queried.
219
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
220
+ */
221
+ USEARCH_EXPORT size_t usearch_size(usearch_index_t index, usearch_error_t* error);
222
+
223
+ /**
224
+ * @brief Reports the current capacity (number of vectors) of the index.
225
+ * @param[in] index The handle to the USearch index to be queried.
226
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
227
+ */
228
+ USEARCH_EXPORT size_t usearch_capacity(usearch_index_t index, usearch_error_t* error);
229
+
230
+ /**
231
+ * @brief Reports the current dimensions of the vectors in the index.
232
+ * @param[in] index The handle to the USearch index to be queried.
233
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
234
+ */
235
+ USEARCH_EXPORT size_t usearch_dimensions(usearch_index_t index, usearch_error_t* error);
236
+
237
+ /**
238
+ * @brief Reports the current connectivity of the index.
239
+ * @param[in] index The handle to the USearch index to be queried.
240
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
241
+ */
242
+ USEARCH_EXPORT size_t usearch_connectivity(usearch_index_t index, usearch_error_t* error);
243
+
244
+ /**
245
+ * @brief Reserves memory for a specified number of incoming vectors.
246
+ * @param[inout] index The handle to the USearch index to be resized.
247
+ * @param[in] capacity The desired total capacity including current size.
248
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
249
+ */
250
+ USEARCH_EXPORT void usearch_reserve(usearch_index_t index, size_t capacity, usearch_error_t* error);
251
+
252
+ /**
253
+ * @brief Retrieves the expansion value used during index creation.
254
+ * @param[in] index The handle to the USearch index to be queried.
255
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
256
+ * @return The expansion value used during index creation.
257
+ */
258
+ USEARCH_EXPORT size_t usearch_expansion_add(usearch_index_t index, usearch_error_t* error);
259
+
260
+ /**
261
+ * @brief Retrieves the expansion value used during search.
262
+ * @param[in] index The handle to the USearch index to be queried.
263
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
264
+ * @return The expansion value used during search.
265
+ */
266
+ USEARCH_EXPORT size_t usearch_expansion_search(usearch_index_t index, usearch_error_t* error);
267
+
268
+ /**
269
+ * @brief Updates the expansion value used during index creation. Rarely used.
270
+ * @param[in] index The handle to the USearch index to be queried.
271
+ * @param[in] expansion The new expansion value.
272
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
273
+ */
274
+ USEARCH_EXPORT void usearch_change_expansion_add(usearch_index_t index, size_t expansion, usearch_error_t* error);
275
+
276
+ /**
277
+ * @brief Updates the expansion value used during search. Rarely used.
278
+ * @param[in] index The handle to the USearch index to be queried.
279
+ * @param[in] expansion The new expansion value.
280
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
281
+ */
282
+ USEARCH_EXPORT void usearch_change_expansion_search(usearch_index_t index, size_t expansion, usearch_error_t* error);
283
+
284
+ /**
285
+ * @brief Updates the metric kind used for distance calculation between vectors.
286
+ * @param[in] index The handle to the USearch index to be queried.
287
+ * @param[in] kind The metric kind used for distance calculation between vectors.
288
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
289
+ */
290
+ USEARCH_EXPORT void usearch_change_metric_kind(usearch_index_t index, usearch_metric_kind_t kind,
291
+ usearch_error_t* error);
292
+
293
+ /**
294
+ * @brief Updates the custom metric function used for distance calculation between vectors.
295
+ * @param[in] index The handle to the USearch index to be queried.
296
+ * @param[in] metric The custom metric function used for distance calculation between vectors.
297
+ * @param[in] state The @b optional state pointer to be passed to the custom metric function.
298
+ * @param[in] kind The metric kind used for distance calculation between vectors. Needed for serialization.
299
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
300
+ */
301
+ USEARCH_EXPORT void usearch_change_metric(usearch_index_t index, usearch_metric_t metric, void* state,
302
+ usearch_metric_kind_t kind, usearch_error_t* error);
303
+
304
+ /**
305
+ * @brief Adds a vector with a key to the index.
306
+ * @param[inout] index The handle to the USearch index to be populated.
307
+ * @param[in] key The key associated with the vector.
308
+ * @param[in] vector Pointer to the vector data.
309
+ * @param[in] vector_kind The scalar type used in the vector data.
310
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
311
+ */
312
+ USEARCH_EXPORT void usearch_add( //
313
+ usearch_index_t index, usearch_key_t key, //
314
+ void const* vector, usearch_scalar_kind_t vector_kind, usearch_error_t* error);
315
+
316
+ /**
317
+ * @brief Checks if the index contains a vector with a specific key.
318
+ * @param[in] index The handle to the USearch index to be queried.
319
+ * @param[in] key The key to be checked.
320
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
321
+ * @return `true` if the index contains the vector with the given key, `false` otherwise.
322
+ */
323
+ USEARCH_EXPORT bool usearch_contains(usearch_index_t index, usearch_key_t key, usearch_error_t* error);
324
+
325
+ /**
326
+ * @brief Counts the number of entries in the index under a specific key.
327
+ * @param[in] index The handle to the USearch index to be queried.
328
+ * @param[in] key The key to be checked.
329
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
330
+ * @return Number of vectors found under that key.
331
+ */
332
+ USEARCH_EXPORT size_t usearch_count(usearch_index_t index, usearch_key_t, usearch_error_t* error);
333
+
334
+ /**
335
+ * @brief Performs k-Approximate Nearest Neighbors (kANN) Search for closest vectors to query.
336
+ * @param[in] index The handle to the USearch index to be queried.
337
+ * @param[in] query_vector Pointer to the query vector data.
338
+ * @param[in] query_kind The scalar type used in the query vector data.
339
+ * @param[in] count Upper bound on the number of neighbors to search, the "k" in "kANN".
340
+ * @param[out] keys Output buffer for up to `count` nearest neighbors keys.
341
+ * @param[out] distances Output buffer for up to `count` distances to nearest neighbors.
342
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
343
+ * @return Number of found matches.
344
+ */
345
+ USEARCH_EXPORT size_t usearch_search( //
346
+ usearch_index_t index, //
347
+ void const* query_vector, usearch_scalar_kind_t query_kind, size_t count, //
348
+ usearch_key_t* keys, usearch_distance_t* distances, usearch_error_t* error);
349
+
350
+ /**
351
+ * @brief Performs k-Approximate Nearest Neighbors (kANN) Search for closest vectors to query,
352
+ * predicated on a custom function that returns `true` for vectors to be included.
353
+ *
354
+ * @param[in] index The handle to the USearch index to be queried.
355
+ * @param[in] query_vector Pointer to the query vector data.
356
+ * @param[in] query_kind The scalar type used in the query vector data.
357
+ * @param[in] count Upper bound on the number of neighbors to search, the "k" in "kANN".
358
+ * @param[in] filter The custom filter function that returns `true` for vectors to be included.
359
+ * @param[in] filter_state The @b optional state pointer to be passed to the custom filter function.
360
+ * @param[out] keys Output buffer for up to `count` nearest neighbors keys.
361
+ * @param[out] distances Output buffer for up to `count` distances to nearest neighbors.
362
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
363
+ * @return Number of found matches.
364
+ */
365
+ USEARCH_EXPORT size_t usearch_filtered_search( //
366
+ usearch_index_t index, //
367
+ void const* query_vector, usearch_scalar_kind_t query_kind, size_t count, //
368
+ int (*filter)(usearch_key_t key, void* filter_state), void* filter_state, //
369
+ usearch_key_t* keys, usearch_distance_t* distances, usearch_error_t* error);
370
+
371
+ /**
372
+ * @brief Retrieves the vector associated with the given key from the index.
373
+ * @param[in] index The handle to the USearch index to be queried.
374
+ * @param[in] key The key of the vector to retrieve.
375
+ * @param[out] vector Pointer to the memory where the vector data will be copied.
376
+ * @param[in] count Number of vectors that can be fitted into `vector` for multi-vector entries.
377
+ * @param[in] vector_kind The scalar type used in the vector data.
378
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
379
+ * @return Number of vectors found under that name and exported to `vector`.
380
+ */
381
+ USEARCH_EXPORT size_t usearch_get( //
382
+ usearch_index_t index, usearch_key_t key, size_t count, //
383
+ void* vector, usearch_scalar_kind_t vector_kind, usearch_error_t* error);
384
+
385
+ /**
386
+ * @brief Removes the vector associated with the given key from the index.
387
+ * @param[inout] index The handle to the USearch index to be modified.
388
+ * @param[in] key The key of the vector to be removed.
389
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
390
+ * @return Number of vectors found under that name and dropped from the index.
391
+ */
392
+ USEARCH_EXPORT size_t usearch_remove(usearch_index_t index, usearch_key_t key, usearch_error_t* error);
393
+
394
+ /**
395
+ * @brief Renames the vector to map to a different key.
396
+ * @param[inout] index The handle to the USearch index to be modified.
397
+ * @param[in] from The key of the vector to be renamed.
398
+ * @param[in] to New key for found entry.
399
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
400
+ * @return Number of vectors found under that name and renamed.
401
+ */
402
+ USEARCH_EXPORT size_t usearch_rename(usearch_index_t index, usearch_key_t from, usearch_key_t to,
403
+ usearch_error_t* error);
404
+
405
+ /**
406
+ * @brief Computes the distance between two equi-dimensional vectors.
407
+ * @param[in] vector_first The first vector for comparison.
408
+ * @param[in] vector_second The second vector for comparison.
409
+ * @param[in] scalar_kind The scalar type used in the vectors.
410
+ * @param[in] dimensions The number of dimensions in each vector.
411
+ * @param[in] metric_kind The metric kind used for distance calculation between vectors.
412
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
413
+ * @return Distance between given vectors.
414
+ */
415
+ USEARCH_EXPORT usearch_distance_t usearch_distance( //
416
+ void const* vector_first, void const* vector_second, //
417
+ usearch_scalar_kind_t scalar_kind, size_t dimensions, //
418
+ usearch_metric_kind_t metric_kind, usearch_error_t* error);
419
+
420
+ /**
421
+ * @brief Multi-threaded exact nearest neighbors search for equi-dimensional vectors.
422
+ * @param[in] dataset Pointer to the first scalar of the dataset matrix.
423
+ * @param[in] queries Pointer to the first scalar of the queries matrix.
424
+ * @param[in] dataset_size Number of vectors in the `dataset`.
425
+ * @param[in] queries_size Number of vectors in the `queries` set.
426
+ * @param[in] dataset_stride Number of bytes between starts of consecutive vectors in `dataset`.
427
+ * @param[in] queries_stride Number of bytes between starts of consecutive vectors in `queries`.
428
+ * @param[in] scalar_kind The scalar type used in the vectors.
429
+ * @param[in] dimensions The number of dimensions in each vector.
430
+ * @param[in] metric_kind The metric kind used for distance calculation between vectors.
431
+ * @param[in] count Upper bound on the number of neighbors to search, the "k" in "kANN".
432
+ * @param[in] threads Upper bound for the number of CPU threads to use.
433
+ * @param[out] keys Output buffer for up to `count` nearest neighbors keys.
434
+ * @param[out] distances Output buffer for up to `count` distances to nearest neighbors.
435
+ * @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
436
+ * @return Number of found matches.
437
+ */
438
+ USEARCH_EXPORT void usearch_exact_search( //
439
+ void const* dataset, size_t dataset_size, size_t dataset_stride, //
440
+ void const* queries, size_t queries_size, size_t queries_stride, //
441
+ usearch_scalar_kind_t scalar_kind, size_t dimensions, //
442
+ usearch_metric_kind_t metric_kind, size_t count, size_t threads, //
443
+ usearch_key_t* keys, size_t keys_stride, //
444
+ usearch_distance_t* distances, size_t distances_stride, //
445
+ usearch_error_t* error);
446
+
447
+ #ifdef __cplusplus
448
+ }
449
+ #endif
450
+
451
+ #endif // UNUM_USEARCH_H
@@ -0,0 +1,7 @@
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)
@@ -0,0 +1,15 @@
1
+ include(FindPackageHandleStandardArgs)
2
+ set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE})
3
+ find_package_handle_standard_args(@PROJECT_NAME@ CONFIG_MODE)
4
+
5
+ if(NOT TARGET @PROJECT_NAME@::@USEARCH_TARGET_NAME@)
6
+ include("${CMAKE_CURRENT_LIST_DIR}/@USEARCH_TARGETS_EXPORT_NAME@.cmake")
7
+ if((NOT TARGET @USEARCH_TARGET_NAME@) AND
8
+ (NOT @PROJECT_NAME@_FIND_VERSION OR
9
+ @PROJECT_NAME@_FIND_VERSION VERSION_LESS 3.2.0))
10
+ add_library(@USEARCH_TARGET_NAME@ INTERFACE IMPORTED)
11
+ set_target_properties(@USEARCH_TARGET_NAME@ PROPERTIES
12
+ INTERFACE_LINK_LIBRARIES @PROJECT_NAME@::@USEARCH_TARGET_NAME@
13
+ )
14
+ endif()
15
+ endif()
@@ -0,0 +1,8 @@
1
+ include(FetchContent)
2
+ FetchContent_Declare(
3
+ emscripten
4
+ GIT_REPOSITORY https://github.com/emscripten-core/emscripten
5
+ GIT_TAG main
6
+ )
7
+ FetchContent_MakeAvailable(emscripten)
8
+ include_directories(${emscripten_SOURCE_DIR}/include)
@@ -0,0 +1,62 @@
1
+ include(ExternalProject)
2
+ set(JEMALLOC_DISABLE_TLS)
3
+
4
+ if (${USTORE_BUILD_SDK_PYTHON})
5
+ set(JEMALLOC_DISABLE_TLS --disable-initial-exec-tls)
6
+ endif ()
7
+
8
+ if (${USTORE_REBUILD_JEMALLOC})
9
+ set(JEMALLOC_PREFIX_DIR ${CMAKE_BINARY_DIR}/_deps/jemalloc)
10
+ set(JEMALLOC_SRC_DIR ${JEMALLOC_PREFIX_DIR}/src/jemalloc)
11
+ set(JEMALLOC_INSTALL_DIR ${JEMALLOC_PREFIX_DIR}/install)
12
+ set(JEMALLOC_DEPENDENCY jemalloc)
13
+
14
+ ExternalProject_Add(
15
+ jemalloc
16
+ GIT_REPOSITORY https://github.com/jemalloc/jemalloc.git
17
+ GIT_TAG 5.3.0
18
+ PREFIX ${JEMALLOC_PREFIX_DIR}
19
+ CONFIGURE_COMMAND
20
+ echo Configuring jemalloc && cd ${JEMALLOC_SRC_DIR} && ./autogen.sh && ./configure
21
+ --prefix=${JEMALLOC_INSTALL_DIR} --enable-prof ${JEMALLOC_DISABLE_TLS} # --with-jemalloc-prefix=je_
22
+ BUILD_COMMAND echo Building jemalloc && cd ${JEMALLOC_SRC_DIR} && make install_lib_static install_include
23
+ INSTALL_COMMAND ""
24
+ UPDATE_COMMAND ""
25
+ )
26
+
27
+ # Create libjemalloc and libjemalloc_pic targets to be used as dependencies
28
+ add_library(libjemalloc STATIC IMPORTED GLOBAL)
29
+ add_library(libjemalloc_pic STATIC IMPORTED GLOBAL)
30
+
31
+ set_property(TARGET libjemalloc PROPERTY IMPORTED_LOCATION ${JEMALLOC_INSTALL_DIR}/lib/libjemalloc.a)
32
+ set_property(TARGET libjemalloc_pic PROPERTY IMPORTED_LOCATION ${JEMALLOC_INSTALL_DIR}/lib/libjemalloc_pic.a)
33
+
34
+ link_libraries(-Wl,--no-as-needed)
35
+ link_libraries(dl ${libjemalloc_pic})
36
+
37
+ # Export the include directory path.
38
+ set(JEMALLOC_SOURCE_DIR ${JEMALLOC_INSTALL_DIR})
39
+ set(JEMALLOC_LIBRARIES ${JEMALLOC_INSTALL_DIR}/lib/libjemalloc_pic.a ${JEMALLOC_INSTALL_DIR}/lib/libjemalloc.a)
40
+
41
+ include_directories(${JEMALLOC_SOURCE_DIR}/include)
42
+
43
+ else ()
44
+ find_path(JEMALLOC_ROOT_DIR NAMES include/jemalloc/jemalloc.h)
45
+
46
+ find_library(
47
+ JEMALLOC_LIBRARIES
48
+ NAMES jemalloc
49
+ HINTS ${JEMALLOC_ROOT_DIR}/lib
50
+ )
51
+
52
+ find_path(
53
+ JEMALLOC_INCLUDE_DIR
54
+ NAMES jemalloc/jemalloc.h
55
+ HINTS ${JEMALLOC_ROOT_DIR}/include
56
+ )
57
+
58
+ include(FindPackageHandleStandardArgs)
59
+ find_package_handle_standard_args(JeMalloc DEFAULT_MSG JEMALLOC_LIBRARIES JEMALLOC_INCLUDE_DIR)
60
+
61
+ mark_as_advanced(JEMALLOC_ROOT_DIR JEMALLOC_LIBRARIES JEMALLOC_INCLUDE_DIR)
62
+ endif ()
@@ -0,0 +1,4 @@
1
+ Name: ${PROJECT_NAME}
2
+ Description: Smaller & Faster Single-File Vector Search Engine from Unum
3
+ Version: ${PROJECT_VERSION}
4
+ Cflags: -I${CMAKE_INSTALL_FULL_INCLUDEDIR}
@@ -0,0 +1,20 @@
1
+ # This is essentially cmake's BasicConfigVersion-SameMajorVersion.cmake.in but
2
+ # without the 32/64-bit check. Since USearch is a header-only library, it doesn't
3
+ # matter if it was built on a different platform than what it is used on (see
4
+ # https://github.com/nlohmann/json/issues/1697).
5
+ set(PACKAGE_VERSION "@PROJECT_VERSION@")
6
+
7
+ if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
8
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
9
+ else()
10
+
11
+ if(PACKAGE_FIND_VERSION_MAJOR STREQUAL "@PROJECT_VERSION_MAJOR@")
12
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
13
+ else()
14
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
15
+ endif()
16
+
17
+ if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
18
+ set(PACKAGE_VERSION_EXACT TRUE)
19
+ endif()
20
+ endif()
@@ -0,0 +1,14 @@
1
+ if (USEARCH_BUILD_TEST_CPP)
2
+ add_executable(test_cpp test.cpp)
3
+ setup_target(test_cpp)
4
+ include(CTest)
5
+ enable_testing()
6
+ add_test(NAME test_cpp COMMAND test_cpp)
7
+ endif ()
8
+
9
+ if (USEARCH_BUILD_BENCH_CPP)
10
+ include(clipp)
11
+ add_executable(bench_cpp bench.cpp)
12
+ setup_target(bench_cpp)
13
+ target_include_directories(bench_cpp PRIVATE ${clipp_SOURCE_DIR}/include)
14
+ endif ()