commit bb92345683929d2331c76d6e2dba64e774c81881 Author: Chen Lixiang Date: Thu Jun 29 17:03:35 2023 +0800 init hnswlab diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e45a29a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +*.out +*.exe \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a2da730 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +set(CMAKE_DEBUG_POSTFIX "_d") +set(CMAKE_RELEASE_POSTFIX "_r") +set_target_properties(${TARGET_NAME} PROPERTIES DEBUG_POSTFIX "_d") +set_target_properties(${TARGET_NAME} PROPERTIES RELEASE_POSTFIX "_r") +cmake_minimum_required(VERSION 3.1) +project("hnswlab") +set(CMAKE_C_STANDARD 11) + +# generate .so file +include_directories(inc) +add_library(hnswc +SHARED + src/utils.c + src/hnsw.c +) + +add_executable(hnsw_test src/test.c) +target_link_libraries(hnsw_test hnswc) diff --git a/README.md b/README.md new file mode 100644 index 0000000..a14e22e --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# HNSW-Lab diff --git a/dataset/.gitkeep b/dataset/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/inc/hnsw.h b/inc/hnsw.h new file mode 100644 index 0000000..43a0439 --- /dev/null +++ b/inc/hnsw.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include "utils.h" + +typedef struct NSWGraph +{ + +} NSWGraph; + +typedef struct HNSWGraph +{ + size_t layers_num; // number of layers + NSWGraph **layers; +} HNSWGraph; + +typedef struct HNSWContext +{ + size_t dim; // dimension of dataset + size_t len; // size of dataset + HNSWGraph *graph; // graph of HNSW +} HNSWContext; + +// help functions + +// public functions +HNSWContext *init_hnsw_context(const char *file_path, size_t dim, size_t len); +void insert_vec(HNSWContext *ctx, VecData vec); +void approximate_knn(HNSWContext *ctx, VecData *results); diff --git a/inc/utils.h b/inc/utils.h new file mode 100644 index 0000000..090093e --- /dev/null +++ b/inc/utils.h @@ -0,0 +1,6 @@ + +typedef char* VecData; + +float vec_dist(VecData x, VecData y); + + diff --git a/src/hnsw.c b/src/hnsw.c new file mode 100644 index 0000000..5fe4992 --- /dev/null +++ b/src/hnsw.c @@ -0,0 +1,2 @@ +#include "hnsw.h" + diff --git a/src/test.c b/src/test.c new file mode 100644 index 0000000..4721e0e --- /dev/null +++ b/src/test.c @@ -0,0 +1,8 @@ +#include +#include "hnsw.h" +#include "utils.h" + +int main() { + printf("Hello, world!\n"); + return 0; +} \ No newline at end of file diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..e69de29