Skip to content

Commit 68b0f28

Browse files
authored
[0.6] Refactor Info Report - [MOD-9321] (#657)
* Refactor Info Report - [MOD-9321] (#650) * refactor `info()` API to indicate it should be used for debug, and prepare structs and new API for statistics info * test fixes * implement new API * format * improve tests * move tiered statisticInfo to base class * refactor * minor simplification * review fixes (cherry picked from commit 5f7dbdf) * fixes for 0.6 * Add back missing debug info comparison and iterator free
1 parent 3e58052 commit 68b0f28

20 files changed

+275
-251
lines changed

src/VecSim/algorithms/brute_force/brute_force.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class BruteForceIndex : public VecSimIndexAbstract<DistType> {
4343
VecSimQueryParams *queryParams) override;
4444
VecSimQueryResult_List rangeQuery(const void *queryBlob, double radius,
4545
VecSimQueryParams *queryParams) override;
46-
virtual VecSimIndexInfo info() const override;
47-
virtual VecSimInfoIterator *infoIterator() const override;
46+
VecSimIndexDebugInfo debugInfo() const override;
47+
VecSimDebugInfoIterator *debugInfoIterator() const override;
4848
virtual VecSimBatchIterator *newBatchIterator(const void *queryBlob,
4949
VecSimQueryParams *queryParams) const override;
5050
bool preferAdHocSearch(size_t subsetSize, size_t k, bool initial_check) override;
@@ -329,9 +329,9 @@ BruteForceIndex<DataType, DistType>::rangeQuery(const void *queryBlob, double ra
329329
}
330330

331331
template <typename DataType, typename DistType>
332-
VecSimIndexInfo BruteForceIndex<DataType, DistType>::info() const {
332+
VecSimIndexDebugInfo BruteForceIndex<DataType, DistType>::debugInfo() const {
333333

334-
VecSimIndexInfo info;
334+
VecSimIndexDebugInfo info;
335335
info.algo = VecSimAlgo_BF;
336336
info.bfInfo.dim = this->dim;
337337
info.bfInfo.type = this->vecType;
@@ -346,11 +346,11 @@ VecSimIndexInfo BruteForceIndex<DataType, DistType>::info() const {
346346
}
347347

348348
template <typename DataType, typename DistType>
349-
VecSimInfoIterator *BruteForceIndex<DataType, DistType>::infoIterator() const {
350-
VecSimIndexInfo info = this->info();
349+
VecSimDebugInfoIterator *BruteForceIndex<DataType, DistType>::debugInfoIterator() const {
350+
VecSimIndexDebugInfo info = this->debugInfo();
351351
// For readability. Update this number when needed.
352352
size_t numberOfInfoFields = 8;
353-
VecSimInfoIterator *infoIterator = new VecSimInfoIterator(numberOfInfoFields);
353+
auto *infoIterator = new VecSimDebugInfoIterator(numberOfInfoFields);
354354

355355
infoIterator->addInfoField(VecSim_InfoField{
356356
.fieldName = VecSimCommonStrings::ALGORITHM_STRING,

src/VecSim/algorithms/hnsw/hnsw.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ class HNSWIndex : public VecSimIndexAbstract<DistType>
192192
inline labelType getEntryPointLabel() const;
193193
inline labelType getExternalLabel(idType internal_id) const;
194194
inline VisitedNodesHandler *getVisitedList() const;
195-
VecSimIndexInfo info() const override;
196-
VecSimInfoIterator *infoIterator() const override;
195+
VecSimIndexDebugInfo debugInfo() const override;
196+
VecSimDebugInfoIterator *debugInfoIterator() const override;
197197
bool preferAdHocSearch(size_t subsetSize, size_t k, bool initial_check) override;
198198
char *getDataByInternalId(idType internal_id) const;
199199
inline linklistsizeint *get_linklist_at_level(idType internal_id, size_t level) const;
@@ -1539,9 +1539,9 @@ VecSimQueryResult_List HNSWIndex<DataType, DistType>::rangeQuery(const void *que
15391539
}
15401540

15411541
template <typename DataType, typename DistType>
1542-
VecSimIndexInfo HNSWIndex<DataType, DistType>::info() const {
1542+
VecSimIndexDebugInfo HNSWIndex<DataType, DistType>::debugInfo() const {
15431543

1544-
VecSimIndexInfo info;
1544+
VecSimIndexDebugInfo info;
15451545
info.algo = VecSimAlgo_HNSWLIB;
15461546
info.hnswInfo.dim = this->dim;
15471547
info.hnswInfo.type = this->vecType;
@@ -1562,11 +1562,11 @@ VecSimIndexInfo HNSWIndex<DataType, DistType>::info() const {
15621562
}
15631563

15641564
template <typename DataType, typename DistType>
1565-
VecSimInfoIterator *HNSWIndex<DataType, DistType>::infoIterator() const {
1566-
VecSimIndexInfo info = this->info();
1565+
VecSimDebugInfoIterator *HNSWIndex<DataType, DistType>::debugInfoIterator() const {
1566+
VecSimIndexDebugInfo info = this->debugInfo();
15671567
// For readability. Update this number when needed.
15681568
size_t numberOfInfoFields = 12;
1569-
VecSimInfoIterator *infoIterator = new VecSimInfoIterator(numberOfInfoFields);
1569+
auto *infoIterator = new VecSimDebugInfoIterator(numberOfInfoFields);
15701570

15711571
infoIterator->addInfoField(VecSim_InfoField{
15721572
.fieldName = VecSimCommonStrings::ALGORITHM_STRING,

src/VecSim/info_iterator.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66

77
#include "info_iterator_struct.h"
88

9-
extern "C" size_t VecSimInfoIterator_NumberOfFields(VecSimInfoIterator *infoIterator) {
9+
extern "C" size_t VecSimDebugInfoIterator_NumberOfFields(VecSimDebugInfoIterator *infoIterator) {
1010
return infoIterator->numberOfFields();
1111
}
1212

13-
extern "C" bool VecSimInfoIterator_HasNextField(VecSimInfoIterator *infoIterator) {
13+
extern "C" bool VecSimDebugInfoIterator_HasNextField(VecSimDebugInfoIterator *infoIterator) {
1414
return infoIterator->hasNext();
1515
}
1616

17-
extern "C" VecSim_InfoField *VecSimInfoIterator_NextField(VecSimInfoIterator *infoIterator) {
17+
extern "C" VecSim_InfoField *
18+
VecSimDebugInfoIterator_NextField(VecSimDebugInfoIterator *infoIterator) {
1819
if (infoIterator->hasNext()) {
1920
return infoIterator->next();
2021
}
2122
return NULL;
2223
}
2324

24-
extern "C" void VecSimInfoIterator_Free(VecSimInfoIterator *infoIterator) {
25+
extern "C" void VecSimDebugInfoIterator_Free(VecSimDebugInfoIterator *infoIterator) {
2526
if (infoIterator != NULL) {
2627
delete infoIterator;
2728
}

src/VecSim/info_iterator.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#pragma once
88
#include <stdlib.h>
9+
#include <stdint.h>
910
#ifdef __cplusplus
1011
extern "C" {
1112
#endif
@@ -15,7 +16,7 @@ extern "C" {
1516
* the type VecSim_InfoFieldType. This struct exposes an iterator-like API to iterate over the
1617
* information fields.
1718
*/
18-
typedef struct VecSimInfoIterator VecSimInfoIterator;
19+
typedef struct VecSimDebugInfoIterator VecSimDebugInfoIterator;
1920

2021
typedef enum {
2122
INFOFIELD_STRING,
@@ -49,7 +50,7 @@ typedef struct {
4950
* @param infoIterator Given info iterator.
5051
* @return size_t Number of fields.
5152
*/
52-
size_t VecSimInfoIterator_NumberOfFields(VecSimInfoIterator *infoIterator);
53+
size_t VecSimDebugInfoIterator_NumberOfFields(VecSimDebugInfoIterator *infoIterator);
5354

5455
/**
5556
* @brief Returns if the fields iterator is depleted.
@@ -58,22 +59,22 @@ size_t VecSimInfoIterator_NumberOfFields(VecSimInfoIterator *infoIterator);
5859
* @return true Iterator is not depleted.
5960
* @return false Otherwise.
6061
*/
61-
bool VecSimInfoIterator_HasNextField(VecSimInfoIterator *infoIterator);
62+
bool VecSimDebugInfoIterator_HasNextField(VecSimDebugInfoIterator *infoIterator);
6263

6364
/**
6465
* @brief Returns a pointer to the next info field.
6566
*
6667
* @param infoIterator Given info iterator.
6768
* @return VecSim_InfoField* A pointer to the next info field.
6869
*/
69-
VecSim_InfoField *VecSimInfoIterator_NextField(VecSimInfoIterator *infoIterator);
70+
VecSim_InfoField *VecSimDebugInfoIterator_NextField(VecSimDebugInfoIterator *infoIterator);
7071

7172
/**
7273
* @brief Free an info iterator.
7374
*
7475
* @param infoIterator Given info iterator.
7576
*/
76-
void VecSimInfoIterator_Free(VecSimInfoIterator *infoIterator);
77+
void VecSimDebugInfoIterator_Free(VecSimDebugInfoIterator *infoIterator);
7778

7879
#ifdef __cplusplus
7980
}

src/VecSim/info_iterator_struct.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#include "info_iterator.h"
1010
#include "VecSim/utils/arr_cpp.h"
1111

12-
struct VecSimInfoIterator {
12+
struct VecSimDebugInfoIterator {
1313
private:
1414
VecSim_InfoField *fields;
1515
size_t currentIndex;
1616

1717
public:
18-
VecSimInfoIterator(size_t len) : fields(array_new<VecSim_InfoField>(len)), currentIndex(0) {}
18+
VecSimDebugInfoIterator(size_t len)
19+
: fields(array_new<VecSim_InfoField>(len)), currentIndex(0) {}
1920

2021
inline void addInfoField(VecSim_InfoField infoField) {
2122
this->fields = array_append(this->fields, infoField);
@@ -27,5 +28,5 @@ struct VecSimInfoIterator {
2728

2829
inline size_t numberOfFields() { return array_len(this->fields); }
2930

30-
virtual ~VecSimInfoIterator() { array_free(this->fields); }
31+
virtual ~VecSimDebugInfoIterator() { array_free(this->fields); }
3132
};

src/VecSim/vec_sim.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ extern "C" VecSimResolveCode VecSimIndex_ResolveParams(VecSimIndex *index, VecSi
172172
if (!qparams || (!rparams && (paramNum != 0))) {
173173
return VecSimParamResolverErr_NullParam;
174174
}
175-
VecSimAlgo index_type = index->info().algo;
175+
VecSimAlgo index_type = index->debugInfo().algo;
176176
bzero(qparams, sizeof(VecSimQueryParams));
177177
auto res = VecSimParamResolver_OK;
178178
for (int i = 0; i < paramNum; i++) {
@@ -256,10 +256,16 @@ extern "C" void VecSimIndex_Free(VecSimIndex *index) {
256256
delete index;
257257
}
258258

259-
extern "C" VecSimIndexInfo VecSimIndex_Info(VecSimIndex *index) { return index->info(); }
259+
extern "C" VecSimIndexDebugInfo VecSimIndex_DebugInfo(VecSimIndex *index) {
260+
return index->debugInfo();
261+
}
262+
263+
extern "C" VecSimDebugInfoIterator *VecSimIndex_DebugInfoIterator(VecSimIndex *index) {
264+
return index->debugInfoIterator();
265+
}
260266

261-
extern "C" VecSimInfoIterator *VecSimIndex_InfoIterator(VecSimIndex *index) {
262-
return index->infoIterator();
267+
extern "C" VecSimIndexStatsInfo VecSimIndex_StatsInfo(VecSimIndex *index) {
268+
return index->statisticInfo();
263269
}
264270

265271
extern "C" VecSimBatchIterator *VecSimBatchIterator_New(VecSimIndex *index, const void *queryBlob,

src/VecSim/vec_sim.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,22 @@ VecSimQueryResult_List VecSimIndex_RangeQuery(VecSimIndex *index, const void *qu
146146
* @param index the index to return its info.
147147
* @return Index general and specific meta-data.
148148
*/
149-
VecSimIndexInfo VecSimIndex_Info(VecSimIndex *index);
149+
VecSimIndexDebugInfo VecSimIndex_DebugInfo(VecSimIndex *index);
150+
151+
/**
152+
* @brief Return statistics information.
153+
* @param index the index to return its info.
154+
* @return Index statistic data.
155+
*/
156+
VecSimIndexStatsInfo VecSimIndex_StatsInfo(VecSimIndex *index);
150157

151158
/**
152159
* @brief Returns an info iterator for generic reply purposes.
153160
*
154161
* @param index this index to return its info.
155-
* @return VecSimInfoIterator* An iterable containing the index general and specific meta-data.
162+
* @return VecSimDebugInfoIterator* An iterable containing the index general and specific meta-data.
156163
*/
157-
VecSimInfoIterator *VecSimIndex_InfoIterator(VecSimIndex *index);
164+
VecSimDebugInfoIterator *VecSimIndex_DebugInfoIterator(VecSimIndex *index);
158165

159166
/**
160167
* @brief Create a new batch iterator for a specific index, for a specific query vector,

src/VecSim/vec_sim_common.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,15 @@ typedef struct {
140140
} VecSimQueryParams;
141141

142142
/**
143-
* @brief Index information. Mainly used for debug/testing.
143+
* Index info for statistics - a thin and efficient (no locks, no calculations) info. Can be used in
144+
* production without worrying about performance
145+
*/
146+
typedef struct {
147+
size_t memory;
148+
} VecSimIndexStatsInfo;
149+
150+
/**
151+
* @brief Index information. Should only be used for debug/testing.
144152
*
145153
*/
146154
typedef struct {
@@ -175,7 +183,7 @@ typedef struct {
175183
} bfInfo;
176184
};
177185
VecSimAlgo algo; // Algorithm being used.
178-
} VecSimIndexInfo;
186+
} VecSimIndexDebugInfo;
179187

180188
// Memory function declarations.
181189
typedef void *(*allocFn)(size_t n);

src/VecSim/vec_sim_index.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ struct VecSimIndexAbstract : public VecSimIndexInterface {
5858
inline size_t GetDim() const { return dim; }
5959
inline void setLastSearchMode(VecSearchMode mode) override { this->last_mode = mode; }
6060
inline bool isMultiValue() const { return isMulti; }
61+
virtual inline VecSimIndexStatsInfo statisticInfo() const override {
62+
return VecSimIndexStatsInfo{
63+
.memory = static_cast<size_t>(this->getAllocationSize()),
64+
};
65+
}
6166
};

src/VecSim/vec_sim_interface.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,21 @@ struct VecSimIndexInterface : public VecsimBaseObject {
110110
*
111111
* @return Index general and specific meta-data.
112112
*/
113-
virtual VecSimIndexInfo info() const = 0;
113+
virtual VecSimIndexDebugInfo debugInfo() const = 0;
114+
115+
/**
116+
* @brief Return index statistic information.
117+
*
118+
* @return Index general and specific statistic data (for quick and lock-less retrieval)
119+
*/
120+
virtual VecSimIndexStatsInfo statisticInfo() const = 0;
114121

115122
/**
116123
* @brief Returns an index information in an iterable structure.
117124
*
118-
* @return VecSimInfoIterator Index general and specific meta-data.
125+
* @return VecSimDebugInfoIterator Index general and specific meta-data.
119126
*/
120-
virtual VecSimInfoIterator *infoIterator() const = 0;
127+
virtual VecSimDebugInfoIterator *debugInfoIterator() const = 0;
121128

122129
/**
123130
* @brief Create a new batch iterator for a specific index, for a specific query vector,

0 commit comments

Comments
 (0)