Enable Faiss for internal use (#4737)

Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4737

Add SVS as dependency of Faiss in BUCK files so we can use SVS internally. Also makes minor changes to index_read and index_factory to fix compiler warnings generated internally.

Reviewed By: mdouze

Differential Revision: D88785138

fbshipit-source-id: 975ade365cd6775582526aa2c852644ef4676610
This commit is contained in:
Junjie Qi
2026-01-27 13:22:08 -08:00
committed by meta-codesync[bot]
parent cd4898bc13
commit 79ec020cbe
3 changed files with 14 additions and 9 deletions
+2 -2
View File
@@ -1389,7 +1389,7 @@ Index* read_index(IOReader* f, int io_flags) {
#ifdef FAISS_ENABLE_SVS
else if (
h == fourcc("ILVQ") || h == fourcc("ISVL") || h == fourcc("ISVD")) {
IndexSVSVamana* svs;
IndexSVSVamana* svs = nullptr;
if (h == fourcc("ILVQ")) {
svs = new IndexSVSVamanaLVQ();
} else if (h == fourcc("ISVL")) {
@@ -1440,8 +1440,8 @@ Index* read_index(IOReader* f, int io_flags) {
faiss::svs_io::ReaderStreambuf rbuf(f);
std::istream is(&rbuf);
svs->deserialize_impl(is);
idx = svs;
}
idx = svs;
}
#endif // FAISS_ENABLE_SVS
else if (h == fourcc("Iwrf")) {
+12 -7
View File
@@ -610,28 +610,33 @@ Index* parse_svs_datatype(
std::smatch sm;
if (datatype_string.empty()) {
if (index_type == "Vamana")
if (index_type == "Vamana") {
return new IndexSVSVamana(d, std::stoul(arg_string), mt);
if (index_type == "Flat")
}
if (index_type == "Flat") {
return new IndexSVSFlat(d, mt);
}
FAISS_ASSERT(!"Unspported SVS index type");
}
if (re_match(datatype_string, "FP16", sm)) {
if (index_type == "Vamana")
if (index_type == "Vamana") {
return new IndexSVSVamana(
d, std::stoul(arg_string), mt, SVSStorageKind::SVS_FP16);
}
FAISS_ASSERT(!"Unspported SVS index type for Float16");
}
if (re_match(datatype_string, "SQI8", sm)) {
if (index_type == "Vamana")
if (index_type == "Vamana") {
return new IndexSVSVamana(
d, std::stoul(arg_string), mt, SVSStorageKind::SVS_SQI8);
}
FAISS_ASSERT(!"Unspported SVS index type for SQI8");
}
if (re_match(datatype_string, "(LVQ[0-9]+x[0-9]+)", sm)) {
if (index_type == "Vamana")
if (index_type == "Vamana") {
return new IndexSVSVamanaLVQ(
d, std::stoul(arg_string), mt, parse_lvq(sm[0].str()));
}
FAISS_ASSERT(!"Unspported SVS index type for LVQ");
}
if (re_match(datatype_string, "(LeanVec[0-9]+x[0-9]+)(_[0-9]+)?", sm)) {
@@ -639,13 +644,14 @@ Index* parse_svs_datatype(
sm[2].length() > 0 ? sm[2].str().substr(1) : "0";
int leanvec_d = std::stoul(leanvec_d_string);
if (index_type == "Vamana")
if (index_type == "Vamana") {
return new IndexSVSVamanaLeanVec(
d,
std::stoul(arg_string),
mt,
leanvec_d,
parse_leanvec(sm[1].str()));
}
FAISS_ASSERT(!"Unspported SVS index type for LeanVec");
}
return nullptr;
@@ -659,7 +665,6 @@ Index* parse_IndexSVS(const std::string& code_string, int d, MetricType mt) {
return parse_svs_datatype("Flat", "", datatype_string, d, mt);
}
if (re_match(code_string, "Vamana([0-9]+)(,.+)?", sm)) {
Index* index{nullptr};
std::string degree_string = sm[1].str();
std::string datatype_string =
sm[2].length() > 0 ? sm[2].str().substr(1) : "";