mirror of
https://github.com/wolfpld/tracy.git
synced 2026-08-13 08:40:04 +00:00
Add vector database.
This commit is contained in:
@@ -271,3 +271,12 @@ CPMAddPackage(
|
||||
GIT_TAG v3.12.0
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
|
||||
# usearch
|
||||
|
||||
CPMAddPackage(
|
||||
NAME usearch
|
||||
GITHUB_REPOSITORY unum-cloud/usearch
|
||||
GIT_TAG v2.17.7
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
|
||||
@@ -61,6 +61,7 @@ set(SERVER_FILES
|
||||
TracyImGui.cpp
|
||||
TracyLlm.cpp
|
||||
TracyLlmApi.cpp
|
||||
TracyLlmEmbeddings.cpp
|
||||
TracyLlmTools.cpp
|
||||
TracyMicroArchitecture.cpp
|
||||
TracyMouse.cpp
|
||||
@@ -221,7 +222,7 @@ else()
|
||||
endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyImGui Threads::Threads TracyLibcurl base64 tidy-static TracyPugixml nlohmann_json::nlohmann_json)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyImGui Threads::Threads TracyLibcurl base64 tidy-static TracyPugixml nlohmann_json::nlohmann_json usearch)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${tidy_SOURCE_DIR}/include)
|
||||
|
||||
if(NOT DEFINED GIT_REV)
|
||||
|
||||
34
profiler/src/profiler/TracyLlmEmbeddings.cpp
Normal file
34
profiler/src/profiler/TracyLlmEmbeddings.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "TracyLlmEmbeddings.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
TracyLlmEmbeddings::TracyLlmEmbeddings( size_t length, size_t reserve )
|
||||
{
|
||||
unum::usearch::metric_punned_t metric( length );
|
||||
m_index = unum::usearch::index_dense_t::make( metric );
|
||||
if( reserve > 0 ) m_index.reserve( reserve );
|
||||
}
|
||||
|
||||
void TracyLlmEmbeddings::Add( std::string str, const std::vector<float>& embedding )
|
||||
{
|
||||
m_index.add( m_data.size(), embedding.data() );
|
||||
m_data.emplace_back( std::move( str ) );
|
||||
}
|
||||
|
||||
std::vector<TracyLlmEmbeddings::Result> TracyLlmEmbeddings::Search( const std::vector<float>& embedding, size_t k ) const
|
||||
{
|
||||
std::vector<Result> ret;
|
||||
auto result = m_index.search( embedding.data(), k );
|
||||
ret.reserve( result.size() );
|
||||
for( size_t i=0; i<result.size(); i++ )
|
||||
{
|
||||
ret.emplace_back( Result {
|
||||
.idx = result[i].member.key,
|
||||
.distance = result[i].distance
|
||||
} );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
34
profiler/src/profiler/TracyLlmEmbeddings.hpp
Normal file
34
profiler/src/profiler/TracyLlmEmbeddings.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef __TRACYLLMEMBEDDINGS_HPP__
|
||||
#define __TRACYLLMEMBEDDINGS_HPP__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
#include <usearch/index_dense.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class TracyLlmEmbeddings
|
||||
{
|
||||
public:
|
||||
struct Result
|
||||
{
|
||||
size_t idx;
|
||||
float distance;
|
||||
};
|
||||
|
||||
explicit TracyLlmEmbeddings( size_t length, size_t reserve = 0 );
|
||||
|
||||
void Add( std::string str, const std::vector<float>& embedding );
|
||||
[[nodiscard]] std::vector<Result> Search( const std::vector<float>& embedding, size_t k ) const;
|
||||
[[nodiscard]] const std::string& Get( size_t idx ) const { return m_data[idx]; }
|
||||
|
||||
private:
|
||||
unum::usearch::index_dense_t m_index;
|
||||
std::vector<std::string> m_data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user