Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/configure-cmake/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

###############################################################################

Expand Down Expand Up @@ -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 ${<SomeLib>_SOURCE_DIR}/include)
# target_link_directories(${MAIN_EXECUTABLE_NAME} PRIVATE ${<SomeLib>_BINARY_DIR}/lib)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<!-- renovate: datasource=github-tags depName=ashvardanian/simsimd versioning=loose -->
- Versiune: [v6.5.13](https://github.com/ashvardanian/simsimd) (Apache 2.0)
- [NumKong](https://github.com/ashvardanian/NumKong)
<!-- renovate: datasource=github-tags depName=ashvardanian/NumKong versioning=loose -->
- 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
6 changes: 3 additions & 3 deletions cmake/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

###############################################################################

Expand All @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// #include "Example.h"

///////////////////////////////////////////////////////////////////
//// Vom folosi simsimd pentru a calcula similaritatea cosinus ////
#include <simsimd/simsimd.h> ////
//// Vom folosi numkong pentru a calcula similaritatea cosinus ////
#include <numkong/numkong.h> ////
///////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -39,7 +39,7 @@

const std::string API_URL = "http://127.0.0.1:8080";

std::vector<simsimd_f32_t> getEmbeddings(const std::string& word)
std::vector<nk_f32_t> getEmbeddings(const std::string& word)
{
std::string api_url = API_URL;
if(const auto* url = std::getenv("LLM_URL")) {
Expand Down Expand Up @@ -79,7 +79,7 @@ std::vector<simsimd_f32_t> getEmbeddings(const std::string& word)
}

json json_resp = json::parse(res.text); // Parsăm răspunsul primit
std::vector<simsimd_f32_t> embedding = json_resp["embedding"];
std::vector<nk_f32_t> embedding = json_resp["embedding"];
// std::cout << json_resp["embedding"].size() << std::endl;
return embedding;
}
Expand Down Expand Up @@ -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";
Expand Down
22 changes: 21 additions & 1 deletion scripts/valgrind-suppressions.supp
Original file line number Diff line number Diff line change
Expand Up @@ -3327,5 +3327,25 @@
ioctl(TCSET{S,SW,SF})
fun:tcsetattr
...
fun:main
}

{
<ftxui_tcsetattr_uninit_param>
Memcheck:Param
ioctl(TCSETS)
fun:tcsetattr
...
}
{
<ftxui_tcsetattr_uninit_param_generic>
Memcheck:Param
ioctl(generic)
fun:tcsetattr
...
}
{
<ftxui_tcsetattr_uninit_speed>
Memcheck:Value8
fun:*cbaud_to_speed*
...
}