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/README.md CHANGED
@@ -30,19 +30,18 @@ Spatial • Binary • Probabilistic • User-Defined Metrics
30
30
  <a href="https://unum-cloud.github.io/usearch/swift">Swift</a> •
31
31
  <a href="https://unum-cloud.github.io/usearch/csharp">C#</a> •
32
32
  <a href="https://unum-cloud.github.io/usearch/golang">GoLang</a> •
33
- <a href="https://unum-cloud.github.io/usearch/wolfram">Wolfram</a> •
34
- <a href="https://unum-cloud.github.io/usearch/sqlite">SQLite3</a>
33
+ <a href="https://unum-cloud.github.io/usearch/wolfram">Wolfram</a>
35
34
  <br/>
36
- Linux • MacOS • Windows • iOS • WebAssembly
35
+ Linux • MacOS • Windows • iOS • WebAssembly •
36
+ <a href="https://unum-cloud.github.io/usearch/sqlite">SQLite3</a>
37
37
  </p>
38
38
 
39
39
  <div align="center">
40
- <a href="https://pepy.tech/project/usearch"> <img alt="PyPI" src="https://static.pepy.tech/personalized-badge/usearch?period=total&units=abbreviation&left_color=black&right_color=blue&left_text=USearch%20Python%20installs"> </a>
41
- <a href="https://www.npmjs.com/package/usearch"> <img alt="NPM" src="https://img.shields.io/npm/dy/usearch?label=NPM%20installs"> </a>
42
- <a href="https://crates.io/crates/usearch"> <img alt="Crate" src="https://img.shields.io/crates/d/usearch?label=Crate%20installs"> </a>
43
- <a href="https://www.nuget.org/packages/Cloud.Unum.USearch"> <img alt="NuGet" src="https://img.shields.io/nuget/dt/Cloud.Unum.USearch?label=NuGet%20installs"> </a>
44
- <a href="https://central.sonatype.com/artifact/cloud.unum/usearch/overview"> <img alt="Maven" src="https://img.shields.io/nexus/r/cloud.unum/usearch?server=https%3A%2F%2Fs01.oss.sonatype.org%2F&label=Maven%20version"> </a>
45
- <a href="https://hub.docker.com/r/unum/usearch"> <img alt="Docker" src="https://img.shields.io/docker/pulls/unum/usearch?label=Docker%20installs"> </a>
40
+ <a href="https://pepy.tech/project/usearch"> <img alt="PyPI" src="https://static.pepy.tech/personalized-badge/usearch?period=total&units=abbreviation&left_color=black&right_color=blue&left_text=Python%20PyPi%20installs"> </a>
41
+ <a href="https://www.npmjs.com/package/usearch"> <img alt="NPM" src="https://img.shields.io/npm/dy/usearch?label=JavaScript%20NPM%20installs"> </a>
42
+ <a href="https://crates.io/crates/usearch"> <img alt="Crate" src="https://img.shields.io/crates/d/usearch?label=Rust%20Crate%20installs"> </a>
43
+ <a href="https://www.nuget.org/packages/Cloud.Unum.USearch"> <img alt="NuGet" src="https://img.shields.io/nuget/dt/Cloud.Unum.USearch?label=CSharp%20NuGet%20installs"> </a>
44
+ <a href="https://central.sonatype.com/artifact/cloud.unum/usearch/overview"> <img alt="Maven" src="https://img.shields.io/nexus/r/cloud.unum/usearch?server=https%3A%2F%2Fs01.oss.sonatype.org%2F&label=Java%20Maven%20version"> </a>
46
45
  <img alt="GitHub code size in bytes" src="https://img.shields.io/github/languages/code-size/unum-cloud/usearch?label=Repo%20size">
47
46
  </div>
48
47
 
@@ -50,18 +49,16 @@ Linux • MacOS • Windows • iOS • WebAssembly
50
49
 
51
50
  - ✅ __[10x faster][faster-than-faiss]__ [HNSW][hnsw-algorithm] implementation than [FAISS][faiss].
52
51
  - ✅ Simple and extensible [single C++11 header][usearch-header] __library__.
53
- - ✅ Compatible with a dozen programming languages out of the box.
54
52
  - ✅ [Trusted](#integrations) by giants like Google and databases like [ClickHouse][clickhouse-docs].
55
53
  - ✅ [SIMD][simd]-optimized and [user-defined metrics](#user-defined-functions) with JIT compilation.
56
54
  - ✅ Hardware-agnostic `f16` & `i8` - [half-precision & quarter-precision support](#memory-efficiency-downcasting-and-quantization).
57
55
  - ✅ [View large indexes from disk](#serving-index-from-disk) without loading into RAM.
58
56
  - ✅ Heterogeneous lookups, renaming/relabeling, and on-the-fly deletions.
59
- - ✅ Variable dimensionality vectors for unique applications, including search over compressed data.
60
57
  - ✅ Binary Tanimoto and Sorensen coefficients for [Genomics and Chemistry applications](#usearch--rdkit--molecular-search).
61
58
  - ✅ Space-efficient point-clouds with `uint40_t`, accommodating 4B+ size.
62
- - ✅ Compatible with OpenMP and custom "executors" for fine-grained control over CPU utilization.
63
- - ✅ Near-real-time [clustering and sub-clustering](#clustering) for Tens or Millions of clusters.
59
+ - ✅ Compatible with OpenMP and custom "executors" for fine-grained parallelism.
64
60
  - ✅ [Semantic Search](#usearch--ai--multi-modal-semantic-search) and [Joins](#joins-one-to-one-one-to-many-and-many-to-many-mappings).
61
+ - 🔄 Near-real-time [clustering and sub-clustering](#clustering) for Tens or Millions of clusters.
65
62
 
66
63
  [faiss]: https://github.com/facebookresearch/faiss
67
64
  [usearch-header]: https://github.com/unum-cloud/usearch/blob/main/include/usearch/index.hpp
@@ -133,7 +130,7 @@ matches = index.search(vector, 10)
133
130
 
134
131
  assert matches[0].key == 42
135
132
  assert matches[0].distance <= 0.001
136
- assert np.allclose(index[42], vector)
133
+ assert np.allclose(index[42], vector, atol=0.1) # Ensure high tolerance in mixed-precision comparisons
137
134
  ```
138
135
 
139
136
  More settings are always available, and the API is designed to be as flexible as possible.
@@ -195,6 +192,44 @@ When compared to FAISS's `IndexFlatL2` in Google Colab, __[USearch may offer up
195
192
  - `faiss.IndexFlatL2`: __55.3 ms__.
196
193
  - `usearch.index.search`: __2.54 ms__.
197
194
 
195
+ ## User-Defined Functions
196
+
197
+ While most vector search packages concentrate on just a few metrics - "Inner Product distance" and "Euclidean distance," USearch extends this list to include any user-defined metrics.
198
+ This flexibility allows you to customize your search for various applications, from computing geospatial coordinates with the rare [Haversine][haversine] distance to creating custom metrics for composite embeddings from multiple AI models.
199
+
200
+ ![USearch: Vector Search Approaches](https://github.com/unum-cloud/usearch/blob/main/assets/usearch-approaches-white.png?raw=true)
201
+
202
+ Unlike older approaches indexing high-dimensional spaces, like KD-Trees and Locality Sensitive Hashing, HNSW doesn't require vectors to be identical in length.
203
+ They only have to be comparable.
204
+ So you can apply it in [obscure][obscure] applications, like searching for similar sets or fuzzy text matching, using [GZip][gzip-similarity] as a distance function.
205
+
206
+ > Read more about [JIT and UDF in USearch Python SDK](https://unum-cloud.github.io/usearch/python#user-defined-metrics-and-jit-in-python).
207
+
208
+ [haversine]: https://ashvardanian.com/posts/abusing-vector-search#geo-spatial-indexing
209
+ [obscure]: https://ashvardanian.com/posts/abusing-vector-search
210
+ [gzip-similarity]: https://twitter.com/LukeGessler/status/1679211291292889100?s=20
211
+
212
+ ## Memory Efficiency, Downcasting, and Quantization
213
+
214
+ Training a quantization model and dimension-reduction is a common approach to accelerate vector search.
215
+ Those, however, are only sometimes reliable, can significantly affect the statistical properties of your data, and require regular adjustments if your distribution shifts.
216
+ Instead, we have focused on high-precision arithmetic over low-precision downcasted vectors.
217
+ The same index, and `add` and `search` operations will automatically down-cast or up-cast between `f64_t`, `f32_t`, `f16_t`, `i8_t`, and single-bit representations.
218
+ You can use the following command to check, if hardware acceleration is enabled:
219
+
220
+ ```sh
221
+ $ python -c 'from usearch.index import Index; print(Index(ndim=768, metric="cos", dtype="f16").hardware_acceleration)'
222
+ > sapphire
223
+ $ python -c 'from usearch.index import Index; print(Index(ndim=166, metric="tanimoto").hardware_acceleration)'
224
+ > ice
225
+ ```
226
+
227
+ Using smaller numeric types will save you RAM needed to store the vectors, but you can also compress the neighbors lists forming our proximity graphs.
228
+ By default, 32-bit `uint32_t` is used to enumerate those, which is not enough if you need to address over 4 Billion entries.
229
+ For such cases we provide a custom `uint40_t` type, that will still be 37.5% more space-efficient than the commonly used 8-byte integers, and will scale up to 1 Trillion entries.
230
+
231
+ ![USearch uint40_t support](https://github.com/unum-cloud/usearch/blob/main/assets/usearch-neighbor-types.png?raw=true)
232
+
198
233
  ## `Indexes` for Multi-Index Lookups
199
234
 
200
235
  For larger workloads targeting billions or even trillions of vectors, parallel multi-index lookups become invaluable.
@@ -267,43 +302,6 @@ pairs: dict = men.join(women, max_proposals=0, exact=False)
267
302
 
268
303
  > Read more in the post: [Combinatorial Stable Marriages for Semantic Search 💍](https://ashvardanian.com/posts/searching-stable-marriages)
269
304
 
270
- ## User-Defined Functions
271
-
272
- While most vector search packages concentrate on just a few metrics - "Inner Product distance" and "Euclidean distance," USearch extends this list to include any user-defined metrics.
273
- This flexibility allows you to customize your search for various applications, from computing geospatial coordinates with the rare [Haversine][haversine] distance to creating custom metrics for composite embeddings from multiple AI models.
274
-
275
- ![USearch: Vector Search Approaches](https://github.com/unum-cloud/usearch/blob/main/assets/usearch-approaches-white.png?raw=true)
276
-
277
- Unlike older approaches indexing high-dimensional spaces, like KD-Trees and Locality Sensitive Hashing, HNSW doesn't require vectors to be identical in length.
278
- They only have to be comparable.
279
- So you can apply it in [obscure][obscure] applications, like searching for similar sets or fuzzy text matching, using [GZip][gzip-similarity] as a distance function.
280
-
281
- > Read more about [JIT and UDF in USearch Python SDK](https://unum-cloud.github.io/usearch/python#user-defined-metrics-and-jit-in-python).
282
-
283
- [haversine]: https://ashvardanian.com/posts/abusing-vector-search#geo-spatial-indexing
284
- [obscure]: https://ashvardanian.com/posts/abusing-vector-search
285
- [gzip-similarity]: https://twitter.com/LukeGessler/status/1679211291292889100?s=20
286
-
287
- ## Memory Efficiency, Downcasting, and Quantization
288
-
289
- Training a quantization model and dimension-reduction is a common approach to accelerate vector search.
290
- Those, however, are only sometimes reliable, can significantly affect the statistical properties of your data, and require regular adjustments if your distribution shifts.
291
- Instead, we have focused on high-precision arithmetic over low-precision downcasted vectors.
292
- The same index, and `add` and `search` operations will automatically down-cast or up-cast between `f64_t`, `f32_t`, `f16_t`, `i8_t`, and single-bit representations.
293
- You can use the following command to check, if hardware acceleration is enabled:
294
-
295
- ```sh
296
- $ python -c 'from usearch.index import Index; print(Index(ndim=768, metric="cos", dtype="f16").hardware_acceleration)'
297
- > avx512+f16
298
- $ python -c 'from usearch.index import Index; print(Index(ndim=166, metric="tanimoto").hardware_acceleration)'
299
- > avx512+popcnt
300
- ```
301
-
302
- Using smaller numeric types will save you RAM needed to store the vectors, but you can also compress the neighbors lists forming our proximity graphs.
303
- By default, 32-bit `uint32_t` is used to enumerate those, which is not enough if you need to address over 4 Billion entries.
304
- For such cases we provide a custom `uint40_t` type, that will still be 37.5% more space-efficient than the commonly used 8-byte integers, and will scale up to 1 Trillion entries.
305
-
306
- ![USearch uint40_t support](https://github.com/unum-cloud/usearch/blob/main/assets/usearch-neighbor-types.png?raw=true)
307
305
 
308
306
  ## Functionality
309
307
 
@@ -434,7 +432,7 @@ doi = {10.5281/zenodo.7949416},
434
432
  author = {Vardanian, Ash},
435
433
  title = {{USearch by Unum Cloud}},
436
434
  url = {https://github.com/unum-cloud/usearch},
437
- version = {2.9.1},
435
+ version = {2.10.0},
438
436
  year = {2023},
439
437
  month = oct,
440
438
  }
@@ -1,4 +1,87 @@
1
- export class Index {
1
+ type Vector = Float32Array | Float64Array | Int8Array;
2
+ type Matrix = Vector[];
3
+ type VectorOrMatrix = Vector | Matrix;
4
+ /**
5
+ * Enumeration representing the various metric kinds used to measure the distance between vectors in the index.
6
+ * @enum {string}
7
+ * @readonly
8
+ */
9
+ export declare enum MetricKind {
10
+ Unknown = "unknown",
11
+ Cos = "cos",
12
+ IP = "ip",
13
+ L2sq = "l2sq",
14
+ Haversine = "haversine",
15
+ Divergence = "divergence",
16
+ Pearson = "pearson",
17
+ Jaccard = "jaccard",
18
+ Hamming = "hamming",
19
+ Tanimoto = "tanimoto",
20
+ Sorensen = "sorensen"
21
+ }
22
+ /**
23
+ * Enumeration representing the various scalar kinds used to define the type of scalar values in vectors.
24
+ * @enum {string}
25
+ * @readonly
26
+ */
27
+ export declare enum ScalarKind {
28
+ Unknown = "unknown",
29
+ F32 = "f32",
30
+ F64 = "f64",
31
+ F16 = "f16",
32
+ I8 = "i8",
33
+ B1 = "b1"
34
+ }
35
+ /**
36
+ * Represents a set of search results.
37
+ */
38
+ export declare class Matches {
39
+ keys: BigUint64Array;
40
+ distances: Float32Array;
41
+ /**
42
+ * Constructs a Matches object.
43
+ *
44
+ * @param {BigUint64Array} keys - The keys of the nearest neighbors found.
45
+ * @param {Float32Array} distances - The distances of the nearest neighbors found.
46
+ */
47
+ constructor(keys: BigUint64Array, distances: Float32Array);
48
+ }
49
+ /**
50
+ * Represents a set of batched search results.
51
+ */
52
+ export declare class BatchMatches {
53
+ keys: BigUint64Array;
54
+ distances: Float32Array;
55
+ counts: BigUint64Array;
56
+ k: number;
57
+ /**
58
+ * Constructs a BatchMatches object.
59
+ *
60
+ * @param {BigUint64Array} keys - The keys of the nearest neighbors found in the batch.
61
+ * @param {Float32Array} distances - The distances of the nearest neighbors found in the batch.
62
+ * @param {BigUint64Array} counts - The number of neighbors found for each query in the batch.
63
+ * @param {number} k - The limit for search results per query in the batch.
64
+ */
65
+ constructor(keys: BigUint64Array, distances: Float32Array, counts: BigUint64Array, k: number);
66
+ /**
67
+ * Retrieves a Matches object at the specified index in the batch.
68
+ *
69
+ * @param {number} i - The index at which to retrieve the Matches object.
70
+ * @returns {Matches} - A Matches object representing the search results at the specified index in the batch.
71
+ */
72
+ get(i: number): Matches;
73
+ }
74
+ export interface IndexCongif {
75
+ dimensions: number;
76
+ metric: MetricKind;
77
+ quantization: ScalarKind;
78
+ connectivity: number;
79
+ expansion_add: number;
80
+ expansion_search: number;
81
+ multi: boolean;
82
+ }
83
+ export declare class Index {
84
+ #private;
2
85
  /**
3
86
  * Constructs a new index.
4
87
  *
@@ -11,16 +94,7 @@ export class Index {
11
94
  * @param {boolean} [multi=false] - Optional, default is false.
12
95
  * @throws Will throw an error if any of the parameters are of incorrect type or invalid value.
13
96
  */
14
- constructor(dimensionsOrConfigs: number | {
15
- dimensions: number;
16
- metric: MetricKind;
17
- quantization: ScalarKind;
18
- connectivity: number;
19
- expansion_add: number;
20
- expansion_search: number;
21
- multi: boolean;
22
- }, metric?: MetricKind, quantization?: ScalarKind, connectivity?: number, expansion_add?: number, expansion_search?: number, multi?: boolean);
23
- _compiledIndex: any;
97
+ constructor(dimensionsOrConfigs: number | bigint | IndexCongif, metric?: MetricKind, quantization?: ScalarKind, connectivity?: number, expansion_add?: number, expansion_search?: number, multi?: boolean);
24
98
  /**
25
99
  * Add vectors to the index.
26
100
  *
@@ -43,7 +117,7 @@ export class Index {
43
117
  * @throws Will throw an error if the length of keys doesn't match the number of vectors
44
118
  * or if it's not a single key.
45
119
  */
46
- add(keys: bigint | bigint[] | BigUint64Array, vectors: Float32Array | Float64Array | Int8Array): void;
120
+ add(keys: bigint | bigint[] | BigUint64Array, vectors: Vector): void;
47
121
  /**
48
122
  * Perform a k-nearest neighbor search on the index.
49
123
  *
@@ -59,13 +133,13 @@ export class Index {
59
133
  * query vector. If there are not enough results for a query, the result array is
60
134
  * padded with -1s.
61
135
  *
62
- * @param {Float32Array|Float64Array|Int8Array|Array<Array<number>>} vectors - Input matrix representing query vectors, can be a TypedArray or an array of arrays.
136
+ * @param {Float32Array|Float64Array|Int8Array|Array<Array<number>>} vectors - Input matrix representing query vectors, can be a TypedArray or an array of TypedArray.
63
137
  * @param {number} k - The number of nearest neighbors to search for each query vector.
64
138
  * @return {Matches|BatchMatches} - Search results for one or more queries, containing keys, distances, and counts of the matches found.
65
139
  * @throws Will throw an error if `k` is not a positive integer or if the size of the vectors is not a multiple of dimensions.
66
- * @throws Will throw an error if `vectors` is not a valid input type (TypedArray or an array of arrays) or if its flattened size is not a multiple of dimensions.
140
+ * @throws Will throw an error if `vectors` is not a valid input type (TypedArray or an array of TypedArray) or if its flattened size is not a multiple of dimensions.
67
141
  */
68
- search(vectors: Float32Array | Float64Array | Int8Array | Array<Array<number>>, k: number): Matches | BatchMatches;
142
+ search(vectors: VectorOrMatrix, k: number): Matches | BatchMatches;
69
143
  /**
70
144
  * Verifies the presence of one or more keys in the index.
71
145
  *
@@ -135,103 +209,4 @@ export class Index {
135
209
  */
136
210
  view(path: string): void;
137
211
  }
138
- /**
139
- * *
140
- */
141
- export type MetricKind = string;
142
- export namespace MetricKind {
143
- let Unknown: string;
144
- let Cos: string;
145
- let IP: string;
146
- let L2sq: string;
147
- let Haversine: string;
148
- let Divergence: string;
149
- let Pearson: string;
150
- let Jaccard: string;
151
- let Hamming: string;
152
- let Tanimoto: string;
153
- let Sorensen: string;
154
- }
155
- /**
156
- * *
157
- */
158
- export type ScalarKind = string;
159
- export namespace ScalarKind {
160
- let Unknown_1: string;
161
- export { Unknown_1 as Unknown };
162
- export let F32: string;
163
- export let F64: string;
164
- export let F16: string;
165
- export let I8: string;
166
- export let B1: string;
167
- }
168
- /**
169
- * Represents a set of search results.
170
- */
171
- export class Matches {
172
- /**
173
- * Constructs a Matches object.
174
- *
175
- * @param {BigUint64Array} keys - The keys of the nearest neighbors found.
176
- * @param {Float32Array} distances - The distances of the nearest neighbors found.
177
- */
178
- constructor(keys: BigUint64Array, distances: Float32Array);
179
- keys: BigUint64Array;
180
- distances: Float32Array;
181
- }
182
- /**
183
- * Represents a set of batched search results.
184
- */
185
- export class BatchMatches {
186
- /**
187
- * Constructs a BatchMatches object.
188
- *
189
- * @param {BigUint64Array} keys - The keys of the nearest neighbors found in the batch.
190
- * @param {Float32Array} distances - The distances of the nearest neighbors found in the batch.
191
- * @param {BigUint64Array} counts - The number of neighbors found for each query in the batch.
192
- * @param {bigint} k - The limit for search results per query in the batch.
193
- */
194
- constructor(keys: BigUint64Array, distances: Float32Array, counts: BigUint64Array, k: bigint);
195
- keys: BigUint64Array;
196
- distances: Float32Array;
197
- counts: BigUint64Array;
198
- k: bigint;
199
- /**
200
- * Retrieves a Matches object at the specified index in the batch.
201
- *
202
- * @param {number} i - The index at which to retrieve the Matches object.
203
- * @returns {Matches} - A Matches object representing the search results at the specified index in the batch.
204
- */
205
- get(i: number): Matches;
206
- }
207
- /**
208
- * Performs an exact search on the given dataset to find the best matching vectors for each query.
209
- *
210
- * @param {Float32Array|Float64Array|Int8Array|Array<Array<number>>} dataset - The dataset containing vectors to be searched. It can be a TypedArray or an array of arrays.
211
- * @param {Float32Array|Float64Array|Int8Array|Array<Array<number>>} queries - The queries containing vectors to search for in the dataset. It can be a TypedArray or an array of arrays.
212
- * @param {number} dimensions - The dimensionality of the vectors in both the dataset and the queries. It defines the number of elements in each vector.
213
- * @param {number} count - The number of nearest neighbors to return for each query. If the dataset contains fewer vectors than the specified count, the result will contain only the available vectors.
214
- * @param {MetricKind} metric - The distance metric to be used for the search.
215
- * @return {Matches|BatchMatches} - Returns a `Matches` or `BatchMatches` object containing the results of the search.
216
- * @throws Will throw an error if `dimensions` and `count` are not positive integers.
217
- * @throws Will throw an error if `metric` is not a valid MetricKind.
218
- * @throws Will throw an error if `dataset` and `queries` are not valid input types (TypedArray or an array of arrays).
219
- * @throws Will throw an error if the sizes of the flattened `dataset` and `queries` are not multiples of `dimensions`.
220
- * @throws Will throw an error if `count` is greater than the number of vectors in the `dataset`.
221
- *
222
- * @example
223
- * const dataset = [[1.0, 2.0], [3.0, 4.0]]; // Two vectors: [1.0, 2.0] and [3.0, 4.0]
224
- * const queries = [[1.5, 2.5]]; // One vector: [1.5, 2.5]
225
- * const dimensions = 2; // The number of elements in each vector.
226
- * const count = 1; // The number of nearest neighbors to return for each query.
227
- * const metric = MetricKind.IP; // Using the Inner Product distance metric.
228
- *
229
- * const result = exactSearch(dataset, queries, dimensions, count, metric);
230
- * // result might be:
231
- * // {
232
- * // keys: BigUint64Array [ 1n ],
233
- * // distances: Float32Array [ some_value ],
234
- * // }
235
- */
236
- export function exactSearch(dataset: Float32Array | Float64Array | Int8Array | Array<Array<number>>, queries: Float32Array | Float64Array | Int8Array | Array<Array<number>>, dimensions: number, count: number, metric: MetricKind): Matches | BatchMatches;
237
- //# sourceMappingURL=usearch.d.ts.map
212
+ export {};