MCPcopy Create free account
hub / github.com/antgroup/vsag / CalDistanceById

Method CalDistanceById

src/algorithm/ivf.cpp:1007–1029  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1005}
1006
1007DatasetPtr
1008IVF::CalDistanceById(const float* query, const int64_t* ids, int64_t count) const {
1009 auto result = Dataset::Make();
1010 result->Owner(true, allocator_);
1011 auto* distances = static_cast<float*>(allocator_->Allocate(sizeof(float) * count));
1012 result->Distances(distances);
1013 if (this->use_reorder_) {
1014 auto computer = this->reorder_codes_->FactoryComputer(query);
1015 Vector<InnerIdType> inner_ids(count, allocator_);
1016 for (int64_t i = 0; i < count; ++i) {
1017 inner_ids[i] = this->label_table_->GetIdByLabel(ids[i]);
1018 }
1019 this->reorder_codes_->Query(distances, computer, inner_ids.data(), count);
1020 return result;
1021 }
1022 auto computer = this->bucket_->FactoryComputer(query);
1023 for (int64_t i = 0; i < count; ++i) {
1024 auto inner_id = this->label_table_->GetIdByLabel(ids[i]);
1025 auto location = this->get_location(inner_id);
1026 distances[i] = this->bucket_->QueryOneById(computer, location.first, location.second);
1027 }
1028 return result;
1029}
1030float
1031IVF::CalcDistanceById(const float* query, int64_t id) const {
1032 if (this->use_reorder_) {

Callers 1

Calls 8

get_locationMethod · 0.95
GetIdByLabelMethod · 0.80
QueryOneByIdMethod · 0.80
OwnerMethod · 0.45
AllocateMethod · 0.45
DistancesMethod · 0.45
FactoryComputerMethod · 0.45
QueryMethod · 0.45

Tested by

no test coverage detected