Skip to content

Commit 3a6db32

Browse files
authored
add estimate_memory (#6)
Signed-off-by: aozeliu.azl@oceanbase.com Signed-off-by: aozeliu.azl@oceanbase.com
1 parent 6a5555e commit 3a6db32

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

ob_vsag_lib.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class HnswIndexHandler
113113
int64_t count,
114114
char *extra_infos);
115115
int get_vid_bound(int64_t &min_vid, int64_t &max_vid);
116+
uint64_t estimate_memory(uint64_t row_count);
116117
int knn_search(const vsag::DatasetPtr& query, int64_t topk,
117118
const std::string& parameters,
118119
const float*& dist, const int64_t*& ids, int64_t &result_size,
@@ -224,6 +225,11 @@ int HnswIndexHandler::get_vid_bound(int64_t &min_vid, int64_t &max_vid)
224225
return static_cast<int>(error);
225226
}
226227

228+
uint64_t HnswIndexHandler::estimate_memory(uint64_t row_count)
229+
{
230+
return index_->EstimateMemory(row_count);
231+
}
232+
227233
int HnswIndexHandler::knn_search(const vsag::DatasetPtr& query, int64_t topk,
228234
const std::string& parameters,
229235
const float*& dist, const int64_t*& ids, int64_t &result_size,
@@ -904,6 +910,17 @@ int get_extra_info_by_ids(VectorIndexPtr& index_handler,
904910
return ret;
905911
}
906912

913+
uint64_t estimate_memory(VectorIndexPtr& index_handler,
914+
uint64_t row_count) {
915+
vsag::logger::debug("TRACE LOG[estimate_memory]");
916+
uint64_t estimate_memory_size = 0;
917+
if (index_handler != nullptr) {
918+
HnswIndexHandler* hnsw = static_cast<HnswIndexHandler*>(index_handler);
919+
estimate_memory_size = hnsw->estimate_memory(row_count);
920+
}
921+
return estimate_memory_size;
922+
}
923+
907924
int64_t example() {
908925
return 0;
909926
}
@@ -977,4 +994,8 @@ extern int deserialize_bin_c(VectorIndexPtr& index_handler,const std::string dir
977994
return deserialize_bin(index_handler, dir);
978995
}
979996

997+
extern uint64_t estimate_memory_c(VectorIndexPtr& index_handler, uint64_t row_count) {
998+
return estimate_memory(index_handler, row_count);
999+
}
1000+
9801001
} //namespace obvectorlib

ob_vsag_lib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ extern int fserialize(VectorIndexPtr& index_handler, std::ostream& out_stream);
8282
extern int fdeserialize(VectorIndexPtr& index_handler, std::istream& in_stream);
8383
extern int delete_index(VectorIndexPtr& index_handler);
8484
extern void delete_iter_ctx(void *iter_ctx);
85+
extern uint64_t estimate_memory(VectorIndexPtr& index_handler, uint64_t row_count);
8586
extern int get_extra_info_by_ids(VectorIndexPtr& index_handler,
8687
const int64_t* ids,
8788
int64_t count,

ob_vsag_lib_c.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ extern int fserialize_c(VectorIndexPtr& index_handler, std::ostream& out_stream)
7979
typedef int (*fdeserialize_ptr)(VectorIndexPtr& index_handler, std::istream& in_stream);
8080
extern int fdeserialize_c(VectorIndexPtr& index_handler, std::istream& in_stream);
8181

82-
82+
typedef uint64_t (*estimate_memory_ptr) (VectorIndexPtr& index_handler, uint64_t row_count);
83+
extern uint64_t estimate_memory_c(VectorIndexPtr& index_handler, uint64_t row_count);
8384

8485

8586
#ifdef __cplusplus

0 commit comments

Comments
 (0)