-
Notifications
You must be signed in to change notification settings - Fork 24
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
support basic searcher #351
base: main
Are you sure you want to change the base?
Conversation
src/data_cell/flatten_interface.h
Outdated
public: | ||
InnerIdType total_count_{0}; | ||
InnerIdType max_capacity_{1000000}; | ||
uint32_t code_size_{0}; | ||
uint32_t prefetch_neighbor_codes_num_{1}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why flatten datacell need neighbor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used for batch query
src/allocator_wrapper.h
Outdated
template <typename T, typename U> | ||
bool | ||
operator==(const AllocatorWrapper<T>&, const AllocatorWrapper<U>&) noexcept { | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
private: | ||
std::shared_ptr<hnswlib::HierarchicalNSW> alg_hnsw_; | ||
}; | ||
} // namespace vsag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only used on test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/data_cell/flatten_datacell.h
Outdated
@@ -70,6 +70,11 @@ class FlattenDataCell : public FlattenInterface { | |||
io_->Prefetch(id * code_size_); | |||
}; | |||
|
|||
bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/data_cell/flatten_interface.h
Outdated
virtual void | ||
SetRuntimeParameters(const UnorderedMap<std::string, ParamValue>& new_params) { | ||
// TODO(ZXY): implement | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/impl/basic_searcher.cpp
Outdated
|
||
template <typename GraphTmpl, typename VectorDataTmpl> | ||
BasicSearcher<GraphTmpl, VectorDataTmpl>::BasicSearcher(std::shared_ptr<GraphTmpl> graph, | ||
std::shared_ptr<VectorDataTmpl> vector, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use interface is better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/impl/basic_searcher.cpp
Outdated
|
||
#ifdef USE_SSE | ||
for (uint32_t i = 0; i < prefetch_neighbor_visit_num_; i++) { | ||
_mm_prefetch(vl->mass + neighbors[i], _MM_HINT_T0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Prefetch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/impl/basic_searcher.cpp
Outdated
for (uint32_t i = 0; i < neighbors.size(); i++) { | ||
#ifdef USE_SSE | ||
if (i + prefetch_neighbor_visit_num_ < neighbors.size()) { | ||
_mm_prefetch(vl->mass + neighbors[i + prefetch_neighbor_visit_num_], _MM_HINT_T0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (vl->mass[neighbors[i]] != vl->curV) { | ||
to_be_visited_rid[count_no_visited] = i; | ||
to_be_visited_id[count_no_visited] = neighbors[i]; | ||
count_no_visited++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sometimes we don't need to_be_visited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for graph searcher, it's required
0d51c38
to
b267091
Compare
src/impl/basic_searcher.cpp
Outdated
|
||
BasicSearcher::BasicSearcher(GraphInterfacePtr graph, | ||
FlattenInterfacePtr vector, | ||
const IndexCommonParam& common_param) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const GraphInterfacePtr& graph
const FlattenInterfacePtr& vector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified to graph & flat interface
src/impl/basic_searcher.h
Outdated
#include <shared_mutex> | ||
|
||
#include "../utils.h" | ||
#include "ThreadPool.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unused header files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/impl/basic_searcher.h
Outdated
const IndexCommonParam& common_param); | ||
|
||
virtual MaxHeap | ||
Search(const float* query, InnerSearchParam& inner_search_param) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we search different graph using one Searcher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified, use SetGraphAndVector to allow search with different graph and vector
src/impl/runtime_parameter.h
Outdated
#include <string> | ||
#include <thread> | ||
#include <variant> | ||
#include <vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
#include "fixtures.h" | ||
#include "io/memory_io.h" | ||
#include "quantization/fp32_quantizer.h" | ||
#include "safe_allocator.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/impl/basic_searcher_test.cpp
Outdated
REQUIRE(result.top().second == valid_result.top().second); | ||
REQUIRE(result.top().second == ids[i]); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/impl/runtime_parameter.h
Outdated
int cur_{0}; | ||
bool is_end_{false}; | ||
}; | ||
} // namespace vsag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/impl/basic_searcher.h
Outdated
uint32_t prefetch_neighbor_visit_num_{1}; | ||
}; | ||
|
||
} // namespace vsag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/impl/basic_searcher.cpp
Outdated
} | ||
|
||
MaxHeap | ||
BasicSearcher::Search(const float* query, InnerSearchParam& inner_search_param) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const InnerSearchParam& inner_search_param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/data_cell/flatten_datacell.h
Outdated
@@ -226,7 +226,18 @@ FlattenDataCell<QuantTmpl, IOTmpl>::query(float* result_dists, | |||
const std::shared_ptr<Computer<QuantTmpl>>& computer, | |||
const InnerIdType* idx, | |||
InnerIdType id_count) { | |||
for (uint32_t i = 0; i < this->prefetch_neighbor_codes_num_ and i < id_count; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefetch_neighbor_codes_num_
is always 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can be further optimized by optimizer
8af23a1
to
6450d83
Compare
6450d83
to
a8a6a01
Compare
Codecov ReportAttention: Patch coverage is @@ Coverage Diff @@
## main #351 +/- ##
==========================================
- Coverage 90.28% 88.02% -2.27%
==========================================
Files 118 135 +17
Lines 7372 8693 +1321
==========================================
+ Hits 6656 7652 +996
- Misses 716 1041 +325
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
src/impl/basic_searcher.cpp
Outdated
|
||
void | ||
BasicSearcher::SetGraphAndVector(GraphInterfacePtr graph_data_cell, | ||
FlattenInterfacePtr vector_data_cell) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split two function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/impl/basic_searcher.cpp
Outdated
std::pair<float, uint64_t>& current_node_pair, | ||
Vector<InnerIdType>& to_be_visited_rid, | ||
Vector<InnerIdType>& to_be_visited_id) const { | ||
// to_be_visited_rid is used in redundant storage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant not used now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comment for distinguish to_be_visited_rid and to_be_visited_id in basic_search.h
src/impl/basic_searcher.cpp
Outdated
} | ||
|
||
void | ||
BasicSearcher::SetGraphAndVector(GraphInterfacePtr graph_data_cell, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use interface name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
uint32_t hops = 0; | ||
uint32_t dist_cmp = 0; | ||
uint32_t count_no_visited = 0; | ||
Vector<InnerIdType> to_be_visited_rid(graph_data_cell_->MaximumDegree(), allocator_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Signed-off-by: zhongxiaoyao.zxy <[email protected]>
a8a6a01
to
cb903ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
#278