diff --git a/.github/actions/configure-cmake/action.yml b/.github/actions/configure-cmake/action.yml index 3ae6806d..c780a212 100644 --- a/.github/actions/configure-cmake/action.yml +++ b/.github/actions/configure-cmake/action.yml @@ -25,7 +25,7 @@ runs: with: path: | ${{ env.BUILD_DIR }}/_deps - key: ${{ inputs.cache_key }}-${{ matrix.cmake_generator }}-${{ matrix.os }}-${{ matrix.cxx }}-${{ matrix.asan_name }}-${{ env.BUILD_TYPE }}-${{ env.CPR_VERSION }} + key: ${{ inputs.cache_key }}-${{ matrix.cmake_generator }}-${{ matrix.os }}-${{ matrix.cxx }}-${{ matrix.asan_name }}-${{ env.BUILD_TYPE }}-${{ env.CPR_VERSION }}-${{ env.NUMKONG_VERSION }} # NOTE: GH Actions does not allow updating the cache yet # Using the workaround found here: https://github.com/actions/cache/issues/171 diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 01813c67..bf1c423e 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -31,6 +31,9 @@ env: BIN_DIR: "bin" # update in cmake/Options.cmake:6 if changing name here BUILD_DIR: "build" EXT_DIR: "ext" + # NOTE: keep in sync with GIT_TAG in CMakeLists.txt; only used to invalidate the _deps cache + # renovate: datasource=github-tags depName=ashvardanian/NumKong versioning=loose + NUMKONG_VERSION: "v7.8.2" defaults: diff --git a/CMakeLists.txt b/CMakeLists.txt index aaec036c..0d7575ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,17 +52,18 @@ FetchContent_Declare( GIT_PROGRESS ON ) +# NOTE: Also update NUMKONG_VERSION in .github/workflows/cmake.yml FetchContent_Declare( - simsimd + numkong SYSTEM - GIT_REPOSITORY https://github.com/ashvardanian/simsimd.git - # renovate: datasource=github-tags depName=ashvardanian/simsimd versioning=loose - GIT_TAG v6.5.13 + GIT_REPOSITORY https://github.com/ashvardanian/NumKong.git + # renovate: datasource=github-tags depName=ashvardanian/NumKong versioning=loose + GIT_TAG v7.8.2 GIT_SHALLOW 1 GIT_PROGRESS ON ) -FetchContent_MakeAvailable(cpr simsimd) +FetchContent_MakeAvailable(cpr numkong) ############################################################################### @@ -98,7 +99,7 @@ target_include_directories(${MAIN_EXECUTABLE_NAME} SYSTEM PRIVATE ext ext/include/json ${cpr_SOURCE_DIR}/include - ${simsimd_SOURCE_DIR}/include + ${numkong_SOURCE_DIR}/include ) # target_include_directories(${MAIN_EXECUTABLE_NAME} SYSTEM PRIVATE ${_SOURCE_DIR}/include) # target_link_directories(${MAIN_EXECUTABLE_NAME} PRIVATE ${_BINARY_DIR}/lib) diff --git a/README.md b/README.md index 0c2738dd..0d9ca658 100644 --- a/README.md +++ b/README.md @@ -194,8 +194,8 @@ The [template repository](https://github.com/mcmarius/oop-template) itself is li - Versiune: [v3.11.3](https://github.com/nlohmann/json/releases/tag/v3.11.3) (MIT) - [llamafile](https://github.com/Mozilla-Ocho/llamafile) - Versiune: [v0.9.1](https://github.com/Mozilla-Ocho/llamafile) (Apache 2.0) -- [simsimd](https://github.com/ashvardanian/simsimd) - - - Versiune: [v6.5.13](https://github.com/ashvardanian/simsimd) (Apache 2.0) +- [NumKong](https://github.com/ashvardanian/NumKong) + + - Versiune: [v7.8.2](https://github.com/ashvardanian/NumKong) (Apache 2.0) - pentru similaritate cosinus - adăugați trimiteri **detaliate** către resursele externe care v-au ajutat sau pe care le-ați folosit diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index acd00127..c0ecdf1c 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -17,8 +17,8 @@ function(set_compiler_flags) message("NOTE: GITHUB_ACTIONS defined") target_compile_definitions(${TARGET_NAME} PRIVATE GITHUB_ACTIONS) endif() - target_compile_definitions(${TARGET_NAME} PRIVATE SIMSIMD_NATIVE_F16=0) - target_compile_definitions(${TARGET_NAME} PRIVATE SIMSIMD_NATIVE_BF16=0) + target_compile_definitions(${TARGET_NAME} PRIVATE NK_NATIVE_F16=0) + target_compile_definitions(${TARGET_NAME} PRIVATE NK_NATIVE_BF16=0) ############################################################################### @@ -37,7 +37,7 @@ function(set_compiler_flags) ############################################################################### # sanitizers - if("${ARG_RUN_SANITIZERS}" STREQUAL "TRUE") + if(ARG_RUN_SANITIZERS) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") else() set_custom_stdlib_and_sanitizers(cpr false) diff --git a/main.cpp b/main.cpp index b5ffa654..ad62d03b 100644 --- a/main.cpp +++ b/main.cpp @@ -7,8 +7,8 @@ // #include "Example.h" /////////////////////////////////////////////////////////////////// -//// Vom folosi simsimd pentru a calcula similaritatea cosinus //// -#include //// +//// Vom folosi numkong pentru a calcula similaritatea cosinus //// +#include //// /////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// @@ -39,7 +39,7 @@ const std::string API_URL = "http://127.0.0.1:8080"; -std::vector getEmbeddings(const std::string& word) +std::vector getEmbeddings(const std::string& word) { std::string api_url = API_URL; if(const auto* url = std::getenv("LLM_URL")) { @@ -79,7 +79,7 @@ std::vector getEmbeddings(const std::string& word) } json json_resp = json::parse(res.text); // Parsăm răspunsul primit - std::vector embedding = json_resp["embedding"]; + std::vector embedding = json_resp["embedding"]; // std::cout << json_resp["embedding"].size() << std::endl; return embedding; } @@ -161,9 +161,11 @@ int main() auto emb1 = getEmbeddings(word1); auto emb2 = getEmbeddings(word2); - simsimd_distance_t distance; - simsimd_cos_f32(emb1.data(), emb2.data(), emb1.size(), &distance); - std::cout << "similarity " << word1 << " - " << word2 << ": " << distance << "\n"; + // distanța angulară (1 - cosinusul unghiului dintre vectori): + // cu cât vectorii sunt mai similari, cu cât distanța e mai aproape de 0 + nk_f64_t distance{}; + nk_angular_f32(emb1.data(), emb2.data(), emb1.size(), &distance); + std::cout << "angular distance (1 - cos) " << word1 << " - " << word2 << ": " << distance << "\n"; // not very reliable, varies too much, not deterministic // std::cout << "score: " << getScore(word1, word2) << "\n"; diff --git a/scripts/valgrind-suppressions.supp b/scripts/valgrind-suppressions.supp index 3e71ec85..3b3dc468 100644 --- a/scripts/valgrind-suppressions.supp +++ b/scripts/valgrind-suppressions.supp @@ -3327,5 +3327,25 @@ ioctl(TCSET{S,SW,SF}) fun:tcsetattr ... - fun:main +} + +{ + + Memcheck:Param + ioctl(TCSETS) + fun:tcsetattr + ... +} +{ + + Memcheck:Param + ioctl(generic) + fun:tcsetattr + ... +} +{ + + Memcheck:Value8 + fun:*cbaud_to_speed* + ... }