usearch 0.1.9 → 0.2.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.
@@ -100,9 +100,15 @@
100
100
  "version": "cpp"
101
101
  },
102
102
  "cSpell.words": [
103
+ "astype",
104
+ "dtype",
103
105
  "equidimensional",
106
+ "hashable",
104
107
  "jaccard",
108
+ "longlong",
109
+ "memmap",
105
110
  "ndim",
111
+ "preprocess",
106
112
  "simsimd",
107
113
  "usearch"
108
114
  ],
package/CMakeLists.txt CHANGED
@@ -7,6 +7,10 @@ set(CMAKE_CXX_EXTENSIONS NO)
7
7
 
8
8
  option(USEARCH_USE_JEMALLOC "Use JeMalloc for Faster Memory Allocations" OFF)
9
9
  option(USEARCH_USE_OPENMP "Use OpenMP for a thread pool" OFF)
10
+ option(USEARCH_USE_SIMD "Use SIMD hardware acceleration" OFF)
11
+
12
+ option(USEARCH_BUILD_BENCHMARK "Compile a native benchmark in C++" ON)
13
+ option(USEARCH_BUILD_WOLFRAM "Compile Wolfram Language bindings" OFF)
10
14
 
11
15
  # Make "Release" by default
12
16
  if(NOT CMAKE_BUILD_TYPE)
@@ -42,7 +46,6 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "NVIDIA" OR CMAKE_CXX_COMPILER_ID STREQUAL
42
46
  elseif(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
43
47
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
44
48
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ferror-limit=1")
45
-
46
49
  endif()
47
50
 
48
51
  if(APPLE)
@@ -52,6 +55,7 @@ if(APPLE)
52
55
  set(CMAKE_USE_PTHREADS_INIT 1)
53
56
  set(THREADS_PREFER_PTHREAD_FLAG ON)
54
57
  endif()
58
+
55
59
  find_package(Threads REQUIRED)
56
60
 
57
61
  if(${USEARCH_USE_OPENMP})
@@ -62,11 +66,13 @@ endif()
62
66
  if(${USEARCH_USE_JEMALLOC})
63
67
  include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/jemalloc.cmake")
64
68
  endif()
69
+
65
70
  include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/clipp.cmake")
66
71
 
67
72
  include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
68
73
  include_directories("${CMAKE_CURRENT_SOURCE_DIR}/fp16/include")
69
74
  include_directories("${CMAKE_CURRENT_SOURCE_DIR}/simsimd/include")
75
+ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
70
76
 
71
77
  # Define our header-only library.
72
78
  add_library(usearch INTERFACE)
@@ -74,11 +80,23 @@ target_sources(usearch INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include/usearch/us
74
80
  target_include_directories(usearch INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
75
81
 
76
82
  # Define the targets
77
- add_executable(bench src/bench.cpp)
78
- target_link_libraries(bench PRIVATE Threads::Threads)
79
- if(${USEARCH_USE_OPENMP})
80
- target_link_libraries(bench PRIVATE ${OPENMP_LIBRARIES})
81
- endif()
82
- if(${USEARCH_USE_JEMALLOC})
83
- target_link_libraries(bench PRIVATE ${JEMALLOC_LIBRARIES})
83
+ if(${USEARCH_BUILD_BENCHMARK})
84
+ add_executable(bench src/bench.cpp)
85
+ target_link_libraries(bench PRIVATE Threads::Threads)
86
+
87
+ if(${USEARCH_USE_SIMD})
88
+ target_compile_definitions(bench PRIVATE USEARCH_USE_SIMD=1)
89
+ endif()
90
+
91
+ if(${USEARCH_USE_OPENMP})
92
+ target_link_libraries(bench PRIVATE ${OPENMP_LIBRARIES})
93
+ endif()
94
+
95
+ if(${USEARCH_USE_JEMALLOC})
96
+ target_link_libraries(bench PRIVATE ${JEMALLOC_LIBRARIES})
97
+ endif()
84
98
  endif()
99
+
100
+ if(${USEARCH_BUILD_WOLFRAM})
101
+ add_subdirectory(wolfram)
102
+ endif()
@@ -13,16 +13,22 @@ git submodule update --init --recursive
13
13
  ```sh
14
14
  cmake -B ./build_release \
15
15
  -DCMAKE_BUILD_TYPE=Release \
16
+ -DUSEARCH_USE_SIMD=1 \
16
17
  -DUSEARCH_USE_OPENMP=1 \
17
18
  -DUSEARCH_USE_JEMALLOC=1 && \
18
19
  make -C ./build_release -j
19
20
 
20
- # To benchmark:
21
+ # To benchmark in C++:
21
22
  ./build_release/bench \
22
23
  --vectors datasets/wiki_1M/base.1M.fbin \
23
24
  --queries datasets/wiki_1M/query.public.100K.fbin \
24
- --neighbors datasets/wiki_1M/groundtruth.public.100K.ibin \
25
- --ip
25
+ --neighbors datasets/wiki_1M/groundtruth.public.100K.ibin
26
+
27
+ # To benchmark in Python:
28
+ python python/bench.py \
29
+ --vectors datasets/wiki_1M/base.1M.fbin \
30
+ --queries datasets/wiki_1M/query.public.100K.fbin \
31
+ --neighbors datasets/wiki_1M/groundtruth.public.100K.ibin
26
32
  ```
27
33
 
28
34
  ### MacOS
@@ -32,15 +38,10 @@ brew install libomp llvm
32
38
  cmake \
33
39
  -DCMAKE_C_COMPILER="/opt/homebrew/opt/llvm/bin/clang" \
34
40
  -DCMAKE_CXX_COMPILER="/opt/homebrew/opt/llvm/bin/clang++" \
41
+ -DUSEARCH_USE_SIMD=1 \
42
+ -DUSEARCH_USE_OPENMP=1 \
35
43
  -B ./build_release && \
36
- make -C ./build_release -j
37
-
38
- # To benchmark:
39
- ./build_release/bench \
40
- --vectors datasets/wiki_1M/base.1M.fbin \
41
- --queries datasets/wiki_1M/query.public.100K.fbin \
42
- --neighbors datasets/wiki_1M/groundtruth.public.100K.ibin \
43
- --ip
44
+ make -C ./build_release -j
44
45
  ```
45
46
 
46
47
  ### Python
@@ -48,13 +49,6 @@ cmake \
48
49
  ```sh
49
50
  pip install -e .
50
51
  python python/test.py
51
-
52
- # To benchmark:
53
- python python/bench.py \
54
- --vectors datasets/wiki_1M/base.1M.fbin \
55
- --queries datasets/wiki_1M/query.public.100K.fbin \
56
- --neighbors datasets/wiki_1M/groundtruth.public.100K.ibin \
57
- --ip
58
52
  ```
59
53
 
60
54
  ### JavaScript
@@ -113,24 +107,45 @@ brew install --cask wolfram-engine
113
107
 
114
108
  ### Datasets
115
109
 
116
- ### Evaluation
110
+ BigANN benchmark is a good starting point, if you are searching for large collections of high-dimensional vectors.
111
+ Those often come with precomputed ground-truth neighbors, which is handy for recall evaluation.
112
+
113
+ | Dataset | Scalar Type | Dimensions | Metric | Size |
114
+ | :------------------------------ | :---------: | :--------: | :----: | :----: |
115
+ | [Microsoft SPACEV][spacev] | int8 | 100 | L2 | 93 GB |
116
+ | [Microsoft Turing-ANNS][turing] | float32 | 100 | L2 | 373 GB |
117
+ | [Yandex Deep1B][deep] | float32 | 96 | L2 | 358 GB |
118
+ | [Yandex Text-to-Image][t2i] | float32 | 200 | Cos | 750 GB |
117
119
 
118
- Yandex Text-to-Image embeddings.
120
+ Luckily, smaller samples of those datasets are available.
121
+
122
+ [spacev]: https://github.com/microsoft/SPTAG/tree/main/datasets/SPACEV1B
123
+ [turing]: https://learning2hash.github.io/publications/microsoftturinganns1B/
124
+ [t2i]: https://research.yandex.com/blog/benchmarks-for-billion-scale-similarity-search
125
+ [deep]: https://research.yandex.com/blog/benchmarks-for-billion-scale-similarity-search
126
+
127
+ ### Yandex Deep1B
128
+
129
+ There is a 10M subset available.
119
130
 
120
131
  ```sh
121
- export path_vectors=datasets/t2i_1M/base.1M.fbin
122
- export path_queries=datasets/t2i_1M/query.public.100K.fbin
123
- export path_neighbors=datasets/t2i_1M/groundtruth.public.100K.ibin
124
- ./build_release/bench
132
+ mkdir -p datasets/deep/ && \
133
+ wget -nc https://storage.yandexcloud.net/yandex-research/ann-datasets/DEEP/base.1B.fbin -P datasets/deep_1B/ &&
134
+ wget -nc https://storage.yandexcloud.net/yandex-research/ann-datasets/DEEP/base.10M.fbin -P datasets/deep_1B/ &&
135
+ wget -nc https://storage.yandexcloud.net/yandex-research/ann-datasets/DEEP/query.public.10K.fbin -P datasets/deep_1B/ &&
136
+ wget -nc https://storage.yandexcloud.net/yandex-research/ann-datasets/DEEP/groundtruth.public.10K.ibin -P datasets/deep_1B/
125
137
  ```
126
138
 
127
- Wikipedia UForm embeddings.
139
+ ### Yandex Text-to-Image
140
+
141
+ There is a 1M subset available.
128
142
 
129
143
  ```sh
130
- export path_vectors=datasets/wiki_1M/base.1M.fbin
131
- export path_queries=datasets/wiki_1M/query.public.100K.fbin
132
- export path_neighbors=datasets/wiki_1M/groundtruth.public.100K.ibin
133
- ./build_release/bench
144
+ mkdir -p datasets/t2i/ && \
145
+ wget -nc https://storage.yandexcloud.net/yandex-research/ann-datasets/T2I/base.1B.fbin -P datasets/t2i_1B/ &&
146
+ wget -nc https://storage.yandexcloud.net/yandex-research/ann-datasets/T2I/base.1M.fbin -P datasets/t2i_1B/ &&
147
+ wget -nc https://storage.yandexcloud.net/yandex-research/ann-datasets/T2I/query.public.100K.fbin -P datasets/t2i_1B/ &&
148
+ wget -nc https://storage.yandexcloud.net/yandex-research/ann-datasets/T2I/groundtruth.public.100K.ibin -P datasets/t2i_1B/
134
149
  ```
135
150
 
136
151
  ### Profiling
@@ -139,9 +154,10 @@ With `perf`:
139
154
 
140
155
  ```sh
141
156
  # Pass environment variables with `-E`, and `-d` for details
142
- sudo -E perf stat -d ./build_release/bench
143
- sudo -E perf mem -d ./build_release/bench
157
+ sudo -E perf stat -d ./build_release/bench ...
158
+ sudo -E perf mem -d ./build_release/bench ...
144
159
  # Sample on-CPU functions for the specified command, at 1 Kilo Hertz:
145
- sudo -E perf record -F 1000 ./build_release/bench
146
- perf record -d -e arm_spe// -- ./build_release/bench
160
+ sudo -E perf record -F 1000 ./build_release/bench ...
161
+ perf record -d -e arm_spe// -- ./build_release/bench ..
147
162
  ```
163
+
package/Cargo.toml CHANGED
@@ -1,8 +1,8 @@
1
1
  [package]
2
2
  name = "usearch"
3
- version = "0.1.9"
3
+ version = "0.2.0"
4
4
  authors = ["Ashot Vardanian <1983160+ashvardanian@users.noreply.github.com>"]
5
- description = "The Mighty Tiny Vector Search Engine with Automatic Quantization and Hardware Acceleration"
5
+ description = "Smaller & Faster Single-File Vector Search Engine from Unum"
6
6
  edition = "2021"
7
7
  license = "Apache-2.0"
8
8
  publish = true
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <h1 align="center">USearch</h1>
2
2
  <h3 align="center">
3
- C++11 Single Header Vector Search<br/>
4
- Compact, yet Powerful<br/>
3
+ Smaller & Faster Single-File<br/>
4
+ Vector Search Engine<br/>
5
5
  </h3>
6
6
  <br/>
7
7
 
@@ -27,20 +27,20 @@ Compact, yet Powerful<br/>
27
27
  - [x] Hardware-accelerated [`ashvardanian/simsimd`](https://github.com/ashvardanian/simsimd).
28
28
  - [x] Variable dimensionality vectors.
29
29
  - [x] Don't copy vectors if not needed.
30
- - [x] Bring your threads.
30
+ - [x] [Bring your threads](#bring-your-threads), like OpenMP.
31
31
  - [x] Multiple vectors per label.
32
32
  - [x] [Python](#python) bindings: `pip install usearch`.
33
33
  - [x] [JavaScript](#java) bindings: `npm install usearch`.
34
34
  - [x] [Rust](#rust) bindings: `cargo add usearch`.
35
35
  - [x] [Java](#java) bindings: `cloud.unum:usearch` on GitHub.
36
36
  - [ ] GoLang bindings.
37
- - [ ] Wolfram language bindings.
37
+ - [x] Wolfram language bindings.
38
38
  - [x] For Linux: GCC, Clang.
39
39
  - [x] For MacOS: Apple Clang.
40
40
  - [ ] For Windows.
41
41
  - [ ] Multi-index lookups in Python.
42
42
  - [ ] Thread-safe `reserve`.
43
- - [ ] Distributed construction.
43
+ - [ ] Distributed construction with MPI.
44
44
  - [x] AI + Vector Search = Semantic Search.
45
45
 
46
46
  [usearch-header]: https://github.com/unum-cloud/usearch/blob/main/include/usearch/usearch.hpp
@@ -80,12 +80,11 @@ Constructing a vector index is a memory-intensive task.
80
80
  Depending on your configuration parameters, part of the memory will be allocated towards copies of vectors, and another part to the Small World Graph, common to NSW-like algorithms.
81
81
  Choosing the right data-structures and numeric types can have profound implications on both.
82
82
 
83
- ---
83
+ ![USearch uint40_t support](assets/usearch-neighbor-types.png)
84
84
 
85
85
  Internally, some point "label" is mapped into an integer identifier for every stored vector.
86
86
  Most implementations hard-code it to `uint32_t`, as people rarely store more than 4 Billion vectors.
87
87
  But when they do, software becomes unusable.
88
-
89
88
  Others hard-code it to `uint64_t`, which hardly space-efficient.
90
89
  We added a tiny class - `uint40_t`, that should be enough for collections up to 1 Trillion vectors.
91
90
 
@@ -94,17 +93,24 @@ We added a tiny class - `uint40_t`, that should be enough for collections up to
94
93
  To construct a large index one may use a beefy RAM-optimized machine, like the AWS `u-24tb1.metal` instances with 24 TB of RAM.
95
94
  Those are, however, pricy, and would cost you over $200/hour.
96
95
 
96
+ | | To Build | To Serve |
97
+ | :------- | :-----------: | :------------: |
98
+ | Instance | u-24tb1.metal | is4gen.8xlarge |
99
+ | Price | ~ $200/h | ~$4.5/h |
100
+ | RAM | 24 TB | 192 GB |
101
+ | SSD | EBS | 30 TB |
102
+
97
103
  You wouldn't want to have them running all the time.
98
104
  So, if you are working on large datasets, but don't need the in-RAM throughput, you can simply view an existing dataset from disk, without ever loading it fully into memory.
99
105
 
100
- Construct on large machines, deploy on the cheap ones.
106
+ > Construct on large machines, deploy on the cheap ones.
101
107
 
102
108
  ### Quantize on the Fly
103
109
 
104
110
  Most modern CPU have at least partial support for `half`-precision `f16_t` arithmetic.
105
111
  USearch supports automatic down-casting and up-casting between `f32_t`, `f16_t`, `f64_t`, and `i8q100_t` representations.
106
112
 
107
- Making vectors smaller will help pack more of them in-memory, while also increasing performance on CPUs implementing native support for target type.
113
+ > Making vectors smaller will help pack more of them in-memory, while also increasing performance on CPUs implementing native support for target type.
108
114
 
109
115
  ## Performance
110
116
 
@@ -213,14 +219,23 @@ import numpy as np
213
219
  import usearch
214
220
 
215
221
  index = usearch.Index(
216
- dim=256, # Define the number of dimensions in input vectors
222
+ ndim=256, # Define the number of dimensions in input vectors
217
223
  metric='cos', # Choose the "metric" or "distance", default = 'ip', optional
218
- dtype='f16', # Quantize to 'f16' or 'i8q100' if needed, default = 'f32', optional
224
+ dtype='f32', # Quantize to 'f16' or 'i8q100' if needed, default = 'f32', optional
219
225
  connectivity=16, # How frequent should the connections in the graph be, optional
220
226
  expansion_add=128, # Control the recall of indexing, optional
221
227
  expansion_search=64, # Control the quality of search, optional
222
228
  )
223
229
 
230
+ vector = np.random.uniform(0, 0.3, (index.ndim)).astype(np.float32)
231
+ index.add(42, vector)
232
+ matches, distances, count = index.search(vector, 10)
233
+ ```
234
+
235
+ Same can be done with batches, rather than single entries.
236
+ Under the hood, worker threads will be spawned, to parallelize the procedure.
237
+
238
+ ```py
224
239
  n = 100
225
240
  labels = np.array(range(n), dtype=np.longlong)
226
241
  vectors = np.random.uniform(0, 0.3, (n, index.ndim)).astype(np.float32)
@@ -228,9 +243,6 @@ vectors = np.random.uniform(0, 0.3, (n, index.ndim)).astype(np.float32)
228
243
  # You can avoid copying the data
229
244
  # Handy when build 1B+ indexes of memory-mapped files
230
245
  index.add(labels, vectors, copy=True)
231
- assert len(index) == n
232
-
233
- # You can search a batch at once
234
246
  matches, distances, counts = index.search(vectors, 10)
235
247
  ```
236
248
 
@@ -395,21 +407,20 @@ from PIL import Image
395
407
 
396
408
  server = ucall.Server()
397
409
  model = uform.get_model('unum-cloud/uform-vl-multilingual')
398
- index = usearch.Index(dim=256)
410
+ index = usearch.Index(ndim=256)
399
411
 
400
412
  @server
401
413
  def add(label: int, photo: Image.Image):
402
414
  image = model.preprocess_image(photo)
403
415
  vector = model.encode_image(image).detach().numpy()
404
- labels = np.array([label], dtype=np.longlong)
405
- index.add(labels, vector, copy=True)
416
+ index.add(label, vector.flatten(), copy=True)
406
417
 
407
418
  @server
408
419
  def search(query: str) -> np.ndarray:
409
420
  tokens = model.preprocess_text(query)
410
421
  vector = model.encode_text(tokens).detach().numpy()
411
- neighbors = index.search(vector, 3)
412
- return neighbors[0][:neighbors[2][0]]
422
+ neighbors, _, _ = index.search(vector.flatten(), 3)
423
+ return neighbors
413
424
 
414
425
  server.run()
415
426
  ```
package/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.2.0
package/build.gradle CHANGED
@@ -90,7 +90,7 @@ publishing {
90
90
 
91
91
  pom {
92
92
  name = "USearch"
93
- description = "The Mighty Tiny Vector Search Engine with Automatic Quantization and Hardware Acceleration"
93
+ description = "Smaller & Faster Single-File Vector Search Engine from Unum"
94
94
  url = "https://github.com/unum-cloud/usearch"
95
95
  licenses {
96
96
  license {
@@ -136,6 +136,30 @@ template <typename scalar_at> struct l2_squared_gt {
136
136
  }
137
137
  };
138
138
 
139
+ /**
140
+ * @brief Hamming distance computes the number of differing elements in
141
+ * two arrays. An example would be a chess board.
142
+ */
143
+ template <typename scalar_at> struct hamming_gt {
144
+ using scalar_t = scalar_at;
145
+ using result_type = std::size_t;
146
+
147
+ inline std::size_t operator()(scalar_t const* a, scalar_t const* b, std::size_t elements,
148
+ std::size_t = 0) const noexcept {
149
+ std::size_t matches{};
150
+ #if defined(__GNUC__)
151
+ #pragma GCC ivdep
152
+ #elif defined(__clang__)
153
+ #pragma clang loop vectorize(enable)
154
+ #elif defined(_OPENMP)
155
+ #pragma omp simd reduction(+ : matches)
156
+ #endif
157
+ for (std::size_t i = 0; i != elements; ++i)
158
+ matches += a[i] != b[i];
159
+ return matches;
160
+ }
161
+ };
162
+
139
163
  /**
140
164
  * @brief Hamming distance computes the number of differing bits in
141
165
  * two arrays of integers. An example would be a textual document,
@@ -315,8 +339,9 @@ class max_heap_gt {
315
339
  bool empty() const noexcept { return !size_; }
316
340
  std::size_t size() const noexcept { return size_; }
317
341
  std::size_t capacity() const noexcept { return capacity_; }
342
+ /// @brief Selects the largest element in the heap.
343
+ /// @return Reference to the stored element.
318
344
  element_t const& top() const noexcept { return elements_[0]; }
319
- element_t const& max() const noexcept { return elements_[0]; }
320
345
 
321
346
  void clear() noexcept {
322
347
  while (size_) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "usearch",
3
- "version": "0.1.9",
4
- "description": "The Mighty Tiny Vector Search Engine with Automatic Quantization and Hardware Acceleration",
3
+ "version": "0.2.0",
4
+ "description": "Smaller & Faster Single-File Vector Search Engine from Unum",
5
5
  "author": "Ashot Vardanian",
6
6
  "license": "Apache 2.0",
7
7
  "repository": {