diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 967ba4b8b8f4da411bab0522445a92b6ddf62f10..d19723fede468bc2cc052ac722705c68ec1785e0 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -14,6 +14,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-622 - Delete vectors should be failed if date range is invalid - MS-620 - Get table row counts display wrong error code - MS-637 - out of memory when load too many tasks +- MS-640 - Cache object size calculate incorrect ## Improvement - MS-552 - Add and change the easylogging library diff --git a/cpp/src/wrapper/VecIndex.cpp b/cpp/src/wrapper/VecIndex.cpp index 6bc054bd21cbceee9963ee2404dee51015e1ffaf..abf97e69e59339d7e5b9fe8c788400c20044ee5b 100644 --- a/cpp/src/wrapper/VecIndex.cpp +++ b/cpp/src/wrapper/VecIndex.cpp @@ -37,9 +37,17 @@ namespace engine { int64_t VecIndex::Size() { + if (size_ != 0) { + return size_; + } return Count() * Dimension() * sizeof(float); } +void +VecIndex::set_size(int64_t size) { + size_ = size; +} + struct FileIOReader { std::fstream fs; std::string name; @@ -159,12 +167,13 @@ GetVecIndexFactory(const IndexType& type, const Config& cfg) { } VecIndexPtr -LoadVecIndex(const IndexType& index_type, const knowhere::BinarySet& index_binary) { +LoadVecIndex(const IndexType& index_type, const knowhere::BinarySet& index_binary, int64_t size) { auto index = GetVecIndexFactory(index_type); if (index == nullptr) return nullptr; // else index->Load(index_binary); + index->set_size(size); return index; } @@ -210,7 +219,7 @@ read_index(const std::string& location) { delete[] meta; } - return LoadVecIndex(current_type, load_data_list); + return LoadVecIndex(current_type, load_data_list, length); } Status diff --git a/cpp/src/wrapper/VecIndex.h b/cpp/src/wrapper/VecIndex.h index 34d3d2f761c01b262ea0f24ac41c9b10265bb2ef..f5fdd49466bcd4ce5c8f2ff484dbe8103503f5bd 100644 --- a/cpp/src/wrapper/VecIndex.h +++ b/cpp/src/wrapper/VecIndex.h @@ -87,6 +87,9 @@ class VecIndex : public cache::DataObj { int64_t Size() override; + void + set_size(int64_t size); + virtual knowhere::BinarySet Serialize() = 0; @@ -115,6 +118,8 @@ class VecIndex : public cache::DataObj { return Status::OK(); } //////////////// + private: + int64_t size_ = 0; }; extern Status @@ -127,7 +132,7 @@ extern VecIndexPtr GetVecIndexFactory(const IndexType& type, const Config& cfg = Config()); extern VecIndexPtr -LoadVecIndex(const IndexType& index_type, const knowhere::BinarySet& index_binary); +LoadVecIndex(const IndexType& index_type, const knowhere::BinarySet& index_binary, int64_t size); extern IndexType ConvertToCpuIndexType(const IndexType& type);