Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
replace diskann distance function by faiss distance function (#634)
Browse files Browse the repository at this point in the history
Signed-off-by: cqy123456 <[email protected]>
  • Loading branch information
cqy123456 authored Jan 13, 2023
1 parent 747cd46 commit 9a9aac5
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 1,218 deletions.
2 changes: 0 additions & 2 deletions knowhere/index/vector_index/IndexDiskANN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,4 @@ IndexDiskANN<T>::GetCachedNodeNum(const float cache_dram_budget, const uint64_t

// Explicit template instantiation
template class IndexDiskANN<float>;
template class IndexDiskANN<uint8_t>;
template class IndexDiskANN<int8_t>;
} // namespace knowhere
3 changes: 1 addition & 2 deletions knowhere/index/vector_index/IndexDiskANN.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ namespace knowhere {

template <typename T>
class IndexDiskANN : public VecIndex {
static_assert(std::is_same_v<T, float> || std::is_same_v<T, int8_t> || std::is_same_v<T, uint8_t>,
"DiskANN only support float, int8 and uint8");
static_assert(std::is_same_v<T, float>, "DiskANN only support float");

public:
explicit IndexDiskANN(std::string index_prefix, MetricType metric_type, std::shared_ptr<FileManager> file_manager);
Expand Down
13 changes: 4 additions & 9 deletions python/knowhere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@ def CreateIndexDiskANN(index_name, index_prefix, metric_type, simd_type="auto"):

if index_name == "diskann_f":
return buildDiskANNf(index_prefix, metric_type)
if index_name == "diskann_i8":
return buildDiskANNi8(index_prefix, metric_type)
if index_name == "diskann_ui8":
return buildDiskANNui8(index_prefix, metric_type)
raise ValueError(
""" index name only support
'diskann_f' 'diskann_i8' 'diskann_ui8'."""
""" index name only support 'diskann_f'. """
)


Expand All @@ -67,15 +62,15 @@ def CreateAsyncIndex(index_name, index_prefix="", metric_type="", simd_type="aut

if index_name not in ["bin_flat", "bin_ivf_flat", "flat", "ivf_flat", "ivf_pq", "ivf_sq8",
"hnsw", "annoy", "gpu_flat", "gpu_ivf_flat",
"gpu_ivf_pq", "gpu_ivf_sq8", "diskann_f", "diskann_i8", "diskann_ui8"]:
"gpu_ivf_pq", "gpu_ivf_sq8", "diskann_f"]:
raise ValueError(
""" index name only support
'bin_flat', 'bin_ivf_flat', 'flat', 'ivf_flat', 'ivf_pq', 'ivf_sq8',
'hnsw', 'annoy', 'gpu_flat', 'gpu_ivf_flat',
'gpu_ivf_pq', 'gpu_ivf_sq8', 'diskann_f', 'diskann_i8', 'diskann_ui8'."""
'gpu_ivf_pq', 'gpu_ivf_sq8', 'diskann_f'."""
)

if index_name in ["diskann_f", "diskann_i8", "diskann_ui8"]:
if index_name == "diskann_f":
if index_prefix == "":
raise ValueError("Must pass index_prefix to DiskANN")
if metric_type == "":
Expand Down
18 changes: 0 additions & 18 deletions python/knowhere/knowhere.i
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ import_array();
%template(DatasetPtr) std::shared_ptr<Dataset>;
#ifdef KNOWHERE_WITH_DISKANN
%shared_ptr(knowhere::IndexDiskANN<float>)
%shared_ptr(knowhere::IndexDiskANN<int8_t>)
%shared_ptr(knowhere::IndexDiskANN<uint8_t>)
#endif
%shared_ptr(knowhere::AsyncIndex)
%include <common/Dataset.h>
Expand Down Expand Up @@ -130,8 +128,6 @@ import_array();
// Support for DiskANN
#ifdef KNOWHERE_WITH_DISKANN
%template(IndexDiskANNf) knowhere::IndexDiskANN<float>;
%template(IndexDiskANNi8) knowhere::IndexDiskANN<int8_t>;
%template(IndexDiskANNui8) knowhere::IndexDiskANN<uint8_t>;

%inline %{

Expand All @@ -145,20 +141,6 @@ buildDiskANNf(std::string index_prefix, std::string metric_type) {
std::shared_ptr<knowhere::FileManager>(new knowhere::LocalFileManager));
}

std::shared_ptr<knowhere::IndexDiskANN<int8_t>>
buildDiskANNi8(std::string index_prefix, std::string metric_type) {
TOUPPER(metric_type);
return std::make_shared<knowhere::IndexDiskANN<int8_t>>(index_prefix, metric_type,
std::shared_ptr<knowhere::FileManager>(new knowhere::LocalFileManager));
}

std::shared_ptr<knowhere::IndexDiskANN<uint8_t>>
buildDiskANNui8(std::string index_prefix, std::string metric_type) {
TOUPPER(metric_type);
return std::make_shared<knowhere::IndexDiskANN<uint8_t>>(index_prefix, metric_type,
std::shared_ptr<knowhere::FileManager>(new knowhere::LocalFileManager));
}

%}
#endif

Expand Down
4 changes: 2 additions & 2 deletions thirdparty/DiskANN/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ else()
set(ENV{TCMALLOC_LARGE_ALLOC_REPORT_THRESHOLD} 500000000000)
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -DDEBUG -O0 -fsanitize=address -fsanitize=leak -fsanitize=undefined")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -DDEBUG -Wall -Wextra")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -DELPP_DISABLE_DEBUG_LOGS -DNDEBUG -march=skylake -ftree-vectorize")
add_compile_options(-march=skylake -Wall -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -fopenmp -fopenmp-simd -funroll-loops -Wfatal-errors -DUSE_AVX2)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -DELPP_DISABLE_DEBUG_LOGS -DNDEBUG -ftree-vectorize")
add_compile_options(-Wall -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -fopenmp -fopenmp-simd -funroll-loops -Wfatal-errors)
endif()

add_definitions( -DAUTO_INITIALIZE_EASYLOGGINGPP )
Expand Down
275 changes: 0 additions & 275 deletions thirdparty/DiskANN/include/cosine_similarity.h

This file was deleted.

Loading

0 comments on commit 9a9aac5

Please sign in to comment.