From 9dba0bedd2af7a46747a757a5fac447cb4d48c24 Mon Sep 17 00:00:00 2001 From: chasingegg Date: Wed, 8 Nov 2023 17:08:48 +0800 Subject: [PATCH] Add row number constraint for building scann index Signed-off-by: chasingegg --- src/index/ivf/ivf.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/index/ivf/ivf.cc b/src/index/ivf/ivf.cc index 2c8916e15..27ed0cf28 100644 --- a/src/index/ivf/ivf.cc +++ b/src/index/ivf/ivf.cc @@ -270,6 +270,15 @@ IvfIndexNode::Train(const DataSet& dataset, const Config& cfg) { auto dim = dataset.GetDim(); auto data = dataset.GetTensor(); + // faiss scann needs at least 16 rows since nbits=4 + constexpr int64_t SCANN_MIN_ROWS = 16; + if constexpr (std::is_same::value) { + if (rows < SCANN_MIN_ROWS) { + LOG_KNOWHERE_ERROR_ << rows << " rows is not enough, scann needs at least 16 rows to build index"; + return Status::faiss_inner_error; + } + } + typename QuantizerT::type* qzr = nullptr; faiss::IndexIVFPQFastScan* base_index = nullptr; std::unique_ptr index;