usearch 2.9.2 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -38
- package/javascript/{types → dist/cjs}/usearch.d.ts +90 -115
- package/javascript/dist/cjs/usearch.js +531 -0
- package/javascript/dist/esm/usearch.d.ts +212 -0
- package/javascript/{usearch.js → dist/esm/usearch.js} +199 -153
- package/package.json +25 -23
- package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
- package/prebuilds/linux-arm64/usearch.node +0 -0
- package/prebuilds/linux-x64/usearch.node +0 -0
- package/prebuilds/win32-ia32/usearch.node +0 -0
- package/prebuilds/win32-x64/usearch.node +0 -0
- package/.clang-format +0 -10
- package/.clang-tidy +0 -60
- package/.cmake-format.py +0 -19
- package/.dockerignore +0 -93
- package/.gitattributes +0 -9
- package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
- package/.github/ISSUE_TEMPLATE/config.yml +0 -5
- package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -64
- package/.github/workflows/Dockerfile.libs +0 -36
- package/.github/workflows/prerelease.yml +0 -331
- package/.github/workflows/release.yml +0 -722
- package/.github/workflows/update_version.sh +0 -15
- package/.gitmodules +0 -9
- package/.releaserc +0 -90
- package/CITATION.cff +0 -11
- package/CMakeLists.txt +0 -324
- package/CODE_OF_CONDUCT.md +0 -128
- package/CONTRIBUTING.md +0 -361
- package/Cargo.toml +0 -19
- package/Dockerfile +0 -16
- package/VERSION +0 -1
- package/assets/unum.png +0 -0
- package/assets/usearch-approaches-transparent.png +0 -0
- package/assets/usearch-approaches-white.png +0 -0
- package/assets/usearch-neighbor-types.png +0 -0
- package/binding.gyp +0 -87
- package/build.gradle +0 -204
- package/build.rs +0 -18
- package/c/CMakeLists.txt +0 -25
- package/c/README.md +0 -34
- package/c/lib.cpp +0 -358
- package/c/test.c +0 -382
- package/c/usearch.h +0 -311
- package/cmake/clipp.cmake +0 -7
- package/cmake/config.cmake.in +0 -15
- package/cmake/emscripten.cmake +0 -8
- package/cmake/jemalloc.cmake +0 -62
- package/cmake/pkg-config.pc.in +0 -4
- package/cmake/usearchConfigVersion.cmake.in +0 -20
- package/conanfile.py +0 -26
- package/cpp/CMakeLists.txt +0 -14
- package/cpp/README.md +0 -161
- package/cpp/bench.cpp +0 -618
- package/cpp/test.cpp +0 -323
- package/fp16/CMakeLists.txt +0 -176
- package/fp16/LICENSE +0 -11
- package/fp16/README.md +0 -20
- package/fp16/bench/alt-element.cc +0 -89
- package/fp16/bench/from-alt-array.cc +0 -175
- package/fp16/bench/from-ieee-array.cc +0 -399
- package/fp16/bench/ieee-element.cc +0 -272
- package/fp16/bench/to-alt-array.cc +0 -91
- package/fp16/bench/to-ieee-array.cc +0 -303
- package/fp16/cmake/DownloadGoogleBenchmark.cmake +0 -15
- package/fp16/cmake/DownloadGoogleTest.cmake +0 -15
- package/fp16/cmake/DownloadPSimd.cmake +0 -15
- package/fp16/configure.py +0 -65
- package/fp16/confu.yaml +0 -8
- package/fp16/include/fp16/__init__.py +0 -0
- package/fp16/include/fp16/avx.py +0 -50
- package/fp16/include/fp16/avx2.py +0 -53
- package/fp16/include/fp16/bitcasts.h +0 -92
- package/fp16/include/fp16/fp16.h +0 -451
- package/fp16/include/fp16/psimd.h +0 -131
- package/fp16/include/fp16.h +0 -11
- package/fp16/jni/Android.mk +0 -6
- package/fp16/jni/Application.mk +0 -4
- package/fp16/test/alt-from-fp32-value.cc +0 -498
- package/fp16/test/alt-to-fp32-bits.cc +0 -263
- package/fp16/test/alt-to-fp32-psimd.cc +0 -145
- package/fp16/test/alt-to-fp32-value.cc +0 -348
- package/fp16/test/alt-to-fp32x2-psimd.cc +0 -245
- package/fp16/test/bitcasts.cc +0 -56
- package/fp16/test/ieee-from-fp32-value.cc +0 -523
- package/fp16/test/ieee-to-fp32-bits.cc +0 -333
- package/fp16/test/ieee-to-fp32-psimd.cc +0 -312
- package/fp16/test/ieee-to-fp32-value.cc +0 -420
- package/fp16/test/ieee-to-fp32x2-psimd.cc +0 -541
- package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +0 -96
- package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +0 -96
- package/fp16/test/peachpy/stubs.py +0 -38
- package/fp16/test/tables.cc +0 -530
- package/fp16/test/tables.h +0 -13
- package/fp16/third-party/THHalf.h +0 -92
- package/fp16/third-party/eigen-half.h +0 -170
- package/fp16/third-party/float16-compressor.h +0 -80
- package/fp16/third-party/half.hpp +0 -2916
- package/fp16/third-party/npy-halffloat.h +0 -328
- package/include/usearch/index.hpp +0 -3836
- package/include/usearch/index_dense.hpp +0 -2004
- package/include/usearch/index_plugins.hpp +0 -2213
- package/javascript/lib.cpp +0 -341
- package/javascript/types/usearch.d.ts.map +0 -1
- package/javascript/usearch.test.js +0 -74
- package/package-ci.json +0 -10
- package/pyproject.toml +0 -51
- package/setup.py +0 -201
- package/simsimd/.releaserc +0 -86
- package/simsimd/CONTRIBUTING.md +0 -88
- package/simsimd/Cargo.lock +0 -709
- package/simsimd/Cargo.toml +0 -44
- package/simsimd/LICENSE +0 -201
- package/simsimd/README.md +0 -317
- package/simsimd/binding.gyp +0 -36
- package/simsimd/build.rs +0 -20
- package/simsimd/include/simsimd/binary.h +0 -245
- package/simsimd/include/simsimd/complex.h +0 -174
- package/simsimd/include/simsimd/probability.h +0 -548
- package/simsimd/include/simsimd/simsimd.h +0 -465
- package/simsimd/include/simsimd/spatial.h +0 -1267
- package/simsimd/include/simsimd/types.h +0 -208
- package/simsimd/javascript/bench.js +0 -127
- package/simsimd/javascript/fallback.ts +0 -193
- package/simsimd/javascript/lib.c +0 -102
- package/simsimd/javascript/node-gyp-build.d.ts +0 -1
- package/simsimd/javascript/simsimd.ts +0 -124
- package/simsimd/javascript/test.mjs +0 -153
- package/simsimd/javascript/tsconfig-base.json +0 -25
- package/simsimd/javascript/tsconfig-cjs.json +0 -8
- package/simsimd/javascript/tsconfig-esm.json +0 -8
- package/simsimd/package-lock.json +0 -1688
- package/simsimd/package.json +0 -61
- package/simsimd/rust/benches/cosine.rs +0 -27
- package/simsimd/rust/benches/native.rs +0 -30
- package/simsimd/rust/benches/sqeuclidean.rs +0 -27
- package/simsimd/rust/lib.c +0 -45
- package/simsimd/rust/lib.rs +0 -550
- package/sqlite/README.md +0 -178
- package/sqlite/lib.cpp +0 -325
- package/stringzilla/CONTRIBUTING.md +0 -446
- package/stringzilla/Cargo.lock +0 -25
- package/stringzilla/Cargo.toml +0 -26
- package/stringzilla/LICENSE +0 -201
- package/stringzilla/README.md +0 -1422
- package/stringzilla/VERSION +0 -1
- package/stringzilla/assets/cover-strinzilla.jpeg +0 -0
- package/stringzilla/assets/meme-stringzilla-v2.jpeg +0 -0
- package/stringzilla/assets/meme-stringzilla-v3.jpeg +0 -0
- package/stringzilla/binding.gyp +0 -16
- package/stringzilla/build.rs +0 -87
- package/stringzilla/c/lib.c +0 -337
- package/stringzilla/cli/README.md +0 -65
- package/stringzilla/cli/__init__.py +0 -0
- package/stringzilla/cli/split.py +0 -105
- package/stringzilla/cli/wc.py +0 -117
- package/stringzilla/include/stringzilla/experimental.h +0 -845
- package/stringzilla/include/stringzilla/module.modulemap +0 -9
- package/stringzilla/include/stringzilla/stringzilla.h +0 -5370
- package/stringzilla/include/stringzilla/stringzilla.hpp +0 -3838
- package/stringzilla/javascript/lib.c +0 -125
- package/stringzilla/javascript/stringzilla.js +0 -22
- package/stringzilla/package-ci.json +0 -10
- package/stringzilla/package.json +0 -32
- package/stringzilla/rust/lib.rs +0 -873
- package/stringzilla/swift/StringProtocol+StringZilla.swift +0 -280
- package/stringzilla/swift/Test.swift +0 -60
- package/tsconfig.json +0 -21
- package/wasmer.toml +0 -12
- package/winlibinstaller.bat +0 -42
- /package/{simsimd/javascript/dist-package-cjs.json → javascript/dist/cjs/package.json} +0 -0
- /package/{simsimd/javascript/dist-package-esm.json → javascript/dist/esm/package.json} +0 -0
package/cmake/clipp.cmake
DELETED
package/cmake/config.cmake.in
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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()
|
package/cmake/emscripten.cmake
DELETED
package/cmake/jemalloc.cmake
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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 ()
|
package/cmake/pkg-config.pc.in
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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()
|
package/conanfile.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
from conans import ConanFile
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
required_conan_version = ">=1.53.0"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class USearchConan(ConanFile):
|
|
8
|
-
|
|
9
|
-
name = "usearch"
|
|
10
|
-
version = '2.9.2'
|
|
11
|
-
license = "Apache-2.0"
|
|
12
|
-
description = "Smaller & Faster Single-File Vector Search Engine from Unum"
|
|
13
|
-
homepage = "https://github.com/unum-cloud/usearch"
|
|
14
|
-
topics = ("search", "vector", "simd")
|
|
15
|
-
settings = "os", "arch", "compiler", "build_type"
|
|
16
|
-
url = "https://github.com/conan-io/conan-center-index"
|
|
17
|
-
package_type = "header-library"
|
|
18
|
-
|
|
19
|
-
# No settings/options are necessary, this is header only
|
|
20
|
-
# Potentially add unit-tests in the future:
|
|
21
|
-
# https://docs.conan.io/1/howtos/header_only.html#with-unit-tests
|
|
22
|
-
exports_sources = "include/*"
|
|
23
|
-
no_copy_source = True
|
|
24
|
-
|
|
25
|
-
def package(self):
|
|
26
|
-
self.copy("*.h")
|
package/cpp/CMakeLists.txt
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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 ()
|
package/cpp/README.md
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
# USearch for C++
|
|
2
|
-
|
|
3
|
-
## Installation
|
|
4
|
-
|
|
5
|
-
To use in a C++ project, copy the `include/usearch/*` headers into your project.
|
|
6
|
-
Alternatively, fetch it with CMake:
|
|
7
|
-
|
|
8
|
-
```cmake
|
|
9
|
-
FetchContent_Declare(usearch GIT_REPOSITORY https://github.com/unum-cloud/usearch.git)
|
|
10
|
-
FetchContent_MakeAvailable(usearch)
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Quickstart
|
|
14
|
-
|
|
15
|
-
Once included, the high-level C++11 interface is as simple as it gets: `reserve()`, `add()`, `search()`, `size()`, `capacity()`, `save()`, `load()`, `view()`.
|
|
16
|
-
This covers 90% of use cases.
|
|
17
|
-
|
|
18
|
-
```cpp
|
|
19
|
-
using namespace unum::usearch;
|
|
20
|
-
|
|
21
|
-
metric_punned_t metric(256, metric_kind_t::l2sq_k, scalar_kind_t::f32_k);
|
|
22
|
-
|
|
23
|
-
// If you plan to store more than 4 Billion entries - use `index_dense_big_t`.
|
|
24
|
-
// Or directly instantiate the template variant you need - `index_dense_gt<vector_key_t, internal_id_t>`.
|
|
25
|
-
index_dense_t index = index_dense_t::make(metric);
|
|
26
|
-
float vec[3] = {0.1, 0.3, 0.2};
|
|
27
|
-
|
|
28
|
-
index.reserve(10); // Pre-allocate memory for 10 vectors
|
|
29
|
-
index.add(42, &vec[0]); // Pass a key and a vector
|
|
30
|
-
auto results = index.search(&vec[0], 5); // Pass a query and limit number of results
|
|
31
|
-
|
|
32
|
-
for (std::size_t i = 0; i != results.size(); ++i)
|
|
33
|
-
results[i].element.key, results[i].element.vector, results[i].distance;
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Here we:
|
|
37
|
-
|
|
38
|
-
- define a metric of kind [`metric_kind_t::l2sq_k`](https://unum-cloud.github.io/usearch/cpp/reference.html#_CPPv413metric_kind_t),
|
|
39
|
-
- to be applied to [`scalar_kind_t::f32_k`](https://unum-cloud.github.io/usearch/cpp/reference.html#_CPPv413scalar_kind_t) floating-point vectors,
|
|
40
|
-
- instantiate an [`index_dense_t`](https://unum-cloud.github.io/usearch/cpp/reference.html#_CPPv4I00EN4unum7usearch14index_dense_gtE) index.
|
|
41
|
-
|
|
42
|
-
The `add` is thread-safe for concurrent index construction.
|
|
43
|
-
It also has an overload for different vector types, casting them under the hood.
|
|
44
|
-
The same applies to the `search`, `get`, `cluster`, and `distance_between` functions.
|
|
45
|
-
|
|
46
|
-
```cpp
|
|
47
|
-
double vec_double[3] = {0.1, 0.3, 0.2};
|
|
48
|
-
_Float16 vec_half[3] = {0.1, 0.3, 0.2};
|
|
49
|
-
index.add(43, {&vec_double[0], 3});
|
|
50
|
-
index.add(44, {&vec_half[0], 3});
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Serialization
|
|
54
|
-
|
|
55
|
-
```cpp
|
|
56
|
-
index.save("index.usearch");
|
|
57
|
-
index.load("index.usearch"); // Copying from disk
|
|
58
|
-
index.view("index.usearch"); // Memory-mapping from disk
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## Multi-Threading
|
|
62
|
-
|
|
63
|
-
Most AI, HPC, or Big Data packages use some form of a thread pool.
|
|
64
|
-
Instead of spawning additional threads within USearch, we focus on the thread safety of `add()` function, simplifying resource management.
|
|
65
|
-
|
|
66
|
-
```cpp
|
|
67
|
-
#pragma omp parallel for
|
|
68
|
-
for (std::size_t i = 0; i < n; ++i)
|
|
69
|
-
native.add(key, span_t{vector, dims});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
During initialization, we allocate enough temporary memory for all the cores on the machine.
|
|
73
|
-
On the call, the user can supply the identifier of the current thread, making this library easy to integrate with OpenMP and similar tools.
|
|
74
|
-
|
|
75
|
-
Moreover, you can take advantage of one of the provided "executors" to parallelize the search:
|
|
76
|
-
|
|
77
|
-
- `executor_openmp_t`, that would use OpenMP under the hood.
|
|
78
|
-
- `executor_stl_t`, that will spawn `std::thread` instances.
|
|
79
|
-
- `dummy_executor_t`, that will run everything sequentially.
|
|
80
|
-
|
|
81
|
-
## Clustering
|
|
82
|
-
|
|
83
|
-
Aside from basic Create-Read-Update-Delete (CRUD) operations and search, USearch also supports clustering.
|
|
84
|
-
Once the index is constructed, you can either:
|
|
85
|
-
|
|
86
|
-
- Identify a cluster to which any external vector belongs, once mapped onto the index.
|
|
87
|
-
- Split the entire index into a set of clusters, each with its own centroid.
|
|
88
|
-
|
|
89
|
-
For the first, the interface accepts a vector and a "clustering level", which is essentially the index of the HNSW graph layer, in which to search.
|
|
90
|
-
If you pass zero, the traversal will happen in every level except the bottom one.
|
|
91
|
-
Otherwise, the search will be limited to the specified level.
|
|
92
|
-
|
|
93
|
-
```cpp
|
|
94
|
-
some_scalar_t vector[3] = {0.1, 0.3, 0.2};
|
|
95
|
-
cluster_result_t result = index.cluster(&vector, index.max_level() / 2);
|
|
96
|
-
match_t cluster = result.cluster;
|
|
97
|
-
member_cref_t member = cluster.member;
|
|
98
|
-
distance_t distance = cluster.distance;
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
If you wish to split the whole structure into clusters, you must provide an iterator over a range of vectors, that will be processed in parallel using the previously described function.
|
|
102
|
-
Unlike the previous function, you don't have to manually specify the level, as the algorithm will pick the best one for you, depending on the number of clusters you want to highlight.
|
|
103
|
-
Aside from that auto-tuning, this function will regroup some of the clusters, if they are too small, and return the final number of clusters.
|
|
104
|
-
|
|
105
|
-
```cpp
|
|
106
|
-
std::size_t queries_count = queries_end - queries_begin;
|
|
107
|
-
index_dense_clustering_config_t config;
|
|
108
|
-
config.min_clusters = 1000;
|
|
109
|
-
config.max_clusters = 2000;
|
|
110
|
-
config.mode = index_dense_clustering_config_t::merge_smallest_k;
|
|
111
|
-
|
|
112
|
-
// Outputs:
|
|
113
|
-
vector_key_t cluster_centroids_keys[queries_count];
|
|
114
|
-
distance_t distances_to_cluster_centroids[queries_count];
|
|
115
|
-
executor_default_t thread_pool;
|
|
116
|
-
dummy_progress_t progress_bar;
|
|
117
|
-
|
|
118
|
-
clustering_result_t result = cluster(
|
|
119
|
-
queries_begin, queries_end,
|
|
120
|
-
config,
|
|
121
|
-
&cluster_centroids_keys, &distances_to_cluster_centroids,
|
|
122
|
-
thread_pool, progress_bar);
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
This approach requires basic understanding of templates meta-programming to implement the `queries_begin` and `queries_end` smart-iterators.
|
|
126
|
-
On the bright side, it allows iteratively deepening into a specific cluster.
|
|
127
|
-
|
|
128
|
-
As in many other bulk-processing APIs, the `executor` and `progress` are optional.
|
|
129
|
-
|
|
130
|
-
## User-Defined Metrics
|
|
131
|
-
|
|
132
|
-
In its high-level interface, USearch supports a variety of metrics, including the most popular ones:
|
|
133
|
-
|
|
134
|
-
- `metric_cos_gt<scalar_t>` for "Cosine" or "Angular" distance.
|
|
135
|
-
- `metric_ip_gt<scalar_t>` for "Inner Product" or "Dot Product" distance.
|
|
136
|
-
- `metric_l2sq_gt<scalar_t>` for the squared "L2" or "Euclidean" distance.
|
|
137
|
-
- `metric_jaccard_gt<scalar_t>` for "Jaccard" distance between two ordered sets of unique elements.
|
|
138
|
-
- `metric_hamming_gt<scalar_t>` for "Hamming" distance, as the number of shared bits in hashes.
|
|
139
|
-
- `metric_tanimoto_gt<scalar_t>` for "Tanimoto" coefficient for bit-strings.
|
|
140
|
-
- `metric_sorensen_gt<scalar_t>` for "Dice-Sorensen" coefficient for bit-strings.
|
|
141
|
-
- `metric_pearson_gt<scalar_t>` for "Pearson" correlation between probability distributions.
|
|
142
|
-
- `metric_haversine_gt<scalar_t>` for "Haversine" or "Great Circle" distance between coordinates used in GIS applications.
|
|
143
|
-
- `metric_divergence_gt<scalar_t>` for the "Jensen Shannon" similarity between probability distributions.
|
|
144
|
-
|
|
145
|
-
In reality, for most common types, one of the [SimSIMD](https://github.com/ashvardanian/SimSIMD) backends will be triggered, providing hardware-acceleration for most common CPUs.
|
|
146
|
-
|
|
147
|
-
If you need a different metric, you can implement it yourself and wrap it into a `metric_punned_t`, which is our alternative to the `std::function`.
|
|
148
|
-
Unlike the `std::function`, it is a trivial type, which is important for performance.
|
|
149
|
-
|
|
150
|
-
## Advanced Interface
|
|
151
|
-
|
|
152
|
-
If you are proficient in C++ and ready to get your hands dirty, you can use the low-level interface.
|
|
153
|
-
|
|
154
|
-
```cpp
|
|
155
|
-
template <typename distance_at = default_distance_t, // `float`
|
|
156
|
-
typename key_at = default_key_t, // `int64_t`, `uuid_t`
|
|
157
|
-
typename compressed_slot_at = default_slot_t, // `uint32_t`, `uint40_t`
|
|
158
|
-
typename dynamic_allocator_at = std::allocator<byte_t>, //
|
|
159
|
-
typename tape_allocator_at = dynamic_allocator_at> //
|
|
160
|
-
class index_gt;
|
|
161
|
-
```
|