Skip to content

Commit 725c197

Browse files
authored
sparse: add StaticHasRawData support (#1188)
Signed-off-by: Shawn Wang <shawn.wang@zilliz.com>
1 parent 5734ebe commit 725c197

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/index/index_static.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ IndexStaticFaced<DataType>::HasRawData(const IndexType& indexType, const IndexVe
116116
}
117117

118118
static std::set<knowhere::IndexType> has_raw_data_index_set = {
119-
IndexEnum::INDEX_FAISS_BIN_IDMAP, IndexEnum::INDEX_FAISS_BIN_IVFFLAT, IndexEnum::INDEX_FAISS_IVFFLAT,
120-
IndexEnum::INDEX_FAISS_IVFFLAT_CC, IndexEnum::INDEX_SPARSE_INVERTED_INDEX, IndexEnum::INDEX_SPARSE_WAND};
119+
IndexEnum::INDEX_FAISS_BIN_IDMAP, IndexEnum::INDEX_FAISS_BIN_IVFFLAT, IndexEnum::INDEX_FAISS_IVFFLAT,
120+
IndexEnum::INDEX_FAISS_IVFFLAT_CC};
121121

122122
static std::set<knowhere::IndexType> has_raw_data_index_alias_set = {"IVFBIN", "BINFLAT", "IVFFLAT", "IVFFLATCC"};
123123

src/index/sparse/sparse_index_node.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ class SparseInvertedIndexNode : public IndexNode {
245245
return expected<DataSetPtr>::Err(Status::not_implemented, "GetVectorByIds not implemented");
246246
}
247247

248+
static bool
249+
StaticHasRawData(const knowhere::BaseConfig& /*config*/, const IndexVersion& /*version*/) {
250+
return false;
251+
}
252+
248253
[[nodiscard]] bool
249254
HasRawData(const std::string& metric_type) const override {
250255
return false;
@@ -541,6 +546,14 @@ class SparseInvertedIndexNodeCC : public SparseInvertedIndexNode<T, use_wand> {
541546
return res;
542547
}
543548

549+
static bool
550+
StaticHasRawData(const knowhere::BaseConfig& config, const IndexVersion& version) {
551+
if (!config.metric_type.has_value()) {
552+
return false;
553+
}
554+
return IsMetricType(config.metric_type.value(), metric::IP);
555+
}
556+
544557
[[nodiscard]] bool
545558
HasRawData(const std::string& metric_type) const override {
546559
return IsMetricType(metric_type, metric::IP);

tests/ut/test_index_check.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ TEST_CASE("Test index has raw data", "[IndexHasRawData]") {
209209
CHECK_FALSE(knowhere::IndexStaticFaced<fp32>::HasRawData(IndexEnum::INDEX_CUVS_CAGRA, ver, {}));
210210
#endif
211211
// sparse index
212-
CHECK(knowhere::IndexStaticFaced<fp32>::HasRawData(IndexEnum::INDEX_SPARSE_INVERTED_INDEX, ver, {}));
213-
CHECK(knowhere::IndexStaticFaced<fp32>::HasRawData(IndexEnum::INDEX_SPARSE_WAND, ver, {}));
212+
CHECK_FALSE(knowhere::IndexStaticFaced<fp32>::HasRawData(IndexEnum::INDEX_SPARSE_INVERTED_INDEX, ver, {}));
213+
CHECK_FALSE(knowhere::IndexStaticFaced<fp32>::HasRawData(IndexEnum::INDEX_SPARSE_WAND, ver, {}));
214214
}
215215

216216
SECTION("Special test") {

tests/ut/test_sparse.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ TEST_CASE("Test Mem Sparse Index With Float Vector", "[float metrics]") {
137137
REQUIRE(idx.Build(train_ds, json) == knowhere::Status::success);
138138
REQUIRE(idx.Size() > 0);
139139
REQUIRE(idx.Count() == nb);
140+
REQUIRE(idx.HasRawData(metric) ==
141+
knowhere::IndexStaticFaced<knowhere::fp32>::HasRawData(name, version, json));
140142

141143
knowhere::BinarySet bs;
142144
REQUIRE(idx.Serialize(bs) == knowhere::Status::success);
@@ -562,7 +564,7 @@ TEST_CASE("Test Mem Sparse Index CC", "[float metrics]") {
562564

563565
SECTION("Test GetVectorByIds") {
564566
std::vector<int64_t> ids = {0, 1, 2};
565-
REQUIRE(idx.HasRawData(metric));
567+
REQUIRE(idx.HasRawData(metric) == knowhere::IndexStaticFaced<knowhere::fp32>::HasRawData(name, version, json));
566568
auto results = idx.GetVectorByIds(GenIdsDataSet(3, ids));
567569
REQUIRE(results.has_value());
568570
auto xb = (knowhere::sparse::SparseRow<float>*)train_ds->GetTensor();

0 commit comments

Comments
 (0)