Skip to content

Commit f916a6f

Browse files
mostly get rid of faiss fork
Signed-off-by: Alexandr Guzhva <alexanderguzhva@gmail.com>
1 parent d957a9a commit f916a6f

286 files changed

Lines changed: 19929 additions & 14661 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmark/hdf5/benchmark_float.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ TEST_F(Benchmark_float, TEST_IVF_RABITQ) {
629629
for (auto nlist : NLISTs_) {
630630
for (auto qb : {0, 4, 6, 8}) {
631631
conf[knowhere::indexparam::NLIST] = nlist;
632+
conf[knowhere::indexparam::RABITQ_BITS] = 1;
632633
conf[knowhere::indexparam::RABITQ_QUERY_BITS] = qb;
633634
std::vector<int32_t> params = {nlist, qb};
634635

@@ -638,3 +639,22 @@ TEST_F(Benchmark_float, TEST_IVF_RABITQ) {
638639
}
639640
}
640641
}
642+
643+
TEST_F(Benchmark_float, TEST_IVF_RABITQ_MULTIBIT) {
644+
index_type_ = knowhere::IndexEnum::INDEX_FAISS_IVFRABITQ;
645+
646+
std::string index_file_name;
647+
knowhere::Json conf = cfg_;
648+
conf.erase(knowhere::indexparam::RABITQ_QUERY_BITS);
649+
for (auto nlist : NLISTs_) {
650+
for (auto rbq_bits : {2, 3, 4}) {
651+
conf[knowhere::indexparam::NLIST] = nlist;
652+
conf[knowhere::indexparam::RABITQ_BITS] = rbq_bits;
653+
std::vector<int32_t> params = {nlist, rbq_bits};
654+
655+
TEST_INDEX(ivf, knowhere::fp32, params);
656+
TEST_INDEX(ivf, knowhere::fp16, params);
657+
TEST_INDEX(ivf, knowhere::bf16, params);
658+
}
659+
}
660+
}

cmake/libs/libdiskann.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ if (WITH_CUVS)
3636
endif()
3737

3838
add_library(diskann STATIC ${DISKANN_SOURCES})
39-
set_target_properties(diskann PROPERTIES CXX_STANDARD 17)
39+
# folly v2026 headers require C++20 (consteval/constinit); DiskANN includes
40+
# milvus-common's thread_pool.h which pulls in folly/executors.
41+
set_target_properties(diskann PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED ON)
4042
target_link_libraries(
4143
diskann
4244
PUBLIC ${AIO_LIBRARIES}
4345
${DISKANN_BOOST_PROGRAM_OPTIONS_LIB}
4446
nlohmann_json::nlohmann_json
47+
milvus-common
4548
Folly::folly
4649
fmt::fmt
4750
prometheus-cpp::core

cmake/libs/libfaiss.cmake

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ knowhere_file_glob(
4848
thirdparty/faiss/faiss/impl/fast_scan/impl-avx512.cpp
4949
thirdparty/faiss/faiss/impl/hnsw/avx512.cpp
5050
thirdparty/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx512.cpp
51+
thirdparty/faiss/faiss/impl/binary_hamming/avx512.cpp
5152
thirdparty/faiss/faiss/cppcontrib/knowhere/impl/sq-avx512-fastpath.cpp
5253
thirdparty/faiss/faiss/utils/distances_fused/avx512.cpp
54+
thirdparty/faiss/faiss/utils/hamming_distance/hamming_avx512.cpp
5355
thirdparty/faiss/faiss/utils/simd_impl/distances_avx512.cpp
5456
thirdparty/faiss/faiss/utils/simd_impl/rabitq_avx512.cpp
57+
thirdparty/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx512.cpp
5558
)
5659
# Baseline sq-avx512.cpp is pulled in textually by the prelude file, not
5760
# compiled directly. Remove it from the generic list so it is not picked
@@ -83,11 +86,14 @@ knowhere_file_glob(
8386
thirdparty/faiss/faiss/impl/fast_scan/impl-avx2.cpp
8487
thirdparty/faiss/faiss/impl/hnsw/avx2.cpp
8588
thirdparty/faiss/faiss/impl/pq_code_distance/pq_code_distance-avx2.cpp
89+
thirdparty/faiss/faiss/impl/binary_hamming/avx2.cpp
8690
thirdparty/faiss/faiss/cppcontrib/knowhere/impl/sq-avx2-fastpath.cpp
8791
thirdparty/faiss/faiss/utils/distances_fused/simdlib_based.cpp
92+
thirdparty/faiss/faiss/utils/hamming_distance/hamming_avx2.cpp
8893
thirdparty/faiss/faiss/utils/simd_impl/distances_avx2.cpp
8994
thirdparty/faiss/faiss/utils/simd_impl/partitioning_avx2.cpp
9095
thirdparty/faiss/faiss/utils/simd_impl/rabitq_avx2.cpp
96+
thirdparty/faiss/faiss/utils/simd_impl/super_kmeans_kernels_avx2.cpp
9197
)
9298
knowhere_file_glob(
9399
GLOB
@@ -111,7 +117,6 @@ knowhere_file_glob(
111117
thirdparty/faiss/faiss/IndexPQFastScan.cpp
112118
thirdparty/faiss/faiss/IndexIVFFastScan.cpp
113119
thirdparty/faiss/faiss/IndexIVFPQFastScan.cpp
114-
thirdparty/faiss/faiss/cppcontrib/knowhere/IndexIVFFastScan.cpp
115120
thirdparty/faiss/faiss/cppcontrib/knowhere/IndexIVFPQFastScan.cpp
116121
thirdparty/faiss/faiss/cppcontrib/knowhere/IVFFastScanIteratorWorkspace.cpp
117122
)
@@ -132,8 +137,10 @@ knowhere_file_glob(
132137
FAISS_DD_NEON_SRCS
133138
thirdparty/faiss/faiss/impl/approx_topk/neon.cpp
134139
thirdparty/faiss/faiss/impl/fast_scan/impl-neon.cpp
140+
thirdparty/faiss/faiss/impl/binary_hamming/neon.cpp
135141
thirdparty/faiss/faiss/cppcontrib/knowhere/impl/sq-neon-fastpath.cpp
136142
thirdparty/faiss/faiss/utils/distances_fused/simdlib_based_neon.cpp
143+
thirdparty/faiss/faiss/utils/hamming_distance/hamming_neon.cpp
137144
thirdparty/faiss/faiss/utils/simd_impl/distances_aarch64.cpp
138145
thirdparty/faiss/faiss/utils/simd_impl/partitioning_neon.cpp
139146
thirdparty/faiss/faiss/utils/simd_impl/rabitq_neon.cpp
@@ -175,13 +182,18 @@ knowhere_file_glob(
175182
FAISS_RVV_SRCS
176183
thirdparty/faiss/faiss/cppcontrib/knowhere/impl/*rvv.cpp
177184
)
178-
# # RVE vanilla Faiss dynamic dispatch related files are not there yet
179-
# knowhere_file_glob(
180-
# GLOB
181-
# FAISS_DD_RVV_SRCS
182-
# )
183-
# # combine files
184-
# list(APPEND FAISS_RVV_SRCS ${FAISS_DD_RVV_SRCS})
185+
# RVV vanilla Faiss dynamic dispatch related files
186+
knowhere_file_glob(
187+
GLOB
188+
FAISS_DD_RVV_SRCS
189+
thirdparty/faiss/faiss/impl/scalar_quantizer/sq-rvv.cpp
190+
thirdparty/faiss/faiss/impl/binary_hamming/rvv.cpp
191+
thirdparty/faiss/faiss/utils/simd_impl/distances_rvv.cpp
192+
thirdparty/faiss/faiss/utils/hamming_distance/hamming_rvv.cpp
193+
thirdparty/faiss/faiss/utils/simd_impl/rabitq_rvv.cpp
194+
)
195+
# combine files
196+
list(APPEND FAISS_RVV_SRCS ${FAISS_DD_RVV_SRCS})
185197
# remove platform files from general files
186198
list(REMOVE_ITEM FAISS_SRCS ${FAISS_RVV_SRCS})
187199

@@ -322,20 +334,14 @@ if(__PPC64)
322334
endif()
323335

324336

325-
if(LINUX)
326-
set(BLA_VENDOR OpenBLAS)
327-
endif()
328-
329337
if(APPLE)
330338
set(BLA_VENDOR Apple)
331-
endif()
332-
333-
if(CMAKE_SYSTEM_NAME STREQUAL "Android" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
334-
find_package(OpenBLAS REQUIRED)
335-
set(BLAS_LIBRARIES OpenBLAS::OpenBLAS)
336-
else()
337339
find_package(LAPACK REQUIRED)
338340
find_package(BLAS REQUIRED)
341+
else()
342+
find_package(OpenBLAS CONFIG REQUIRED)
343+
set(BLAS_LIBRARIES OpenBLAS::OpenBLAS)
344+
set(LAPACK_LIBRARIES OpenBLAS::OpenBLAS)
339345
endif()
340346

341347
find_package(xxHash REQUIRED)
@@ -489,7 +495,7 @@ if(__RISCV64)
489495
add_dependencies(faiss knowhere_utils)
490496
target_link_libraries(faiss PUBLIC OpenMP::OpenMP_CXX ${BLAS_LIBRARIES}
491497
${LAPACK_LIBRARIES} knowhere_utils)
492-
target_compile_definitions(faiss PRIVATE FINTEGER=int)
498+
target_compile_definitions(faiss PRIVATE FINTEGER=int COMPILE_SIMD_RISCV_RVV)
493499
endif()
494500

495501
# generate `faiss` library for PPC64

cmake/libs/libmilvus-common.cmake

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES "")
3-
set( MILVUS-COMMON-VERSION 2eb54ae )
3+
set( MILVUS-COMMON-VERSION 28a2b48f5ab5e14280cfd5d6bf9b34a9cb9a6fd7 )
44
set( GIT_REPOSITORY "https://github.com/zilliztech/milvus-common.git" )
55

66
message(STATUS "milvus-common repo: ${GIT_REPOSITORY}")
@@ -16,6 +16,15 @@ find_package(fmt REQUIRED)
1616
find_package(glog REQUIRED)
1717
find_package(nlohmann_json REQUIRED)
1818
find_package(folly REQUIRED)
19+
if(APPLE)
20+
set(BLA_VENDOR Apple)
21+
find_package(LAPACK REQUIRED)
22+
find_package(BLAS REQUIRED)
23+
set(MILVUS_COMMON_BLAS_LIBS ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
24+
else()
25+
find_package(OpenBLAS CONFIG REQUIRED)
26+
set(MILVUS_COMMON_BLAS_LIBS OpenBLAS::OpenBLAS)
27+
endif()
1928
find_package(prometheus-cpp REQUIRED)
2029

2130
FetchContent_Declare(
@@ -32,11 +41,19 @@ if ( NOT milvus-common_POPULATED )
3241
add_subdirectory( ${milvus-common_SOURCE_DIR}
3342
${milvus-common_BINARY_DIR} )
3443

44+
# milvus-common's CMakeLists hardcodes CMAKE_CXX_STANDARD=17, but folly v2026
45+
# headers require C++20 (consteval/constinit). Override on the target.
46+
set_target_properties(milvus-common PROPERTIES
47+
CXX_STANDARD 20
48+
CXX_STANDARD_REQUIRED ON)
49+
3550
if(NOT APPLE)
3651
target_link_libraries(milvus-common PUBLIC atomic)
3752
endif()
3853
endif()
3954

55+
target_link_libraries(milvus-common PUBLIC ${MILVUS_COMMON_BLAS_LIBS})
56+
4057
set( MILVUS_COMMON_INCLUDE_DIR ${milvus-common_SOURCE_DIR}/include
4158
CACHE INTERNAL "Path to milvus-common include directory" )
4259

conanfile.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ def _minimum_compilers_version(self):
9090
"apple-clang": "13",
9191
}
9292

93+
@property
94+
def _openblas_dynamic_arches(self):
95+
# Keep OpenBLAS portable across supported CPU families without pinning a
96+
# concrete TARGET such as SANDYBRIDGE.
97+
return ["x86", "x86_64", "armv8", "ppc64", "ppc64le"]
98+
9399
def config_options(self):
94100
if self.settings.os == "Windows":
95101
self.options.rm_safe("fPIC")
@@ -101,6 +107,8 @@ def config_options(self):
101107
def configure(self):
102108
if self.options.shared:
103109
self.options.rm_safe("fPIC")
110+
if self.settings.os in ["Linux", "Android"] and str(self.settings.arch) in self._openblas_dynamic_arches:
111+
self.options["openblas"].dynamic_arch = True
104112

105113
def requirements(self):
106114
self.requires("abseil/20250127.0#481edcc75deb0efb16500f511f0f0a1c")
@@ -114,18 +122,21 @@ def requirements(self):
114122
self.requires("double-conversion/3.3.0#640e35791a4bac95b0545e2f54b7aceb")
115123
self.requires("xz_utils/5.4.5#fc4e36861e0a47ecd4a40a00e6d29ac8")
116124
self.requires("protobuf/5.27.0@milvus/dev#42f031a96d21c230a6e05bcac4bdd633", force=True, override=True)
117-
self.requires("lz4/1.9.4#7f0b5851453198536c14354ee30ca9ae", force=True, override=True)
125+
self.requires("lz4/1.10.0#982d9b673900f665a1da109e09c17cab", force=True, override=True)
118126
if self.settings.os == "Linux":
119127
self.requires("liburing/2.8", force=True, override=True)
120128
self.requires("fmt/11.2.0#eb98daa559c7c59d591f4720dde4cd5c", force=True, override=True)
121129
self.requires("libevent/2.1.12#95065aaefcd58d3956d6dfbfc5631d97")
122130
self.requires("grpc/1.67.1@milvus/dev#efeaa484b59bffaa579004d5e82ec4fd")
123-
self.requires("folly/2024.08.12.00@milvus/dev#f9b2bdf162c0ec47cb4e5404097b340d")
131+
self.requires("folly/2026.04.20.00@milvus/dev#06852bea5b6449f0c4eb0df002b5779c")
132+
self.requires("fast_float/8.0.0@milvus/dev#c7802833c74c5a86ffed70e4af1a795e")
124133
self.requires("libcurl/8.10.1#a3113369c86086b0e84231844e7ed0a9", force=True, override=True)
125134
self.requires("simde/0.8.2#5e1edfd5cba92f25d79bf6ef4616b972")
126135
self.requires("xxhash/0.8.3#caa6d0af1b951c247922e38fbcebdbe6")
136+
if self.settings.os == "Linux":
137+
self.requires("openblas/0.3.30")
127138
if self.settings.os == "Android":
128-
self.requires("openblas/0.3.27")
139+
self.requires("openblas/0.3.30")
129140
if not self.options.with_light:
130141
self.requires("opentelemetry-cpp/1.23.0@milvus/dev#11bc565ec6e82910ae8f7471da756720")
131142
if self.settings.os not in ["Macos", "Android"]:

include/knowhere/comp/index_param.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ constexpr const char* DROP_RATIO_BUILD = "drop_ratio_build";
228228
constexpr const char* DROP_RATIO_SEARCH = "drop_ratio_search";
229229

230230
// RaBitQ Params
231+
constexpr const char* RABITQ_BITS = "rbq_bits";
231232
constexpr const char* RABITQ_QUERY_BITS = "rbq_bits_query";
232233

233234
// minhash meta Params

include/knowhere/index/index_node.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ class ThreadPool;
4747
#endif
4848

4949
namespace faiss {
50-
namespace cppcontrib {
51-
namespace knowhere {
5250
class IndexFlat;
53-
}
54-
} // namespace cppcontrib
5551
} // namespace faiss
5652

5753
namespace knowhere {
@@ -644,7 +640,11 @@ class IndexNode : public Object {
644640
// into different representations for ANN search. Since the base index holds encoded
645641
// vectors (not raw), this IndexFlat stores original vectors for exact distance
646642
// computation during MaxSim reranking.
647-
std::shared_ptr<faiss::cppcontrib::knowhere::IndexFlat> emb_list_raw_index_;
643+
// Baseline type so that the same shared_ptr can hold either the knowhere
644+
// Jaccard-aware IndexFlat subclass (fresh build path, if ever needed) or
645+
// a plain ::faiss::IndexFlat{,IP,L2} restored by the deserialization
646+
// factory in cppcontrib/knowhere/impl/index_read.cpp.
647+
std::shared_ptr<::faiss::IndexFlat> emb_list_raw_index_;
648648

649649
#if defined(NOT_COMPILE_FOR_SWIG) && !defined(KNOWHERE_WITH_LIGHT)
650650
struct PrometheusMetrics {

scripts/install_deps.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ if [[ "${OS}" == "Linux" ]]; then
5757
libdouble-conversion-dev # folly dependency
5858
libevent-dev # gRPC dependency
5959
libgflags-dev # folly / glog dependency
60-
libopenblas-openmp-dev # faiss BLAS operations
6160
libomp-dev # OpenMP parallelization
6261
python3 python3-pip
6362
clang-tidy-14 # CI: static analysis (analyzer CI)
@@ -80,7 +79,6 @@ if [[ "${OS}" == "Linux" ]]; then
8079
double-conversion-devel # folly dependency
8180
libevent-devel # gRPC dependency
8281
gflags-devel # folly / glog dependency
83-
openblas-devel # faiss BLAS operations
8482
libomp-devel # OpenMP parallelization
8583
python3 python3-pip
8684
clang-tools-extra # CI: static analysis (provides clang-tidy)

src/index/data_view_dense_index/refine_computer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ struct QuantRefine {
139139
static constexpr size_t list_num = 1;
140140
static constexpr size_t segment_size = 48;
141141
faiss::ScalarQuantizer* quantizer = nullptr;
142-
faiss::cppcontrib::knowhere::InvertedLists* storage = nullptr;
142+
// Path-D step 10.10: declared as the concrete
143+
// ConcurrentArrayInvertedLists* (previously the base InvertedLists*)
144+
// because this class uses the segment-sliced get_codes(list_no, offset)
145+
// accessor which is no longer a virtual on the base.
146+
faiss::cppcontrib::knowhere::ConcurrentArrayInvertedLists* storage = nullptr;
143147
faiss::MetricType metric_type;
144148
DataFormatEnum origin_data_type;
145149
RefineType refine_type;

src/index/hnsw/faiss_hnsw.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,11 @@ get_index_data_format(const faiss::Index* index) {
706706
}
707707

708708
// is it flat?
709-
// note: IndexFlatCosine preserves the original data, no cosine norm is applied
710-
auto index_flat = dynamic_cast<const faiss::cppcontrib::knowhere::IndexFlat*>(index);
709+
// note: IndexFlatCosine preserves the original data, no cosine norm is applied.
710+
// Cast to baseline ::faiss::IndexFlat so this catches both the knowhere
711+
// Jaccard-aware subclass (fresh build path) and baseline variants produced
712+
// by the IxFI/IxF2 deserialization factory.
713+
auto index_flat = dynamic_cast<const ::faiss::IndexFlat*>(index);
711714
if (index_flat != nullptr) {
712715
return DataFormatEnum::fp32;
713716
}
@@ -1433,7 +1436,7 @@ class BaseFaissRegularIndexHNSWNode : public BaseFaissRegularIndexNode {
14331436

14341437
// perform the search
14351438
if (is_refined) {
1436-
faiss::cppcontrib::knowhere::IndexRefineSearchParameters refine_params;
1439+
faiss::IndexRefineSearchParameters refine_params;
14371440
refine_params.k_factor = hnsw_cfg.refine_k.value_or(1);
14381441
// a refine procedure itself does not need to care about filtering
14391442
refine_params.sel = nullptr;
@@ -1727,7 +1730,7 @@ class BaseFaissRegularIndexHNSWNode : public BaseFaissRegularIndexNode {
17271730

17281731
// perform the search
17291732
if (is_refined) {
1730-
faiss::cppcontrib::knowhere::IndexRefineSearchParameters refine_params;
1733+
faiss::IndexRefineSearchParameters refine_params;
17311734
refine_params.k_factor = hnsw_cfg.refine_k.value_or(1);
17321735
// a refine procedure itself does not need to care about filtering
17331736
refine_params.sel = nullptr;

0 commit comments

Comments
 (0)