Skip to content

Commit f98dded

Browse files
committed
sparse: add StaticHasRawData support
Signed-off-by: Shawn Wang <shawn.wang@zilliz.com>
1 parent 4746db1 commit f98dded

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/index/index_static.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ IndexStaticFaced<DataType>::HasRawData(const IndexType& indexType, const IndexVe
117117

118118
static std::set<knowhere::IndexType> has_raw_data_index_set = {
119119
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};
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_sparse.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ 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) == knowhere::IndexStaticFaced<knowhere::fp32>::HasRawData(name, version, json));
140141

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

563564
SECTION("Test GetVectorByIds") {
564565
std::vector<int64_t> ids = {0, 1, 2};
565-
REQUIRE(idx.HasRawData(metric));
566+
REQUIRE(idx.HasRawData(metric) == knowhere::IndexStaticFaced<knowhere::fp32>::HasRawData(name, version, json));
566567
auto results = idx.GetVectorByIds(GenIdsDataSet(3, ids));
567568
REQUIRE(results.has_value());
568569
auto xb = (knowhere::sparse::SparseRow<float>*)train_ds->GetTensor();

0 commit comments

Comments
 (0)