Skip to content

Commit

Permalink
Add patch to support multi vector in faiss
Browse files Browse the repository at this point in the history
  • Loading branch information
heemin32 committed Dec 20, 2023
1 parent 1d5fc83 commit 7d68d8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
18 changes: 11 additions & 7 deletions jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ list(APPEND TARGET_LIBS ${TARGET_LIB_COMMON})
# ---------------------------------- NMSLIB ----------------------------------
if (${CONFIG_NMSLIB} STREQUAL ON OR ${CONFIG_ALL} STREQUAL ON OR ${CONFIG_TEST} STREQUAL ON)
# Check if nmslib exists
find_path(NMS_REPO_DIR NAMES similarity_search PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib)
find_path(NMS_REPO_DIR NAMES similarity_search PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib NO_DEFAULT_PATH)

# If not, pull the updated submodule
if (NOT EXISTS ${NMS_REPO_DIR})
Expand Down Expand Up @@ -117,13 +117,13 @@ if (${CONFIG_FAISS} STREQUAL ON OR ${CONFIG_ALL} STREQUAL ON OR ${CONFIG_TEST} S
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib)
set(OpenMP_omp_LIBRARY /opt/homebrew/opt/llvm/lib/libomp.dylib)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/opt/llvm/include")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib)
set(OpenMP_omp_LIBRARY /opt/homebrew/opt/llvm/lib/libomp.dylib)
endif()
endif()

Expand All @@ -134,16 +134,20 @@ if (${CONFIG_FAISS} STREQUAL ON OR ${CONFIG_ALL} STREQUAL ON OR ${CONFIG_TEST} S
find_package(LAPACK REQUIRED)

# Check if faiss exists
find_path(FAISS_REPO_DIR NAMES faiss PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss)
find_path(FAISS_REPO_DIR NAMES faiss PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss NO_DEFAULT_PATH)

# If not, pull the updated submodule and apply patches
if (NOT EXISTS ${FAISS_REPO_DIR})
message(STATUS "Could not find faiss. Pulling updated submodule.")
execute_process(COMMAND git submodule update --init -- external/faiss WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS "Applying custom patches.")
execute_process(COMMAND git apply --directory=external/faiss patches/faiss/multi-vector-support.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif ()

message(STATUS "Applying custom patches.")
execute_process(COMMAND git apply --3way ${CMAKE_CURRENT_SOURCE_DIR}/patches/faiss/0001-Custom-patch-to-support-multi-vector.patch WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/faiss ERROR_VARIABLE ERROR_MSG RESULT_VARIABLE RESULT_CODE)
if(RESULT_CODE)
message(FATAL_ERROR "Failed to apply patch:\n${ERROR_MSG}")
endif()

set(FAISS_ENABLE_GPU OFF)
set(FAISS_ENABLE_PYTHON OFF)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/faiss EXCLUDE_FROM_ALL)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
commit a97473e0c816fa1213ab97ac340d932bfd265b9b
Author: Heemin Kim <[email protected]>
Date: Wed Dec 6 16:33:52 2023 -0800
From 6bd27053e20e133991c0b2c03c7836d78d5079c8 Mon Sep 17 00:00:00 2001
From: Heemin Kim <[email protected]>
Date: Wed, 6 Dec 2023 16:33:52 -0800
Subject: [PATCH] Custom patch to support multi-vector

Introduce result collector for HNSW
Signed-off-by: Heemin Kim <[email protected]>
---
faiss/CMakeLists.txt | 2 +
faiss/Index.h | 6 ++-
faiss/IndexIDMap.cpp | 19 ++++++++++
faiss/IndexIDMap.h | 1 +
faiss/impl/HNSW.cpp | 25 ++++++++-----
faiss/impl/ResultCollector.h | 58 +++++++++++++++++++++++++++++
faiss/impl/ResultCollectorFactory.h | 29 +++++++++++++++
7 files changed, 128 insertions(+), 12 deletions(-)
create mode 100644 faiss/impl/ResultCollector.h
create mode 100644 faiss/impl/ResultCollectorFactory.h

diff --git a/faiss/CMakeLists.txt b/faiss/CMakeLists.txt
index 27701586..af682a05 100644
Expand Down Expand Up @@ -263,3 +275,6 @@ index 00000000..4d903f8d
+};
+
+} // namespace faiss
--
2.39.3 (Apple Git-145)

0 comments on commit 7d68d8f

Please sign in to comment.