Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: knowhere support data view index node #1016

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cqy123456
Copy link
Collaborator

@cqy123456 cqy123456 commented Jan 8, 2025

issue: #909

@sre-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cqy123456

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

mergify bot commented Jan 8, 2025

@cqy123456 🔍 Important: PR Classification Needed!

For efficient project management and a seamless review process, it's essential to classify your PR correctly. Here's how:

  1. If you're fixing a bug, label it as kind/bug.
  2. For small tweaks (less than 20 lines without altering any functionality), please use kind/improvement.
  3. Significant changes that don't modify existing functionalities should be tagged as kind/enhancement.
  4. Adjusting APIs or changing functionality? Go with kind/feature.

For any PR outside the kind/improvement category, ensure you link to the associated issue using the format: “issue: #”.

Thanks for your efforts and contribution to the community!.

@cqy123456 cqy123456 changed the title enhance: knowhere support data view index enhance: knowhere support data view index node Jan 8, 2025
@cqy123456 cqy123456 force-pushed the data-view-index branch 2 times, most recently from 669d387 to d9dc4cb Compare January 8, 2025 06:53
include/knowhere/comp/index_param.h Outdated Show resolved Hide resolved
template <typename T>
class Pack : public Object {
static_assert(std::is_same_v<T, std::shared_ptr<knowhere::FileManager>>,
static_assert(std::is_same_v<T, std::shared_ptr<knowhere::FileManager>> || std::is_same_v<T, knowhere::ViewDataOp>,
"IndexPack only support std::shared_ptr<knowhere::FileManager> by far.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This message should be updated

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated.

src/index/ivf/ivf.cc Show resolved Hide resolved
src/index/ivf/ivf.cc Outdated Show resolved Hide resolved
src/index/data_view_dense_index/data_view_dense_index.h Outdated Show resolved Hide resolved
* @param range_filter
*/
virtual RangeSearchResult
RangeSearchWithIds(const idx_t n, const void* x, const idx_t* ids_num_lims, const idx_t* ids, const float radius,
Copy link
Collaborator

Choose a reason for hiding this comment

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

same above

include/knowhere/object.h Outdated Show resolved Hide resolved
@cqy123456 cqy123456 force-pushed the data-view-index branch 2 times, most recently from 1667fc3 to d4ff301 Compare January 8, 2025 13:47
namespace knowhere {
class IndexWithDataViewRefinerConfig : public ScannConfig {
public:
CFG_INT reorder_k;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this config is in scannconfig, could be excluded here

@@ -1261,4 +1261,7 @@ KNOWHERE_MOCK_REGISTER_DENSE_FLOAT_ALL_GLOBAL(IVF_SQ8, IvfIndexNode, knowhere::f
KNOWHERE_MOCK_REGISTER_DENSE_FLOAT_ALL_GLOBAL(IVF_SQ_CC, IvfIndexNode, knowhere::feature::NONE,
faiss::IndexIVFScalarQuantizerCC)

// faiss index + data view refiner combination
KNOWHERE_SIMPLE_REGISTER_DENSE_FLOAT_ALL_GLOBAL(SCANN_DVR, IndexNodeWithDataViewRefiner, knowhere::feature::NONE,
IvfIndexNode<fp32, faiss::IndexScaNN>)
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need IVFFLAT and IVFSQ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we can all more xxx_with_data_view_refiner index in the future.

@@ -118,7 +119,7 @@ constexpr const char* WITH_RAW_DATA = "with_raw_data";
constexpr const char* ENSURE_TOPK_FULL = "ensure_topk_full";
constexpr const char* CODE_SIZE = "code_size";
constexpr const char* RAW_DATA_STORE_PREFIX = "raw_data_store_prefix";

constexpr const char* SUB_DIM = "sub_dim";
Copy link
Collaborator

Choose a reason for hiding this comment

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

we could use m like PQ and not introduce a new config, but m is slightly different from sub_dim

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using this parameter is a bit like the meaning of diskann's pq_code_budget_gb, and it is ealier to maintain a constant memory/(raw data size) ratio for different dim in milvus.

@cqy123456 cqy123456 force-pushed the data-view-index branch 2 times, most recently from cb686ab to d3b1a95 Compare January 12, 2025 17:53
Copy link

codecov bot commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.00%. Comparing base (3c46f4c) to head (b768594).
Report is 291 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           main    #1016       +/-   ##
=========================================
+ Coverage      0   73.00%   +73.00%     
=========================================
  Files         0       86       +86     
  Lines         0     8138     +8138     
=========================================
+ Hits          0     5941     +5941     
- Misses        0     2197     +2197     

see 86 files with indirect coverage changes

@mergify mergify bot added the ci-passed label Jan 12, 2025
include/knowhere/utils.h Outdated Show resolved Hide resolved
src/common/utils.cc Show resolved Hide resolved
src/index/data_view_dense_index/data_view_dense_index.h Outdated Show resolved Hide resolved
src/index/data_view_dense_index/data_view_dense_index.h Outdated Show resolved Hide resolved
// use copy to avoid concurrent add and search
std::shared_lock lock(norms_mutex_);
base_norms = std::shared_ptr<float[]>(new float[norms_.size()]);
std::memcpy(base_norms.get(), norms_.data(), sizeof(float) * norms_.size());
Copy link
Collaborator

Choose a reason for hiding this comment

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

just to clarify: a single query with n == 1 leads to copying of all norms?

src/index/data_view_dense_index/data_view_dense_index.h Outdated Show resolved Hide resolved
src/index/data_view_dense_index/data_view_dense_index.h Outdated Show resolved Hide resolved
if (is_cosine_) {
for (auto j = 0; j < base_n; j++) {
if (base_ids[j] != -1) {
std::shared_lock lock(norms_mutex_);
Copy link
Collaborator

Choose a reason for hiding this comment

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

putting a lock here could impose a very hardcore overhead. Isn't it better to put it around for-loop or clone norms_?

@@ -88,6 +89,8 @@ struct IndexIVFFastScan : IndexIVF {
// // todo aguzhva: get rid of this
std::vector<float> norms;

std::shared_ptr<std::shared_mutex> mutex = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this cannot be resolved by surrounding a corresponding faiss index with a mutex rather than adding a mutex as a field? Technically, adding such a mutex implies a lot of unit testing and thorough analysis of the whole class

@@ -361,6 +364,7 @@ void IndexIVFFastScan::search_preassigned(
bool store_pairs,
const IVFSearchParameters* params,
IndexIVFStats* stats) const {
std::shared_lock<std::shared_mutex> lock(*mutex.get());
Copy link
Collaborator

Choose a reason for hiding this comment

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

check for range_search and iterator

@mergify mergify bot removed the ci-passed label Jan 14, 2025
@cqy123456 cqy123456 force-pushed the data-view-index branch 2 times, most recently from 0b71169 to 506348a Compare January 14, 2025 06:58
@mergify mergify bot added the ci-passed label Jan 14, 2025
@mergify mergify bot removed the ci-passed label Jan 14, 2025
@cqy123456 cqy123456 force-pushed the data-view-index branch 2 times, most recently from c3b89ea to 505699f Compare January 14, 2025 11:14
@mergify mergify bot added the ci-passed label Jan 14, 2025
src/index/data_view_dense_index/data_view_dense_index.h Outdated Show resolved Hide resolved
src/index/data_view_dense_index/data_view_index_config.h Outdated Show resolved Hide resolved

namespace {
constexpr int64_t kBatchSize = 4096;
constexpr int64_t kMaxTrainSize = 5000;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is for training what exactly? 5k points seems to be a bit small

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

DVR index will only uses in milvus growing segment, and the row count of growing segment is not very large.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The difference may be large for different dims, so dynamic parameters may need to be considered here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why different dims need different train row count?

@foxspy
Copy link
Collaborator

foxspy commented Jan 15, 2025

/hold wait v2.5.4 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants