Skip to content

Conversation

@yuejiaointel
Copy link
Contributor

This PR intends to add per index logging feature to help the redis integration progress

@yuejiaointel yuejiaointel changed the title feature: logger in vamana index and unit test feature: Per index logger and new logger unit test for each index Feb 28, 2025
@yuejiaointel yuejiaointel marked this pull request as ready for review February 28, 2025 06:33
Level::Critical,
Level::Off};
Level::Off
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please run these commands from the repository's root to ensure all the formatting is consistent?
sudo apt install clang-format-15
bash tools/clang-format.sh clang-format-15

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thx!

inline void set_global_log_callback(log_callback_function callback) {
global_log_callback = callback;
std::cout << "[DEBUG] set_global_log_callback(" << reinterpret_cast<void*>(callback)
<< ")\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove the std::cout print statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, thx!

/// search. This may be included to perform operations like reranking for quantized
/// datasets.
/// @tparam log_callback_ctx A pointer to a user-defined context for per-index logging
/// customization.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the logger from here as it is not the template parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, thx!

Copy link
Member

@rfsaliev rfsaliev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this change breaks existing SVS logging design based on spdlog.
IMHO, instead of log_callback_ctx we should use logger_ptr.
In such case user will follow known spdlog approach for custom loggers (including contexts) rather than than learn one more SVS-specific approach (with the risk of typos like "DЕBYG" instead of "DEBUG").
And there is still global logger used, e.g. in MutableVamanaIndex::consolidate()

Data data,
Dist distance,
ThreadPoolProto threadpool_proto,
void* log_callback_ctx = nullptr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, svs::logger_ptr would be better.

Copy link
Contributor Author

@yuejiaointel yuejiaointel Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, that make sense, changed!

@yuejiaointel
Copy link
Contributor Author

consolidate

That's a good idea! I changed the code to use sink component and make shared function in spdlog. But not too sure about functions like MutableVamanaIndex::consolidate(). It looks like these loggers are just used for debugging, do we want them to have per index logging as well?
Best,
Yue

@dian-lun-lin
Copy link
Member

dian-lun-lin commented Mar 7, 2025

Now that we have per-index-instance logger, each member function in the index should use that logger. For example,
svs::logging::debug(logger, "Replacing entry point."); in consolidate should use per-index-instance logger. The unittest should check if this logging information is captured by per-index-instance logger.

Note that we have logging information in construct as well. We should also delegate the per-index-instance logger to that construct for logging rather than the global logger.

@yuejiaointel
Copy link
Contributor Author

Now that we have per-index-instance logger, each member function in the index should use that logger. For example, svs::logging::debug(logger, "Replacing entry point."); in consolidate should use per-index-instance logger. The unittest should check if this logging information is captured by per-index-instance logger.

Note that we have logging information in construct as well. We should also delegate the per-index-instance logger to that construct for logging rather than the global logger.

Thx for the help! Now these files are using per index logging :D

// const double DELETE_PERCENT = 0.05;
// #endif

// CATCH_TEST_CASE("MutableVamanaIndex", "[graph_index]") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we comment out this test?

Copy link
Contributor Author

@yuejiaointel yuejiaointel Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are removed already, dynamic_index.cpp is not changed, only dynamic_index_2.cpp is added a new test

std::string prefix;
};

static void test_log_impl(void* ctx, const char* level, const char* message) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure the purpose of static in every test_log_impl. I think putting this function and the struct into anonymous namespace is enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see it anymore, seems to be older old?

<< post_add_time << " seconds." << std::endl;
}
}
CATCH_TEST_CASE("Dynamic MutableVamanaIndex Per-Index Logging Test", "[logging]") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test for not setting the callback (i.e., not calling set_global_log_callback)? Adding this test in dynamic index should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx! Added in dynamic_index_2.cpp

/// @brief Add the points with the given external IDs to the dataset.
//
/// When `delete_entries` is called, a soft deletion is performed, marking the entries
/// as `deleted`. When `consolidate` is called, the state of these deleted entries becomes `empty`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a side note that I notice clang-format keeps changing the format of this paragraph. We might want to consider disabling clang-format for this specific section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, this part will not change

}

/// @brief Getter method for logger
svs::logging::logger_ptr get_logger() const { return logger_; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have this get_logger for each index?

Copy link
Contributor Author

@yuejiaointel yuejiaointel Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, added logger getter for each index


// Verify the custom logger captured the log messages
CATCH_REQUIRE(captured_logs[0].find("Number of syncs:") != std::string::npos);
CATCH_REQUIRE(captured_logs[1].find("Batch Size:") != std::string::npos);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also test here to check if the global logger is not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, added!

I{},
std::move(distance),
std::move(threadpool),
logger};
Copy link
Member

@ibhati ibhati Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger};
std::move(logger)};

should we move instead of copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, changed!

@ibhati ibhati merged commit 1878951 into intel:main Mar 14, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants